我是这么写的,但是并没有达到我需要的效果IProcess = interface
function GetFlag: Boolean;
procedure SetFlag(Value: Boolean);
function GetData: Integer;
end;TProcess = class(TInterfacedObject, IProcess)
private
FFlag: Boolean; //FData已修改未读取时 为True;其它状态为False
FData: True;
public
function GetFlag: Boolean;
procedure SetFlag(Value: Boolean);
function GetData: Integer;
constructor Create; override;
procedure Robot;
end;TShowDataThrd = class(TThread)
private
FProcess: IProcess;
protected
procedure Execute; override;
public
constructor Create(AProcess: IProcess);
end;implementation{TProcess}
constructor TProcess.Create;
begin
inherited;
Self.FFlag := Flase;
end;procedure TProcess.Robot;
begin
Self.FData := 0;
repeat
while Self.FFlag do Sleep(1);
Inc(Self.FData);
Self.FFlag := True;
until Self.FData < 1000; Self.FFlag := False;
end;function TProcess.GetFlag: Boolean;
begin
Result := Self.FFlag;
end; procedure TProcess.SetFlag(Value: Boolean);
begin
Self.FFlag := True;
end;function TProcess.GetData: Integer;
begin
Result := Self.FData;
end;
{TShowDataThrd}
constructor TShowDataThrd.Create(AProcess: IProcess);
begin
inherited Create(True);
Self.FProcess := AProcess;
end;procedure TShowDataThrd.Execute;
begin
try
while not Terminated do
begin
while not Self.FProcess.GetFlag do Sleep(1);
//... Show Data
Self.FProcess.SetFlag(False);
end;
except
Terminate;
end;
end;--------------------------------------------------
// 启用的地方
procedure TForm1.Button1Click(Sender: TObject);
var
Prcs: TProcess;
Thrd: TShowDataThrd;
begin
Prcs := TProcess.Create;
Thrd := TShowDataThrd.Create(IProcess(Prcs)); try
Thrd.Resume;
Prcs.Robot;
finally
Thrd.Free;
Prcs.Free;
end;
end;
function GetFlag: Boolean;
procedure SetFlag(Value: Boolean);
function GetData: Integer;
end;TProcess = class(TInterfacedObject, IProcess)
private
FFlag: Boolean; //FData已修改未读取时 为True;其它状态为False
FData: True;
public
function GetFlag: Boolean;
procedure SetFlag(Value: Boolean);
function GetData: Integer;
constructor Create; override;
procedure Robot;
end;TShowDataThrd = class(TThread)
private
FProcess: IProcess;
protected
procedure Execute; override;
public
constructor Create(AProcess: IProcess);
end;implementation{TProcess}
constructor TProcess.Create;
begin
inherited;
Self.FFlag := Flase;
end;procedure TProcess.Robot;
begin
Self.FData := 0;
repeat
while Self.FFlag do Sleep(1);
Inc(Self.FData);
Self.FFlag := True;
until Self.FData < 1000; Self.FFlag := False;
end;function TProcess.GetFlag: Boolean;
begin
Result := Self.FFlag;
end; procedure TProcess.SetFlag(Value: Boolean);
begin
Self.FFlag := True;
end;function TProcess.GetData: Integer;
begin
Result := Self.FData;
end;
{TShowDataThrd}
constructor TShowDataThrd.Create(AProcess: IProcess);
begin
inherited Create(True);
Self.FProcess := AProcess;
end;procedure TShowDataThrd.Execute;
begin
try
while not Terminated do
begin
while not Self.FProcess.GetFlag do Sleep(1);
//... Show Data
Self.FProcess.SetFlag(False);
end;
except
Terminate;
end;
end;--------------------------------------------------
// 启用的地方
procedure TForm1.Button1Click(Sender: TObject);
var
Prcs: TProcess;
Thrd: TShowDataThrd;
begin
Prcs := TProcess.Create;
Thrd := TShowDataThrd.Create(IProcess(Prcs)); try
Thrd.Resume;
Prcs.Robot;
finally
Thrd.Free;
Prcs.Free;
end;
end;
解决方案 »
- 服务器端怎么知道客户端发送的数据格式?(用的TTCP)
- 高手快来指点一下啊..在局域网中,如何获得连接到本机的主机名/IP
- 用Delphi开放一个三层结构的Web应用程序,一般怎么做?要用到哪些控件(一定要是Delphi自带的)
- 如何实现类似windows桌面图像拖动的效果?
- 数据导入道word的问题
- 紧急:Delphi6安装程序汉化问题?
- 请问在Form1打开Form2的同时如何暂停Form1的其它操作
- 在delphi中怎样利用TTbale控件来实现数据库的修改,就是update了。急!!!!
- 哪儿有BDE驱动引擎可下,,,急....!!!!
- 天,就这么一个问题就没人回答了吗??!!
- ado嵌套事务问题
- 有谁见过这个问题吗?我碰到过两次了
谢谢