2009. július 10., péntek

Delete a line in a TMemo in its OnChange event

Problem/Question/Abstract:

I want to use a TMemo as a FIFO, and every time a new string is written to the memo, the OnChange event will be triggered. In the OnChange event I will do my work on the string and as the last thing make a memo.delete(0) so that the next string in the memo will move to line 0. My question is now, is this a right thing to do? I suppose that it will make a recursive call to the OnChange event and that I in this way have a "system" that will empty my memo as fast as possible.

Answer:

The trick is to save, wipe, and restore the event value:

procedure TForm1.Memo1Change(Sender: TObject);
var
Save: TNotifyEvent;
begin
Save := Memo1.OnChange; {Save}
Memo1.OnChange := nil; {Erase}
Memo1.Lines.Delete(0);
Memo1.OnChange := Save; {Restore}
end;


Nincsenek megjegyzések:

Megjegyzés küldése