Tuesday, February 14, 2006

Changing a TEdit text in its OnChange event


    If you want to change a TEdit text in its OnChange event, it will fire
    the event recursively until stack exhausts. To do this, you must set it
    to NIL before changing its text and reassigning it after, like this:






      procedure Edit1Change(Sender : TObject);

      begin

        Edit1.OnChange := NIL;

        if Edit1.Text = 'Some Text' then

          Edit1.Text := 'New Text';

        Edit1.OnChange := Edit1Change;

      end;




    This tip works also with OnValidate events.


0 Comments:

Post a Comment

<< Home