![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Потоки
Pacific © (2007-11-29 20:52:00)Здравтсвуйте! Такой вопрос: у меня главная форма подвисает, когда
активируется процедура OnIcqLogin, ведь подвисать не должно :(
unit th;
interface
uses
Classes, SysUtils, icqclient, icqworks;
type
threed = class(TThread)
private
ICQClient: TICQClient;
procedure OnICQLogin(Sender: TObject);
protected
procedure Execute; override;
end;
implementation
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure threed.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ threed }
uses main;
procedure threed.OnICQLogin(Sender: TObject);
var
x:integer;
begin
x:=strtoint(form1.Label12.Caption);
Inc(x);
form1.Label12.Caption:=inttostr(x);
sleep(strtoint(form1.Edit3.text)*1000);
icqclient.SendMessage(strtoint(form1.edit6.text), form1.Memo1.Text);
end;
procedure threed.Execute;
var
sent:integer;
icq,uin,pass, proxy:string;
begin
sent:=0;
Inc(form1.listp);
If form1.listp=form1.Proxylist.Count-1 then
begin
proxy:=copy(form1.Proxylist.Strings[form1.listp], 1, 400);
form1.listp:=-1;
end
else
begin
proxy:=copy(form1.Proxylist.Strings[form1.listp], 1, 400);
end;
icq:=form1.ICQlist.Strings[form1.list];
uin:=copy(icq, 1, Pos(';', icq)-1);
pass:=copy(icq, Pos(';', icq)+1, 255);
icqclient:=Ticqclient.Create(nil);
ICQClient.DisableDirectConnections:= True;
ICQClient.ICQServer:= 'login.icq.com';
ICQClient.ICQPort:=5190;
icqclient.UIN:=strtoint(uin);
icqclient.Password:=pass;
icqclient.OnLogin:=OnIcqLogin;
icqclient.Login();
end;
end.
Loginov Dmitry (2007-11-29 21:45:00) [1]> из основного потока
т.е. из дополнительного
Loginov Dmitry (2007-11-29 21:43:00) [2]Для устранения проблем, возникающих с данным кодом, необходимо в ПЕРВУЮ очередь убрать ВСЕ обращения к VCL из основного потока. Иначе "подвисание" - это ДАЛЕКО не самое страшное, что здесь может происходить.
Pacific (2007-11-29 21:00:00) [3]но так незя :(
icqclient.OnLogin:=synchronize(OnIcqLogin);
т.к.
property OnLogin: TLoginEvent;
tesseract (2007-11-29 20:58:00) [4]По этому не должна. А так черт знает где у тебя synchronize понатыкан.