如何在客户端建立一个线程?(100分)

  • 主题发起人 主题发起人 昨夜渡轮上
  • 开始时间 开始时间

昨夜渡轮上

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在客户端那里用一个线程去访问应用程序服务器的apartment
(假设具有apartment model)
---如何在客户端建立一个线程去访问呢?
---请写上具体的代码谢谢各位大虾
 
我也想知道啊
 
不知道.是否用WaitForSingleObject(hMutex,INFINITE);试试吧
 
提问者:
如果你还要继续讨论请定期提前你的帖子,如果不想继续讨论请结束帖子。
 
用TThread类不行吗?
type
TMyThread=class(TThread)
private
..........
protected
procedure Execute;override;
end;
Execute里面写访问代码。
 
当然可以
只要从TThread派生新的线程类,结合TClientSocket就行了
type
TSendMailThread=class(TThread)
private
Fsmtp:TIdSMTP;
//procedure OnConnectionError(Sender : TObject);
{ Private declarations }
protected
procedure Execute;
override;
procedure Terminate;
public
constructor Create(CreateSuspended: Boolean);
end;
{ TSendMailThread }
constructor TSendMailThread.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
Priority := tpIdle;
self.FreeOnTerminate:=true;
Fsmtp:=TIdSMTP.Create(FormMain.IdSMTP1);
Fsmtp.Authen
ticationType:=atLogin;
Fsmtp.Host:=FormMain.Edit1.Text;
Fsmtp.Port:=StrToInt(FormMain.Edit2.Text);
Fsmtp.UserID:=formMain.Edit4.Text;
//Fsmtp.OnWorkEnd:=OnConnectionError;
end;

procedure TSendMailThread.Terminate;
begin
if fsmtp.Connected=True then
Fsmtp.Disconnect;
end;

{procedure TSendMailThread.OnConnectionError(Sender:TObject);
begin
self.DoTerminate;
end;
}
procedure TSendMailThread.Execute;
begin
if (self.Terminated=false) then
begin
formmain.IdMessage1.SetBody(Formmain.Memo1.Lines);
formmain.IdMessage1.From.Text :='Codehunter@sohu.com';
formmain.IdMessage1.Recipients.EMailAddresses:=formmain.ListBox1.Items.Strings[0];
formmain.IdMessage1.Subject:='password';
Fsmtp.Connect;
if Fsmtp.Connected=true then
begin
try
FSmtp.Send(formmain.IdMessage1);
except
FSmtp.Disconnect;
end;
end;
Fsmtp.Destroy;
end;
end;
 
procedure TestComThread.Execute;
var
TempInt:OLEVariant;
DCOMConnection:TDCOMConnection;
begin
TempInt:=150;
DCOMConnection:=TDCOMConnection.Create(Application);
DCOMConnection.ComputerName:='Host';
DCOMConnection.ServerName:='TestDcom.TestDcomServer';
try
CoInitialize(nil);
DCOMConnection.Open;
DCOMConnection.AppServer.GetResult(TempInt);
finally
CoUninitialize;
end;

DCOMConnection.Free;
end;
 
谢谢.q_l先..等我试试再给你加分...分数虽然小但是还是希望各位大虾积极发言....
 
q_l能不能发各这方面的源代码过来研究研究...
我的e_mail是:xiao_pei2000@21cn.com
 
忘了还有CODEHUNTER大虾..谢谢你...
差点忘了..真的不好意思..嘻嘻..
 
那位大虾有这方面的源代码..请给我email..xiao_pei2000@21cn.com
 
后退
顶部