求助!在DLL中定位事件句柄(TNotifyEvent)的语法.(200分)

  • 主题发起人 主题发起人 CZHEN
  • 开始时间 开始时间
C

CZHEN

Unregistered / Unconfirmed
GUEST, unregistred user!
在我的DLL中,有一个对象,设为object_my:Tobject_my.
它有这样一个属性 property OnSomething: TNotifyEvent
published;
现在要把一个事件句柄定位到一个函数:
procedure Something(Sender: TObject)
begin
ready_yn:=true;
end

ready_yn为全局变量.

我用 object_my.Onsomething:=somthing;
编译不通过.

这里的语法如何解决.(函数定义,句柄定位).

十万火急.

我要回家!

 
You need a private variable to hode the instance of the notify event.

TObject_My = class(TControl)
provate
fOnSomethine: TNotifyEvent;
published
Property OnSomethine: TNotifyEvent read fOnSomething write fOnSomething;
end;

Besides above, you need to add a trigger as a result of something happened. That means your control must know when to call the event
handler. There are two ways to trigger your event, by windows message or by control itself.

By windows message is a little bit comfusing, and you need to write
a message handler as well. It needs some kind of planning.
By control itself is much simple. Such as responce to one of the
property change, you can do:

ptocedure TObject_My.SetXXXProperty(value: valueType);
begin
if value <> fXXX then
begin
fxxx:=value;
if assigned(fOnSomething) then fOnSomething(self);
end;
end;

That's all for now, I want to go home.
 
没有数据!属性必须读写实际的数据!你定义一个TNotifyEvent的变量!
 
定义一个基类,把something过程作为基类的publish方法再赋值
好像也可以。such as:
type TTest=class
published
procedure something(sender:Tobject);
end;
知其然,不知其所以然。:-(
 
这样好像类型才匹配。
 
TNotifyEvent是event of object!
 
不过可以用。
 
接受答案了.
 
to CZHEN:

问题是怎样解决的? 应该给一个结论, 否则别人还是不知其所以然.
 
解决方案如下:
定义Tsomething_my的子类Tson,增加方法set_ready;
这样set_ready即为TNotifyEvent型.

type
TSon=class(TSomthing_my)
procedure set_ready(sender:Tobject);
end;

var
Son:Tson;

Init
begin
son:=Tson.create;
son.onsomthing:=son.set_ready;
end;

set_ready
begin
ready_yn:=true;
end



另有一问题如下:(已提出, 分值200,Object Pascal版)
小弟用DELPHI3.0编了一个Dll, 需在VC5中调用. 调用者和DLL均用
stdcall调用约定. 但无法用参数返回数值.

请教各位大虾如何返回数组和单个参数.(var和指针均已尝试)

dll:

type
a=array[0..3] of byte;
p=^a;

function Set_para_array(var irq:a):byte;stdcall;
begin
irq[0]:=1;
irq[1]:=1;
irq[2]:=1;
irq[3]:=1;
end;

function Set_para_one(var one:byte):byte;stdcall;
begin
one:=11;
end;

exports
set_para_one, set_para_array;

c:
typedef BYTE m_Set_para_one(byte *one);
typedef BYTE m_Set_para_array(byte one[]);

int a;
int b[4];
//LoadLib等省
//调用:
set_para_one(&amp;a);
set_para_array(b);

指针,VAR,变量本身的各种组合作VC和DELPHI的参数几乎均已尝试,未果.

求助!求助!求助!求助!求助!
 
后退
顶部