delphi 创建线程的问题 代码报错 5
functionTForm1.MyThreadFun(p:Pointer):Integer;stdcall;vari:Integer;pt2:TPoint;{因为指针参数...
function TForm1.MyThreadFun(p: Pointer): Integer; stdcall;
var
i: Integer;
pt2: TPoint; {因为指针参数给的点随时都在变, 需用线程的局部变量存起来}
begin
try
pt2 := PPoint(p)^; {转换}
for i := 0 to 100000 do
begin
with Form1.Canvas do begin
Lock;
TextOut(pt2.X, pt2.Y, IntToStr(i));
Unlock;
end;
end;
except
on e:Exception do
begin
ShowMessage(e.Message);
end;
end;
Result := 0;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
ID: DWORD;
begin
pt := Point(X, Y);
CreateThread(nil, 0, @TForm1.MyThreadFun, @pt, 0, ID);
end; 展开
var
i: Integer;
pt2: TPoint; {因为指针参数给的点随时都在变, 需用线程的局部变量存起来}
begin
try
pt2 := PPoint(p)^; {转换}
for i := 0 to 100000 do
begin
with Form1.Canvas do begin
Lock;
TextOut(pt2.X, pt2.Y, IntToStr(i));
Unlock;
end;
end;
except
on e:Exception do
begin
ShowMessage(e.Message);
end;
end;
Result := 0;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
ID: DWORD;
begin
pt := Point(X, Y);
CreateThread(nil, 0, @TForm1.MyThreadFun, @pt, 0, ID);
end; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询