delphi多线程编程5

delphi多线程编程5

ID:15332328

大小:68.00 KB

页数:9页

时间:2018-08-02

delphi多线程编程5_第1页
delphi多线程编程5_第2页
delphi多线程编程5_第3页
delphi多线程编程5_第4页
delphi多线程编程5_第5页
资源描述:

《delphi多线程编程5》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、delphi多线程编程5窗体文件:objectForm1:TForm1 Left=0 Top=0 Caption='Form1' ClientHeight=206 ClientWidth=371 Color=clBtnFace Font.Charset=DEFAULT_CHARSET Font.Color=clWindowText Font.Height=-11 Font.Name='Tahoma' Font.Style=[] OldCreateOrder=False OnDestroy=FormDest

2、roy PixelsPerInch=96 TextHeight=13 objectPaintBox1:TPaintBox  Left=8  Top=8  Width=114  Height=153 end objectPaintBox2:TPaintBox  Left=128  Top=8  Width=114  Height=153 end objectPaintBox3:TPaintBox  Left=248  Top=8  Width=114  Height=153 end objectButton

3、1:TButton  Left=288  Top=172  Width=75  Height=25  Caption='Button1'  TabOrder=0  OnClick=Button1Click endend  可以借助入口函数的参数,把这个程序简化一下(窗体和运行效果不变):unitUnit1;interfaceuses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms, Dialogs,StdCtrls,Ex

4、tCtrls;type TForm1=class(TForm)  PaintBox1:TPaintBox;  PaintBox2:TPaintBox;  PaintBox3:TPaintBox;  Button1:TButton;  procedureButton1Click(Sender:TObject);  procedureFormDestroy(Sender:TObject); end;var Form1:TForm1;implementation{$R*.dfm}var h1,h2,h3:THa

5、ndle;{线程的入口函数:不同的线程画不同颜色的椭圆}functionThreadFun(p:Pointer):Integer;stdcall;var i,x1,y1,x2,y2:Integer; paint:TPaintBox;begin caseInteger(p)of  1:begin   paint:=Form1.PaintBox1;   paint.Canvas.Brush.Color:=clRed;  end;  2:begin   paint:=Form1.PaintBox2;   pai

6、nt.Canvas.Brush.Color:=clGreen  end;  3:begin   paint:=Form1.PaintBox3;   paint.Canvas.Brush.Color:=clBlue;  end; end; fori:=0to5000dowithpaintdo begin  x1:=Random(Width);y1:=Random(Height);  x2:=Random(Width);y2:=Random(Height);  Canvas.Lock;  Canvas.Ell

7、ipse(x1,y1,x2,y2);  Canvas.Unlock;  Sleep(0); end; Result:=0;end;procedureTForm1.Button1Click(Sender:TObject);var ID:DWORD;begin h1:=CreateThread(nil,0,@ThreadFun,Ptr(1),0,ID); h2:=CreateThread(nil,0,@ThreadFun,Ptr(2),0,ID); h3:=CreateThread(nil,0,@Thread

8、Fun,Ptr(3),0,ID);end;procedureTForm1.FormDestroy(Sender:TObject);begin CloseHandle(h1); CloseHandle(h2); CloseHandle(h3);end;end. 多用点数组,再简化一下(窗体与效果一样):unitUnit1;interfaceuses Windows,Messages,SysUtils,Variants,Class

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。