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