我正在使用Delphi匿名线程来执行代码。
在线程中间,需要进行一些GUI更新,例如改变标签等。
如果我在线程内部执行这些操作,则更改会生效。但是一旦线程停止,它们就会消失,然后应用程序会给出旧的窗口处理程序错误...(这是预料之中的)
我尝试使用
我已经搜索了一页又一页的内容,它们似乎都是这样调用的,但是当我这样做时,我得到了上面的错误...
我的调用方式有误吗?
代码:
如果我在线程内部执行这些操作,则更改会生效。但是一旦线程停止,它们就会消失,然后应用程序会给出旧的窗口处理程序错误...(这是预料之中的)
我尝试使用
Synchronize(updateui);
方法来执行更改(将它们移至单独的函数中),但是同步会出现错误E2066 Missing operator or semicolon
,这对我来说毫无意义...我已经搜索了一页又一页的内容,它们似乎都是这样调用的,但是当我这样做时,我得到了上面的错误...
我的调用方式有误吗?
代码:
TThread.CreateAnonymousThread(
procedure
begin
main.Enabled:=false;
Loading.show;
label52.caption:=getfieldvalue(datalive.users,'users','credit_amount','user_id',user_id );
CoInitialize(nil);
if (length(maskedit1.Text)=maskedit1.MaxLength) and (pingip(serverip)=true) then
begin
if (strtofloat(label52.caption)>0) then
begin
....do some work....
Synchronize(updateui);
end
else Showmessage('Insufficient Funds. Please add funds to continue.');
end
else if (length(maskedit1.Text)<>maskedit1.MaxLength) then
begin
Showmessage('ID Number not long enough.');
end
else
begin
Showmessage('Could not connect to the server. Please check your internet connection and try again.');
end;
CoUnInitialize;
loading.close;
main.Enabled:=true;
end).start;
更新用户界面:
procedure TMain.updateui;
var
birthdate,deathdate:TDate;
begin
Panel3.Show;
Label57.Caption := 'Change 1';
Label59.Caption := 'Change 2';
Label58.Caption := 'Change 3';
Label60.Caption := 'Change 4';
Label62.Caption := 'Change 5';
Label70.Caption := 'Change 6';
ScrollBox1.Color := clwhite;
end;