java gui 多线程 界面更新_多线程 – 如何使用Delphi从Thread更新GUI

在使用Delphi编程时,开发者遇到了一个问题,即在匿名线程中更新图形用户界面(GUI)导致窗口句柄无效的错误。尝试使用Synchronize方法调用updateui函数进行同步更新,但遇到了编译错误E2066。错误发生在尝试同步更新GUI的代码行,可能是因为语法错误或上下文使用不当。解决方案可能涉及正确使用Synchronize方法或者寻找替代方案以在多线程环境中安全地更新GUI。
摘要由CSDN通过智能技术生成

我正在使用Delphi匿名线程来执行代码.

在线程的中间,必须进行一些GUI更新,一些标签更改等.

如果我从线程内部执行此操作,则会发生更改,但一旦线程停止.他们消失了,然后应用程序给我旧的窗口处理程序错误…(这是预期的)

系统错误.编号:1400.窗口句柄无效

我尝试使用Syncronize(updateui);执行更改的方法(将它们移动到一个单独的函数),但我在syncronize E2066 Missing操作符或分号上得到一个错误,这对我来说根本没有意义……

我一页又一页地搜索过,他们似乎都这么称呼它,但是当我这样做时,我得到了上述错误……

我说错了吗?

码:

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;

UpdateUI:

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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值