Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TWebBrowser printing custom header and footer with safearray

87 views
Skip to first unread message

Chris Morgan

unread,
Nov 17, 2006, 11:22:59 AM11/17/06
to
Hi,

I have been trying to get TWebBrowser to print with
custom headers and footers by passing a safearray
as the 3rd argument to ExecWB.

I cannot get the web browser component to accept
my safearray correctly. It either ignores it
completely, or displays a runtime error
EVariantBadVarTypeError 'Invalid variant type'
from inside the ExecWB method (and then prints
with my custom header and footer).

Obviously, I need to avoid the EVariantBadVarTypeError,
but there is so much implicit type conversion going on that
I'm confused as to what I need to do!

Here's an example of my code:

procedure TTBMainForm.Print1Click(Sender: TObject);
//const htmlhdr = '<html><body><h1>HTML Header</h1></body></html>';
var
v: OleVariant;
psa: PSafeArray;
//strm:IStream;
i: integer;
//j: int64;
hdr,
ftr: WideString;
begin
//CreateStreamOnHGlobal(0,true,strm);
//strm.Write(pchar(htmlhdr),Length(htmlhdr),@i);
//strm.Seek(0,STREAM_SEEK_SET,j);

psa := SafeArrayCreateVector(VT_VARIANT,0,2);
hdr := 'Header';
ftr := 'Footer';
i := 0;
SafeArrayPutElement(psa,i,hdr);
i := 1;
SafeArrayPutElement(psa,i,ftr);
//SafeArrayCopy(PSafeArray(TVarData(VarArrayOf([hdr,ftr,strm as
IUnknown])).VArray),psa);
TVarData(v).VType := varArray or varByRef;
SafeArrayCopy(psa,PSafeArray(TVarData(v).VArray));

WebBrowser1.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_PROMPTUSER,v);
end;

Does anyone have a working example?

I'm using D2006.

Cheers,

Chris


leo....@gmail.com

unread,
Mar 6, 2014, 5:27:54 PM3/6/14
to
Did you find a solution for this??
0 new messages