这种情况应如何定义事件。(99分)

  • 主题发起人 主题发起人 koenemy
  • 开始时间 开始时间
K

koenemy

Unregistered / Unconfirmed
GUEST, unregistred user!
线程Execute函数的值,怎么用自定义的事件返回
unit ExecuteHandler;
interface
uses
Classes, SearchBase;
type
TExecuteHandler = class(TThread)
private
TS: TSearchBase;
FOnGetPlace: TNotifyEvent;//这块定义一个事件,,有问题嘛
protected
procedure Execute;
override;
public
constructor Create(CreateSuspended: Boolean;
TS: TSearchBase);
published
property OnGetPlace: TNotifyEvnet read FOnGetPlace write FOnGetPlace;//这块总提示找不着TNotifyEvnet
end;
implementation
{ TExecuteHandler }
constructor TExecuteHandler.Create(CreateSuspended: Boolean;
TS: TSearchBase);
begin
FreeOnTerminate := True;
Self.TS := TS;
inherited Create(CreateSuspended);
end;
procedure TExecuteHandler.Execute;
var
place: string;
begin
place := self.TS.GetPlace;
if self.Terminated then
begin
if Assigned(OnGetPlace) then
OnGetPlace(place);//在这触发这事件,参数place对不
exit;
end;
end;
end.
 
TNotifyEvnet标识的事件,参数都是tobjcet的哦,不是string的撒!你全文检索一下关于tnotifyevent和关于自定义事件的帖子,我回答不权威,嘿嘿!
 
是不是事件的类型不对呀
 
里面的参数类型不对撒,你不如找一个第三方控件来看看,看别人是怎么添加自定义事件 的撒!
 
恩,你可以先定义一个新的事件类型,参数是String的。比如
TNewEvent = procedure(AStr: string) of object;
然后再定义FOnGetPlace: TNewEvent;
 
如果是定义已知类型的事件最好参数是一样的,否则你还不如使用消息
 
老大们,,,,给写点代码,,如何定义一个事件,,参数是string ,,如何触发,如何调用
 
相当的感谢。
unit ExecuteHandler;
interface
uses
Classes, SearchBase;
type
TOnGetPlace = procedure(place: string) of object;
TExecuteHandler = class(TThread)
private
TS: TSearchBase;
FOnGetPlace: TOnGetPlace;
protected
procedure Execute;
override;
public
constructor Create(CreateSuspended: Boolean;
TS: TSearchBase);
property OnGetPlace: TOnGetPlace read FOnGetPlace write FOnGetPlace;
end;

implementation

{ TExecuteHandler }
constructor TExecuteHandler.Create(CreateSuspended: Boolean;
TS: TSearchBase);
begin
FreeOnTerminate := True;
Self.TS := TS;
inherited Create(CreateSuspended);
end;

procedure TExecuteHandler.Execute;
var
place: string;
begin
place := self.TS.GetPlace;
if Assigned(OnGetPlace) then
OnGetPlace(place);
if self.Terminated then
exit;
end;

end.

结果是这样的。呵呵呵
 
后退
顶部