Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-11

Suppressing OnChange

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Timothy Groves

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?

Reply by email

Antonio Fortuny
to Timothy Groves

Le 08/11/2012 16:28, Timothy Groves a ?crit :

Show quoted text 11 lines
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.

Show quoted text 9 lines
-- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

bsquared
to Timothy Groves: I have a program which allows you to edit records. This is done using a dynamic array of…
Timothy Groves wrote 20 lines
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? -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
You can temporarily un-assign the event handler.
{ remove event handler from all edits }
with MyForm do
   for (i := 0 to Pred(Form.ComponentCount)) do
     if (Components[i] is TEdit) then
     begin
       theEdit := TEdit(Components[i])
       theEdit.OnChange := nil;
     end;
PushMyData();
{ re-assign the event handler to all edit }
with MyForm do
   for (i := 0 to Pred(ComponentCount)) do
     if (Components[i] is TEdit) then
     begin
       theEdit := TEdit(Components[i])
       theEdit.OnChange := @OnChange;
     end;

I apologize if this double posts. I had some problem with the first attempt.

Regards, Brian

Reply by email

Timothy Groves
to bsquared

Thanks to both responders. I actually found another solution:

procedure TfrmMain.txtVolAuthorChange(Sender: TObject);
begin
   if (txtVolAuthor.Enabled) then
     VolumeList [CurrentVolume].Author := txtVolAuthor.Text;
end;
Then I just set txtVolAuthor.Enabled := false before manually updating it.

Reply by email