[阅读: 754] 2005-01-19 06:25:08
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
tyw = class
public
TmpIntA: integer;
TmpIntB: integer;
TmpIntC: integer;
end;
pyw = ^tyw;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function ExecThread(tmpA,tmpB:integer):integer;
function GetSumAB(Tmpyw:pyw):integer;
end;
type
TMyThread = class(TThread)
private
protected
procedure Execute;override;
public
ptmpYW :PYW;
constructor Create(Tmpyw:pyw);virtual;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.ExecThread(tmpA,tmpB:integer):integer;
var
yw : pyw;
fyw: tyw;
begin
fyw := tyw.Create;
yw := @fyw;
fyw.TmpIntA := 1;
fyw.TmpIntB := 2;
if GetSumAB(yw) = 0 then
showmessage(IntToStr(yw.TmpIntC));
end;
function TForm1.GetSumAB(Tmpyw:pyw):integer;
begin
//这里创建一个线程,在线程中执行fyw.TmpIntA和fyw.TmpIntB的和,然后赋给fyw.TmpIntC
result := 1;
try
TMyThread.Create(Tmpyw);
result := 0;
except
result := 1;
end;
end;
constructor TMyThread.Create(Tmpyw:pyw);
begin
inherited Create(True);
FreeOnTerminate := True;
Resume;
end;
procedure TMyThread.Execute;
begin
ptmpYW.TmpIntC := ptmpYW.TmpIntB + ptmpYW.TmpIntA;
/////////////////在此处设置断点后,ptmpYW.TmpIntC的值是Inaccessible value//////////////////
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ExecThread(1,2);
end;
end.