List Info

Thread: Dynamically codified a TNotifyEvent




Dynamically codified a TNotifyEvent
user name
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 <lamyebellsouth.net> wrote:
&nbsp; 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
&nbsp;  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



&nbsp; SPONSORED LINKS
 &nbsp; &nbsp;   ; C programming language&nbsp;  Computer programming languages&nbsp;  Java programming language&nbsp; &nbsp;  The c programming language&nbsp;  C programming language&nbsp;  Concept of programming language
 &nbsp; 
---------------------------------
  YAHOO! GROUPS LINKS

   ;
 &nbsp;  Visit your group "delphi-en" on the web.
&nbsp; &nbsp;
 &nbsp;  To unsubscribe from this group, send an email to:
delphi-en-unsubscribe@yahoogroups.com
&nbsp; &nbsp;
 &nbsp;  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

   ;
---------------------------------
 



&nbsp; &nbsp;    &nbsp; &nbsp; 
---------------------------------
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.&nbsp; Great rates starting at 1&cent;/min.

[Non-text portions of this message have been removed]

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )