自己定制方法和事件(200分)

S

sxqsxq

Unregistered / Unconfirmed
GUEST, unregistred user!
自己定制方法和事件
 
不明白什么意思,自己写的控件还是动态生成的控件?
 
自己写的控件,想提供像 onclick一样的事件
 
你看一下别人的VCL代码就知道了呀。
举例:
Type
TOnShowStatus = procedure(msg : string) of object; //函数名字和参数自己定
TZWMoxa = class(TComponent)
private
...
FOnShowStatus : TOnShowStatus;
...
published
property OnShowStatus : TOnShowStatus read FOnShowStatus write FOnShowStatus;
...
end;
 
如在activeform中,有memo1,当memo1change时,在控件中定义一事件onmemo,
其他程序可从onmemo中读到memo1的内容。
望给完整原码
 
很简单,继承一个TMemo就是了,你自己为什么不试一试呢?

unit ZWMemo;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TOnMemo = procedure(msg : string) of object;
TZWMemo = class(TMemo)
private
{ Private declarations }
FOnMemo: TOnMemo;
protected
{ Protected declarations }
public
{ Public declarations }
procedure Change;override;
published
{ Published declarations }
property OnMemo : TOnMemo read FOnMemo write FOnMemo;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TZWMemo]);
end;

procedure TZWMemo.Change;
begin
if assigned(OnMemo) then OnMemo(text);
if assigned(OnChange) then OnChange(self);
end;

end.

 
zw84611,先给50分,我是说的activex ,非 vcl控件,
 
嘿,我并不在乎分数,但别人的代码不能代替你自己的思考。
ActiveForm和ActiveX控件是有区别的。
另外VCL控件可以非常容易的转换成ActiveX控件。
 
视金钱如粪土,太感动了,倾家当产200分全给了。
还望帮助解决一下,有转换的方法也行。。[:)]
 
顶部