This site is temporarily down. Please come back. Change text in a OnChange event without stack overflow
DelphiFAQ Home Search:

Change text in a OnChange event without stack overflow

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

If you change a TEdit text in its OnChange event, e.g. to do some adjustments, it will fire the event recursively until stack exhausts.
You can temporarily disable the event handler just by setting the internal method pointer to nil. Don't forget to set it back to the right procedure - this sample shows how to do it:

procedure Form1.Edit1Change(Sender : TObject); 
begin
  { temporarily disable the event handler }
  Edit1.OnChange := NIL; 
  if Edit1.Text = 'Some Text' then 
    Edit1.Text := 'New Text'; 
  { enable the event handler again }
  Edit1.OnChange := Edit1Change; 
end;

Content-type: text/html

Comments:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: