趣百科

delphi多线程应用

编辑:Simone 2025-02-02 08:01:04 616 阅读

delphi多线程应用

在这里我教大家如何使用Delphi语言的多线程

第一步:安装好Delphi,并打开;

第二步:给Delphi窗体上加一个Button按钮,一个statictext;

第三部:给button 按钮写点击的代码;代码这样写:

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Buttons;

type

TForm1 = class(TForm)

BitBtn1: TBitBtn;

procedure BitBtn1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

function MyThreadFunc(P:pointer):Longint;stdcall;

var

i:longint;

DC:HDC;

S:string;

begin

DC:=GetDC(Form1.Handle);

for i:=0 to 500000 do begin

S:=Inttostr(i);

Textout(DC,10,10,Pchar(S),length(S));

end;

ReleaseDC(Form1.Handle,DC);

end;

procedure TForm1.Button1Click(Sender: TObject);

var

hThread:Thandle;//定义一个句柄

ThreadID:DWord;

begin

//创建线程,同时线程函数被调用

hthread:=CreateThread(nil,0,@MyThreadfunc,nil,0,ThreadID);

if hThread=0 then

end;

版权声明:本站【趣百科】文章素材来源于网络或者用户投稿,未经许可不得用于商用,如转载保留本文链接:https://www.qubaik.com/life/127987.html

相关推荐