Board index » delphi » Procedure EditExit(Sender : TObject);

Procedure EditExit(Sender : TObject);

Hi,

Can anyone tell me wheter (and perhaps how) it is possible for a procedure
to determine which item called it? I am trying to write a procedure that is
called by 7 different TEdit objects but within my procedure I need to know
the contents of Edit.Text.  Perhaps the following example will clarify
things a bit:

procedure EditExit(Sender: TObject);

begin
 if not DirExists(Sender.Text) then ShowMessage('Directory does not
exist!!');
end;

The only problem is that TEdit is derived from TObject and therefore this
construction is not possible .. can anybody help??

thanks .. melle
siesw...@knmg.nl

 

Re:Procedure EditExit(Sender : TObject);


melle schrieb in Nachricht <77podi$74...@news.worldonline.nl>...
Quote
>Hi,

>Can anyone tell me wheter (and perhaps how) it is possible for a procedure
>to determine which item called it? I am trying to write a procedure that is
>called by 7 different TEdit objects but within my procedure I need to know
>the contents of Edit.Text.  Perhaps the following example will clarify
>things a bit:

>procedure EditExit(Sender: TObject);

>begin
> if not DirExists(Sender.Text) then ShowMessage('Directory does not
>exist!!');
>end;

>The only problem is that TEdit is derived from TObject and therefore this
>construction is not possible .. can anybody help??

>thanks .. melle
>siesw...@knmg.nl

It's very simple.
The Sender parameter is the object that called the procedure.
You can retrieve the component's name by using "TComponent(Sender).Name".
And you can validate what type the component is of by using something like
"if (Sender is TEdit)..."
And in the object explorer you can assign the OnExit event of the single
TEdits to one procedure.

So, it is possible to react in only one procedure on the exits of more than
one TEdit.
For example:

procedure TForm1.EditExit(Sender: TObject);
begin
    {Maybe all of your directory edit fields are called something like
    ...Dir...}
    if pos('Dir',TComponent(Sender).Name)<>0 then begin
         if not DirExists(TEdit(Sender).Text) then
            ShowMessage('Directory does not exist!!');
    end;
    {... and some TEdits for file names are called something like
    ...File...}
    if pos('File',TComponent(Sender).Name)<>0 then begin
        if not FileExists(TEdit(Sender).Text) then ShowMessage('File does
not exist!!!');
    end;
end;

I hope this is what you wanted to know.
Hth,
Matthias.

Other Threads