|
List Info
Thread: Dynamically codified a TNotifyEvent
|
|
| Dynamically codified a TNotifyEvent |

|
2006-04-02 19:02:27 |
|
Well you picked a lousy example since SelectAll is a property of the edit control! Just set the property for that behavior. But to answer your question:
Create your OnEnter event for an editbox the usual way and code your event. Let's say it's named
Edit1Enter(Sender: TObject)
In the Object Inspector, copy the text in the OnEnter event and cut and paste it into the OnEnter event for all the other edit controls. In otherwords, have all the Edit controls point to the same event for their code. You can rename it to something more generic like EditboxEnter (remember to rename the declaration as well) for better "self documentation".
tip: This is where the Sender variable becomes useful since Sender points to the exact instance of edit box executing the code. You can use it to be specific about what code executes for each control but still have the editEnter code centrallized.
example:
EditboxEnter(Sender: TObject);
begin
If Sender = Edit1 Then
begin
// do something specific for that control
end
else
begin
// do something more generic for the rest of the edit controls
end;
Dave
What could be simpler? This is why Delphi blows everything else away.
Emmanuel Lamy <lamye bellsouth.net> wrote:
Hello Everybody,
I am trying to dynamically attach a routine to a group of controls.
Let's say I have a multitude of Edit boxes on a form and I want
to "SelectAll" the content of each edit box "OnEnter", if the edit
box is not empty. I tried this:
...
for i:=0 to pred(ComponentCount) do
if Components[i] is TEdit then
(Components[i] as TEdit).OnEnter:=SelectAll((Components[i] as
TEdit));
...
procedure Tform1.SelectAll(aField: TEdit);
begin
if aField.Text <> '' then
aField.SelectAll;
end;
This approach generates an error when I compile the codes. I remain
convinced that there is an easier way other than coding the OnEnter
event of each individual Edit box. Can somebody, please, help? TIA.
Emmanuel
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: delphi-en-unsubscribe@yahoogroups.com
SPONSORED LINKS
C programming language Computer programming languages Java programming language The c programming language C programming language Concept of programming language
---------------------------------
YAHOO! GROUPS LINKS
Visit your group "delphi-en" on the web.
To unsubscribe from this group, send an email to:
delphi-en-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
---------------------------------
---------------------------------
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1¢/min.
[Non-text portions of this message have been removed]
|
[1]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|