在IdTCPServer的OnExecute事件中访问VCL需要同步吗? |
尚未結案
|
sdshw
一般會員 發表:8 回覆:11 積分:3 註冊:2008-03-24 發送簡訊給我 |
各位大师:
在IdTCPServer的OnExecute事件中访问VCL需要同步吗? 在Indy9 的Chat Demo中没有看到同步访问VCL的代码,这样做安全吗? 请看代码: [code delphi] procedure TfrmMain.tcpServerExecute(AThread: TIdPeerThread); var Client : TSimpleClient; Com, // System command Msg : String; begin { Get the text sent from the client } Msg := AThread.Connection.ReadLn; { Get the clients package info } Client := Pointer(AThread.Data); { Check to see if the clients name has been assigned yet } if Client.Name = 'Logging In' then begin { if not, assign the name and announce the client } Client.Name := Msg; UpdateClientList; //这里面访问了TListBox BroadcastMessage('System', Msg ' has just logged in.'); AThread.Connection.WriteLn(memEntry.Lines.Text); end else { If name is set, then send the message } if Msg[1] <> '@' then begin { Not a system command } BroadcastMessage(Client.Name, Msg); end else begin { System command } Com := UpperCase(Trim(Copy(Msg, 2, Pos(':', Msg) -2))); Msg := UpperCase(Trim(Copy(Msg, Pos(':', Msg) 1, Length(Msg)))); if Com = 'CLIENTS' then AThread.Connection.WriteLn( '@' 'clients:' lbClients.Items.CommaText); end; end; [/code] [code delphi] procedure TfrmMain.UpdateClientList; var Count : Integer; begin { Loop through all the clients connected to the system and set their names } for Count := 0 to lbClients.Items.Count -1 do if Count < Clients.Count then lbClients.Items.Strings[Count] := TSimpleClient(Clients.Items[Count]).Name; //这儿访问了TListBox end; [/code] |
sos_admin
版主 發表:121 回覆:697 積分:768 註冊:2003-07-23 發送簡訊給我 |
|
sdshw
一般會員 發表:8 回覆:11 積分:3 註冊:2008-03-24 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |