为什么不直接用TThread呢
我改动了以下,编译不出错了,结果可能会出错,你看看
声明 ……
TActiveFormX = class(TActiveForm, IActiveFormX)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
FEvents: IActiveFormXEvents;
procedure ActivateEvent(Sender: TObject);
procedure ClickEvent(Sender: TObject);
procedure CreateEvent(Sender: TObject);
procedure DblClickEvent(Sender: TObject);
procedure DeactivateEvent(Sender: TObject);
procedure DestroyEvent(Sender: TObject);
procedure KeyPressEvent(Sender: TObject
var Key: Char);
procedure PaintEvent(Sender: TObject);
function MyThreadFunc(P: pointer): Longint
stdcall;
protected
定义……
function [blue]TActiveFormX[/blue].MyThreadFunc(P
ointer):Longint;stdcall;
var
i:longint;
DC:HDC;
S:string;
begin
DC:=GetDC(Self.Handle);
for i:=0 to 500000 do begin
S:=Inttostr(i);
Textout(DC,10,10,Pchar(S),length(S));
end;
ReleaseDC(Self.Handle,DC);
end;
procedure TActiveFormX.Button1Click(Sender: TObject);
var
hThread:Thandle;//定义一个句柄
ThreadID
Word;
begin
//创建线程,同时线程函数被调用
hthread:=CreateThread(nil,0[blue],@TActiveFormX.MyThreadfunc[/blue],nil,0,ThreadID);
if hThread=0 then
messagebox(Handle,'Didn’tCreateaThread',nil,MB_OK);
end;
procedure TActiveFormX.Button2Click(Sender: TObject);
begin
MyThreadfunc(nil);
//没有创建线程时,直接调用线程函数
end;