delphi多執行緒程式示例

2021-04-02 06:09:26 字數 1511 閱讀 9468

delphi多執行緒程式示例(與.net一樣簡單) 選擇自 yonny 的 blog

關鍵字delphi多執行緒程式示例(與.net一樣簡單)

出處(*----下面這個程式介紹了我們在使用執行緒及未使用執行緒二種情況下,執行該程式的反

應。當點usedthread按鈕時,則建立乙個執行緒,這時我們可以在程式進行計算的同

時,改變窗體的尺寸及移動它。當按下nousedthread按鈕時,不建立執行緒,我們會發

現在程式沒有計算完之前根本不能做其它任何事情!

unit unit1;

inte***ce

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

public

end;

varform1: tform1;

implementation

function mythreadfunc(p:pointer):longint;stdcall;

vari: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);

varhthread: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.

delphi 多執行緒

摘自 萬一的部落格 functionmyfun p pointer integer stdcall var i integer begin fori 0to500000do begin form1.canvas.lock form1.canvas.textout 10,10,inttostr i f...

delphi 多執行緒

看別人的部落格一萬次記憶效果也沒那麼好,還是自己動手寫寫吧!functioncreatethread lpthreadattributes pointer dwstacksize dword lpstartaddress tfnthreadstartroutine lpparameter point...

多執行緒示例

include include include pthread t thread 2 pthread mutex t mut int num 0 void thread1 void args pthread exit null void thread2 void args pthread exit ...