线程中设置FONT属性,为什么僵死了,哪位高手能告诉小弟我如何解决
线程中设置FONT属性,为什么僵死了,谁能告诉我怎么解决
------解决方案--------------------
需要使用方法同步到主线程
具体参考
http://www.cnblogs.com/cardon/archive/2010/03/10/1682130.html
------解决方案--------------------
线程中不能调用了GDI对象,这是多线程程序设计的规矩。
界面的事情只能主线程自己解决,主线程可以接收工作线程的通知消息,然后根据消息刷新界面。
procedure TDisplayWordThread.Execute;
var
tmpStr, Word: string;
I: Integer;
begin
while not Terminated do
begin
Sleep(10);
if aString.Count > 0 then
begin
tmpStr:=aString[0];
aString.Delete(0);
with TLabel.Create(frmMain) do
begin
Parent := frmMain;
//EnterCriticalSection(Critical1);
Font.Name := '黑体'; //调试这一步就不动了,不知道为什么
//Font.Size := 20;
//Font.Color := clRed;
//Font.Style := [fsBold];
//LeaveCriticalSection(Critical1);
Name := 'lb_' + IntToStr(iCount);
Caption := tmpStr + IntToStr(iCount);
Left := 10;
Top := 10;
Height := 30;
Width := frmMain.Width - 40;
Inc(iCount);
end;
end;
end;
end;
------解决方案--------------------
需要使用方法同步到主线程
具体参考
http://www.cnblogs.com/cardon/archive/2010/03/10/1682130.html
------解决方案--------------------
线程中不能调用了GDI对象,这是多线程程序设计的规矩。
界面的事情只能主线程自己解决,主线程可以接收工作线程的通知消息,然后根据消息刷新界面。