我试图让这个库与线程一起工作,但我无法使用 syncronize 将结果返回到主线程。
在执行方法中创建 xml 没有问题。
有人用过吗?
TMyThread = class(TThread)
private
ADoc : TNativeXml;
protected
procedure Execute; override;
procedure DoProgress;
public
constructor Create(CreateSuspended: Boolean);
end;
{ TMyThread }
constructor TMyThread.Create(CreateSuspended: Boolean);
begin
inherited;
end;
procedure TMyThread.DoProgress;
begin
formMain.meminfo.Lines.Add(ADoc.WriteToString);
end;
procedure TMyThread.Execute;
var i,j : integer;
begin
inherited;
begin
ADoc:= ADoc.Create(formMain);
try
Adoc.XmlFormat := xfReadable;
ADoc.LoadFromFile('test.xml');
Synchronize(DoProgress);
finally
FreeAndNil(ADoc);
end;
end;
end;