大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> delphi多线程程序示例

delphi多线程程序示例

时间: 2021-07-31 作者:daque

unit unit1;interface

uses  windows, messages, sysutils, variants, classes, graphics, controls, forms,  dialogs, stdctrls, buttons;

type  tform1 = class(tform)    usedthread: tbitbtn;    nousedthread: tbitbtn;    procedure usedthreadclick(sender: tobject);    procedure nousedthreadclick(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.usedthreadclick(sender: tobject);var  hthread:thandle;//设置一个句柄  threadid:dword;begin//创造线程,同声线程因变量被挪用  hthread:=createthread(nil,0,@mythreadfunc,nil,0,threadid);  if hthread=0 then  messagebox(handle,'didn’tcreateathread',nil,mb_ok);end;

procedure tform1.nousedthreadclick(sender: tobject);begin  mythreadfunc(nil);  //没有创造线程时,径直挪用线程因变量end;end.

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.