delphi 6里面新建线程
线程代码如下:
unit Un_GetDFServer;interfaceuses
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;implementationuses 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
线程代码如下:
unit Un_GetDFServer;interfaceuses
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;implementationuses 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
解决方案 »
- 为何我用cxGrid把数据导出到Excel中提示"Unsupported Export type"错误信息?
- 迷茫,我到底该做什么?希望大家多多给意见?
- 怎样在数据库表中选中一个记录然后在进行判断啊?
- 谁能告诉我怎么用dbexpress 的sqlconnection来连接sql2000数据库。装dephi的机器上的sql client可以连接的上sql 2000 server。
- DateTimePicker1加入到DBgrid中?
- HS开头的是什么控件呀
- 如何在屏幕上快速查找指定的小图形?
- 会EmbeddedWB或精通webbrowser的同志请进!~
- 望report高手指导!!!
- Delphi里如何跟踪调试DLL
- 两个dxcurrencyedit中的数据如何相加啊,加结果在第三个dxcurrencyedit中显示
- 生成局部临时表不行,但是生成全局临时表和tabel可以的adoquery控件的问题~~~~~~~~~~~~~~
constructor create;
constructor create;
begin
inherited create(true);
end;
等后面地调用时候采用
但是这段代码在DELPHI7是可以执行
我郁闷ing..........