如何设计类似TreeViewOnChange的自定义事件 ( 积分: 50 )

  • 主题发起人 主题发起人 月满C楼
  • 开始时间 开始时间

月满C楼

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TFormMain.fcTreeView1OnChange(TreeView: TfcCustomTreeView;
Node: TfcTreeNode);//node上是你选定了的节点,在事件处理过程中你是可以读取该节点的相关信息的。

好,现在来看一下我定义的类
type
TParent=class(TObject)
private
S:string;//假设S:='hello;
FTimeOut:TNotifyEvent;
protected
procedure SetTimeOut;dynamic;
public

published
property OnTimeOut:TNotifyEvent read FTimeOut write SetTimeOut;
end;

implementation

procedure TTimeCount.SetTimeOut;
begin
if Assigned(FTimeOut) then
FTimeOut(Self);
//调用事件过程时要把类中私有变量S的值传出去事件事件处理过程
//这样就相当于:
{
m_parentOnTimeOut(sender:Tobject;S:string;);
showmessage(S);//就得到信息框hello了
}
end;

end;//class
 
type
TMyEvent = procedure(Sender: TObject; Str: string) of object;

TParent = class(TObject)
private
S: string;//假设S:='hello;
FTimeOut: TMyEvent;
protected
procedure SetTimeOut; dynamic;
public
published
property OnTimeOut: TMyEvent read FTimeOut write FTimeOut;
end;

implementation

{ TParent }

procedure TParent.SetTimeOut;
begin
if Assigned(FTimeOut) then FTimeOut(Self, S);
end;
 
后退
顶部