[Lazarus] Suppressing OnChange

Antonio Fortuny a.fortuny at sitasoftware.lu
Thu Nov 8 17:06:45 CET 2012



Le 08/11/2012 16:28, Timothy Groves a écrit :
> I have a program which allows you to edit records.  This is done using a
> dynamic array of records, with three strings in each record.  I have
> been using TEdits to allow the user to edit the records.  The record is
> updated during TEdit.OnChange.
>
> Unfortunately, whenever I push the data *from* a selected record *to*
> the form, TEdit.OnChange triggers, which tends to corrupt my data.  I
> tried disabling the TEdit, using TEdit.Enabled := false, but the event
> still triggers.
>
> Any suggestions?
Yep.
On all "controlled" TEdit components setup a OnEnter, OnChange and 
OnExit event
Remove the OnChange event from the component events list but leave the 
code in the unit anyway. Then fill in the following: (assume TMyEdit is 
one of the components)

TMyForm.MyEditOnEnter(Sender: TObject);
begin
   MyDedit.OnChange := @MyEditChange;
end;

TMyForm.MyEditOnChange(Sender: TObject);
begin
   do whatever you need to when Edit changes
end;

TMyForm.MyEditOnExit(Sender: TObject);
begin
   MyDedit.OnChange := nil
end;

When you fill in data from the program code the events are not fired. 
But they are when the use enters someting in them.

>
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>






More information about the Lazarus mailing list