Board index » delphi » Problems with a typed procedure/event handler

Problems with a typed procedure/event handler

Hello,

I am using a component in a non-visual environment, and I am trying to write a
procedure for one of the event handlers.  In a visual environment, this isn't
a problem - because I just doubleclick the event in the object inspector.

In the non-visual programming environment, I have a line which manually sets
the procedure which will be be used for the "onevent" handler.  This has
worked fine before, but on this occasion I get the following message :-

"Incompatible types: 'TSessionAvailable' and 'Procedure'"

In this case, "TSessionAvailable" is the datatype of the procedure in the
source unit of the component I am using.

I think I need to tell my own procedure that it needs to be of this type, but
how do I do that???

Help!

--
Jules

--
Still using a normal Newsreader?  Get buzzez.com! (it's not normal)
http://www.buzzez.com

 

Re:Problems with a typed procedure/event handler


Quote
"Jules" <a...@spamdomain.com> wrote in message news:98slrq$tjg$2@news8.svr.pol.co.uk...
> Hello,

> I am using a component in a non-visual environment, and I am trying to write a
> procedure for one of the event handlers.  In a visual environment, this isn't
> a problem - because I just doubleclick the event in the object inspector.

> In the non-visual programming environment, I have a line which manually sets
> the procedure which will be be used for the "onevent" handler.  This has
> worked fine before, but on this occasion I get the following message :-

> "Incompatible types: 'TSessionAvailable' and 'Procedure'"

> In this case, "TSessionAvailable" is the datatype of the procedure in the
> source unit of the component I am using.

> I think I need to tell my own procedure that it needs to be of this type, but
> how do I do that???

??
do you want to call a method procedure pointer???

P1 is a method of  form1, you define these as below
because you have to supply a object to be passed as the 'self'
it must be a real object when assigned and remain so when called
not just a type reference

type Tmp=procedure(sender:Tobject) of object ;
var mp:tmp;

procedure TForm1.P1(Sender: TObject); begin end;

procedure TForm1.P2(Sender: TObject); begin end;
begin
 mp:=form1.P1;
 mp(sender);
 //same as
 P1(sender);   // called as  methodobject.procedurecode(<realobject>,sender);
end;

procedure P3;
begin
 mp:=form1.P1;
 mp(Tobject(Form1.component));
end;

Other Threads