一
一只笨小狗
Unregistered / Unconfirmed
GUEST, unregistred user!
这个函数放在一个unit文件,uses到线程里使用,就出错,
如果在form1下使用,就对了,为什么?
线程代码代码如下,大家看看哪里出错了?
unit Unit2;
interface
uses
Classes, Activex, SHDocVw_TLB, mshtml,Variants;
type
TTestIE = class(TThread)
private
{ Private declarations }
procedure IEWrite(const webbrowser: Twebbrowser
const content: string);
protected
procedure Execute
override;
end;
implementation
uses
Unit1;
{ TTestIE }
procedure TTestIE.Execute;
begin
{ Place thread code here }
CoInitialize(nil);
IEWrite(form1.IE,'<html><body><b>haha</b></body></html>');
end;
procedure TTestIE.IEWrite(const webbrowser: Twebbrowser
const content: string);
var
vv: Variant;
HTMLDocument: IHTMLDocument2;
begin
vv := VarArrayCreate([0, 0], varVariant);
vv[0] := content;
HTMLDocument := webbrowser.Document as IHTMLDocument2;
HTMLDocument.write(PSafeArray(TVarData(vv).VArray));
HTMLDocument.charset := 'gb2312';
HTMLDocument.close;
vv := Unassigned;
end;
end.
如果在form1下使用,就对了,为什么?
线程代码代码如下,大家看看哪里出错了?
unit Unit2;
interface
uses
Classes, Activex, SHDocVw_TLB, mshtml,Variants;
type
TTestIE = class(TThread)
private
{ Private declarations }
procedure IEWrite(const webbrowser: Twebbrowser
const content: string);
protected
procedure Execute
override;
end;
implementation
uses
Unit1;
{ TTestIE }
procedure TTestIE.Execute;
begin
{ Place thread code here }
CoInitialize(nil);
IEWrite(form1.IE,'<html><body><b>haha</b></body></html>');
end;
procedure TTestIE.IEWrite(const webbrowser: Twebbrowser
const content: string);
var
vv: Variant;
HTMLDocument: IHTMLDocument2;
begin
vv := VarArrayCreate([0, 0], varVariant);
vv[0] := content;
HTMLDocument := webbrowser.Document as IHTMLDocument2;
HTMLDocument.write(PSafeArray(TVarData(vv).VArray));
HTMLDocument.charset := 'gb2312';
HTMLDocument.close;
vv := Unassigned;
end;
end.