如何处理自定义的类中的属性的消息?(200分)

子陵

Unregistered / Unconfirmed
GUEST, unregistred user!
有类如下定义
type
TAttribute=class
FControl:TControl;
FLabel:TLabel
...
end;
其中,FControl可能时TEdit.TMemo等
现在我想处理FControl的OnSize消息,请问该如何处理.

另外,如果我在程序中得到FControl实例的句柄和地址,如何得到TAttribute的指针
 
type
TAttribute=class
private
procedure OnSize(xxx,xxx,xxx);
FMemo:TMemo;
FLabel:TLabel
...
end;

construcrotr create()
{
FMemo_OnSize:=OnSize;
}

procedure OnSize(xxx.xxx)
{
//在这里处理。。。
}
 
看一下在线文档中关于事件的例子!
 
但是TMemo和TEdit没有OnSize消息啊
可以截取他们的WMSize消息吗,谁知道啊?
 
>>但是TMemo和TEdit没有OnSize消息啊
那么他们怎么会产生OnSize事件呢? 你处理什么?
 
1.
type
TAttribute=class
private
FControl:TControl;
FLabel:TLabel
FControlOnSize:TNotifyEvent;
procedure SetControlOnSize(value:TNotifyEvent);
function ReadControlOnSize:TNotifyevent;
...
pubished
Property ControlOnSize :TNotifyEvent read ReadControlOnSize write SetControlOnSize;
....
fucntion TAttribute.ReadControlOnSize:TNotifyEvent;
begin
Result := Fcontrol.onsize;
end;

procedure TAttribute.SetControlOnSize(value:TNOtifyEvent);
begin
if FControl.OnSize <> value then
FControl.OnSize := value;
end;


2.
constructor TAttribute.create(owner:Tobject);
begin
FControl := TFcontrol.create(self);
.......
end;
这样同过Fcontrol的owner属性就可找到TAttribute;
 
to xeen
Result := Fcontrol.onsize;出错,TControl没有OnSize事件
再问一下,如果FControl时TEdit类型的,TEdit没有OnSize事件,那它有WMSize消息吗
如果有,如何捕获.
 
最好别用TControl,用TWinControl;肯定有WMSize
 
通过TWinControl的WindowProc方法可捕获WM_SIZE和其他WM_XXX类消息:

unit Unit1;

interface

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

type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
OldWinProc: TWndMethod;
procedure NewWinProc(var Message: TMessage);
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.NewWinProc(var Message: TMessage);
begin
case Message.Msg of
WM_SIZE: caption := caption + 'size';
end
//end of case
OldWinProc(Message);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
OldWinProc := ListBox1.WindowProc;
ListBox1.WindowProc := NewWinProc;
end;

end.
 
TEdit的窗口应该也有WM_Size消息,但这个类没把这个消息封装成一个
事件.关于如何截获消息可以去看话题094911
 
声明一个方法指针来截获相应的消息

在你需要的时候连接这个方法指针,相应消息事件
 
多人接受答案了。
 
顶部