CreateThread中怎么把数据写入VCL中,好像有时候报错 CreateThread中怎么把数据写入VCL中,好像有时候报错 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本帖最后由 bdmh 于 2012-07-07 17:43:45 编辑 procedure TMyThread.Execute;begin inherited; ... Synchronize(MyUpdate); ...end;procedure TMyThread.MyUpdate;begin Form1.StringGrid1.Cells[1, 2] := 100end; function TestThr(s:string): Integer; stdcall;begin Form1.StringGrid1.Cells[1,1]:=s; Result:=0;end;procedure TForm1.Button1Click(Sender: TObject);var H:DWord; s:Pchar;begin s:='Hello World'; Createthread(nil, 0, @TestThr, s, 0, H);end; 还是可以用Synchronize同步的!procedure TForm1.MyUpdate;begin SHowMessage('abc');end;function ThreadFunc(P: Pointer): DWORD; stdcall;var M: TMethod;begin M.Data := Form1; M.Code := @TForm1.MyUpdate; TThread.Synchronize(nil, TThreadMethod(M)); Result := 0end;procedure TForm1.Button1Click(Sender: TObject);var C: Cardinal;begin CreateThread(0, 0, @ThreadFunc, nil, 0, C)end; 多线程下载多个任务,分批下载,及相关问题的请教 Access中导数据时,如何将文本型转化成日期时间型? 图片拼接的问题,如何能拼接多幅图片阿 ◆◆水源升双星,哇咔咔◆◆ VCL的基类是什么?编写控件的基类又是什么?可视化控件的基类又是什么? SQL怎样才能把查出的表中,在DBGRID同一个字段中,只显示相同记录名字的第一个,如下: 科學計數法問題 如何随机地选取任意几条数据 關天Delphi深層的問題? 关于 WinServer2008下IIS7.5配置CGI的问题 出现提示:Constant expression expected 是什么原因 Tpaintbox控件的Refresh等三个方法特点、区别?
begin
inherited;
...
Synchronize(MyUpdate);
...
end;procedure TMyThread.MyUpdate;
begin
Form1.StringGrid1.Cells[1, 2] := 100
end;
begin
Form1.StringGrid1.Cells[1,1]:=s;
Result:=0;
end;procedure TForm1.Button1Click(Sender: TObject);
var
H:DWord;
s:Pchar;
begin
s:='Hello World';
Createthread(nil, 0, @TestThr, s, 0, H);
end;
procedure TForm1.MyUpdate;
begin
SHowMessage('abc');
end;function ThreadFunc(P: Pointer): DWORD; stdcall;
var
M: TMethod;
begin
M.Data := Form1;
M.Code := @TForm1.MyUpdate;
TThread.Synchronize(nil, TThreadMethod(M));
Result := 0
end;procedure TForm1.Button1Click(Sender: TObject);
var
C: Cardinal;
begin
CreateThread(0, 0, @ThreadFunc, nil, 0, C)
end;