Board index » delphi » passing actual parameter to Events handlers?

passing actual parameter to Events handlers?

Hello,

I am wondering if it is possible to dictate at run time what actual
parameters are passed to event handlers for Delphi built-in events?

For example, consider

TTabChangingEvent = procedure (Sender: TObject; var AllowChange:
Boolean) of object;

To allow/disallow tab changing, one could simply pass true/false
respectively to the event handler, which is a empty procedure.  I think
this is neater than writing two procedures to handle the two cases.

Any thoughts?

 

Re:passing actual parameter to Events handlers?


Jeffrey -

 > I am wondering if it is possible to dictate at run time what actual
 > parameters are passed to event handlers for Delphi built-in events?
 > For example, consider
 > TTabChangingEvent = procedure (Sender: TObject; var AllowChange:
 > Boolean) of object;
 > To allow/disallow tab changing, one could simply pass true/false
 > respectively to the event handler, which is a empty procedure.  I think
 > this is neater than writing two procedures to handle the two cases.

Perhaps I am missing the point of your question. But the whole idea of
this event handler is to ask your application whether this particular
object should be allowed to change to a new tab, and to allow your
application to take any other actions required in conjunction with
that.

If you choose not to supply an event handler, the default is to allow
the change. (Which makes at least some sense, since you'd otherwise be
stuck on that first page forever.) So, effectively, there is a default
True result, because a False result would make no sense.

All of that said, since I missed the entire concept of your question,
can you expand  a bit?

Good luck.

Kurt

Re:passing actual parameter to Events handlers?


Kurt Barthelmess (TeamB) asked for clarification.  Let me try to be more
explicit.

I want to allow tab changes sometimes but not others.  So the way I do it now
is to create *two* different event handlers:  one to set AllowChange to be
true, the other sets it to false.  Each is assigned to the OnChaning event
property as appropriate.  This works fine.

Now, wouldn't it be neater if I can just write a *single* event handler (which
really does nothing; ie. an empty procedure).  Since the handler, as typed by
TTabChangingEvent, accepted a var parameter AllowChange, if one can pass to it
the appropriate value for that parameter, this would be effectively the same
as the other way above.  So I am trading 2 procedures for 2 passed values.

The OnChanging event detects tab changes.  But I don't know how I can change
the AllowChange parameter passed along.

^D

Quote
> Jeffrey -

>  > I am wondering if it is possible to dictate at run time what actual
>  > parameters are passed to event handlers for Delphi built-in events?
>  > For example, consider
>  > TTabChangingEvent = procedure (Sender: TObject; var AllowChange:
>  > Boolean) of object;
>  > To allow/disallow tab changing, one could simply pass true/false
>  > respectively to the event handler, which is a empty procedure.  I think
>  > this is neater than writing two procedures to handle the two cases.

> All of that said, since I missed the entire concept of your question,
> can you expand  a bit?

> Good luck.

Re:passing actual parameter to Events handlers?


Jeffrey,

who forces you to assign True or False directly to AllowChanges? You can assign
it the value of a Boolean field of your form, for example, or evaluate some
expression to see what you should return (the same sort of descision you now
make on what handler to use). You only need one handler.

Peter Below (TeamB)  100113.1...@compuserve.com)

Other Threads