delphi 6线程问题

jiaorg 2004-07-14 02:13:31
delphi 6里面新建线程
线程代码如下:
unit Un_GetDFServer;

interface

uses
Classes,OAFDIWebService,SyncObjs,dialogs,windows,ADODB,DB;

type
Test = class(TThread)
constructor Create(const url:string;const UserID: Integer; const Pwd: String;ef:TSimpleEvent;query:Tadoquery);
private
_url : String;
_UserId : Integer;
_Pwd : String;
_GetLmListResult: ErrorCode;
_LmInfo: ArrayOfLmNode;
_ef:TsimpleEvent;
_query :TAdoquery;
{ Private declarations }
protected
procedure Execute(); override;
published

end;

implementation

uses MainForm;



{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,

Synchronize(UpdateCaption);

and UpdateCaption could look like,

procedure TGetDFServer.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }

{ TGetDFServer }



{ TGetDFServer }

constructor Test.Create(const url: string; const UserID: Integer;
const Pwd: String;ef : TSimpleEvent;query:Tadoquery);
begin

_url := Url;
_Pwd := Pwd;
_UserId := UserId;
_GetLmListResult := nil;
_LmInfo := nil;
_ef := ef;
FreeOnTerminate:=true;
_query := query;
inherited Create(false);

end;

procedure Test.Execute();
var i : integer;
begin
try

{ GetOAFDIWebServiceSoap(false, _url).GetLmList(_UserID, _Pwd, _GetLmListResult, _LmInfo);
frmMain.GetLmListResult := _GetLmListResult;
frmMain.LmInfo := _LmInfo ;
frmMain.IsComplete := true;
_GetLmListResult := nil;
_LmInfo := nil;
}
if _query<> nil then
_query.Open();
while not _query.Eof do
begin
_query.Next;
end;
//OAFDIWebService.GetOAFDIWebServiceSoap(false,_url).GetLmList(_userId,_Pwd,_Getlmlistresult,_lminfo);
frmmain._GetLmListResult := _Getlmlistresult;
frmmain._LmInfo := _lminfo;
except
{_ef.SetEvent; }
frmMain.IsComplete := true;
end;
end;

end.
调用过程如下;
var
ec: ErrorCode;
lms: ArrayOfLmNode;
t: Test;
ef : TSimpleEvent;
a : TWaitResult;
begin
Loading := true;

if not Assigned(LmInfoList) then LmInfoList := TLmNodeCollection.Create;

//修改的地方
//LmInfoList.Clear;
// ec := nil;
// lms := nil;
//修改结束
ef := TSimpleEvent.Create;
try
t:= test.Create(RegSetup.WebServiceURL,RegSetup.UserID,RegSetup.UserPWD,ef,adoquery1);
a := ef.WaitFor(10);
while not isComplete do
begin
application.HandleMessage;
end;
except
end;
提示错误信息:尚未调用Colinitialize
...全文
129 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ju1 2004-07-15
  • 打赏
  • 举报
回复
看来D7和D6又有发现不同了
jiaorg 2004-07-14
  • 打赏
  • 举报
回复
False传递参数,这样建立的时候先不执行这个EXCUTE.
等后面地调用时候采用
但是这段代码在DELPHI7是可以执行
我郁闷ing..........
tsst 2004-07-14
  • 打赏
  • 举报
回复
可是你为什么用False做参数呢!请指明教!
tsst 2004-07-14
  • 打赏
  • 举报
回复
不好意思,我没有看到你的create
tsst 2004-07-14
  • 打赏
  • 举报
回复
public
constructor create;
constructor create;
begin
inherited create(true);
end;

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧