Board index » delphi » Firing the Exit events on form

Firing the Exit events on form

I need to be able to modify the text from any of my tedit or comboboxes
on a form and call the exit event for that component if it is of that
type.  I don't have a way to know the name of the component so I can't
use <componentnameexit>.  I need to be able to use something like the
form.controlcount or form .componentcount and be able to process from
that list.
 

Re:Firing the Exit events on form


Quote
In article <37BC907E.788A3...@pfshouston.com>, Rafel Coyle wrote:
> I need to be able to modify the text from any of my tedit or comboboxes
> on a form and call the exit event for that component if it is of that
> type.

What are you actually trying to achieve?

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03)
 (Unsolicited e-mail replies will most likely be ignored)

Re:Firing the Exit events on form


Quote
> I need to be able to modify the text from any of my tedit or comboboxes
> on a form and call the exit event for that component if it is of that
> type.  I don't have a way to know the name of the component so I can't
> use <componentnameexit>.  I need to be able to use something like the
> form.controlcount or form .componentcount and be able to process from
> that list.

The usual solution if you have only a few control classes to handle is

  for i:= 0 to componentcount-1 do
    if Components[i] Is Tedit Then
      with TEdit( Components[i] ) do begin
        ..do stuff with text
      end
    Else if Components[i] Is TCombobox Then
      with TCombobox( Components[i] ) do begin
        ..do stuff with text
      end

For more classes it gets cumbersome if you cannot identify a common
ancestor class that already has the properties you need accessible
(public or published). In this case the RTTI functions in unit TypInfo
can often be a boon. The allow you to find out if a given object has a
published property of a certain name, you can check the type of the
property and even access it in a generic way. Only works for published
stuff, though. If you go to http://www.dejanews.com,
http://www.mers.com/searchsite.html, or http://developers.href.com and
search the newsgroups for GetPropInfo you will find tons of examples.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:Firing the Exit events on form


Peter I have the examples that you wrote below, however,  please show me how
you would fire the exit event of the tedit within the loop.

Thanks

Quote
"Peter Below (TeamB)" wrote:
> > I need to be able to modify the text from any of my tedit or comboboxes
> > on a form and call the exit event for that component if it is of that
> > type.  I don't have a way to know the name of the component so I can't
> > use <componentnameexit>.  I need to be able to use something like the
> > form.controlcount or form .componentcount and be able to process from
> > that list.

> The usual solution if you have only a few control classes to handle is

>   for i:= 0 to componentcount-1 do
>     if Components[i] Is Tedit Then
>       with TEdit( Components[i] ) do begin
>         ..do stuff with text
>       end
>     Else if Components[i] Is TCombobox Then
>       with TCombobox( Components[i] ) do begin
>         ..do stuff with text
>       end

> For more classes it gets cumbersome if you cannot identify a common
> ancestor class that already has the properties you need accessible
> (public or published). In this case the RTTI functions in unit TypInfo
> can often be a boon. The allow you to find out if a given object has a
> published property of a certain name, you can check the type of the
> property and even access it in a generic way. Only works for published
> stuff, though. If you go to http://www.dejanews.com,
> http://www.mers.com/searchsite.html, or http://developers.href.com and
> search the newsgroups for GetPropInfo you will find tons of examples.

> Peter Below (TeamB)  100113.1...@compuserve.com)
> No e-mail responses, please, unless explicitly requested!

Re:Firing the Exit events on form


Quote
In article <37BD8489.404FC...@pfshouston.com>, Rafel Coyle wrote:
> Peter I have the examples that you wrote below, however,  please show me how
> you would fire the exit event of the tedit within the loop.

In this case the easiest method is to send the same message to the control the
VCL itself sends to trigger the Exit event:

      with TEdit( Components[i] ) do begin
        ..do stuff with text
        Perform( CM_EXIT, 0, 0 );
      end

The DoExit method which calls the Onexit handler is protected in TWincontrol,
so you cannot  call it directly. But sending the message will make the control
call it for you. The neat thing about using messages is that you can send them
to any TControl without bothering to check if the control knows what to do
with the message, if it does not it will simply ignore the message. CM_EXIT
fill fire the OnExit event for every TWinControl descendent, for example.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:Firing the Exit events on form


Thanks Peter,  This might do the trick.
Quote
"Peter Below (TeamB)" wrote:
> In article <37BD8489.404FC...@pfshouston.com>, Rafel Coyle wrote:
> > Peter I have the examples that you wrote below, however,  please show me how
> > you would fire the exit event of the tedit within the loop.

> In this case the easiest method is to send the same message to the control the
> VCL itself sends to trigger the Exit event:

>       with TEdit( Components[i] ) do begin
>         ..do stuff with text
>         Perform( CM_EXIT, 0, 0 );
>       end

> The DoExit method which calls the Onexit handler is protected in TWincontrol,
> so you cannot  call it directly. But sending the message will make the control
> call it for you. The neat thing about using messages is that you can send them
> to any TControl without bothering to check if the control knows what to do
> with the message, if it does not it will simply ignore the message. CM_EXIT
> fill fire the OnExit event for every TWinControl descendent, for example.

> Peter Below (TeamB)  100113.1...@compuserve.com)
> No e-mail responses, please, unless explicitly requested!

Re:Firing the Exit events on form


One last question.  Is there a way to tell if the component has an exit event
assigned.
Quote
"Peter Below (TeamB)" wrote:
> In article <37BD8489.404FC...@pfshouston.com>, Rafel Coyle wrote:
> > Peter I have the examples that you wrote below, however,  please show me how
> > you would fire the exit event of the tedit within the loop.

> In this case the easiest method is to send the same message to the control the
> VCL itself sends to trigger the Exit event:

>       with TEdit( Components[i] ) do begin
>         ..do stuff with text
>         Perform( CM_EXIT, 0, 0 );
>       end

> The DoExit method which calls the Onexit handler is protected in TWincontrol,
> so you cannot  call it directly. But sending the message will make the control
> call it for you. The neat thing about using messages is that you can send them
> to any TControl without bothering to check if the control knows what to do
> with the message, if it does not it will simply ignore the message. CM_EXIT
> fill fire the OnExit event for every TWinControl descendent, for example.

> Peter Below (TeamB)  100113.1...@compuserve.com)
> No e-mail responses, please, unless explicitly requested!

Re:Firing the Exit events on form


Quote
In article <37C170AE.44C38...@pfshouston.com>, Rafel Coyle wrote:
> Is there a way to tell if the component has an exit event
> assigned.

I think D4 will accept

  If Assigned( TEdit( components[i] ).OnExit ) Then
  ...

This does not work in earlier versions if i remember correctly. There
one had to use a local variable as mediator:

 var
   ev: TNotifyEvent;
 begin
   ....
   ev:= TEdit( components[i] ).OnExit;
   If Assigned( ev ) Then
     ....

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Other Threads