Does anybody know the trick, how to free control inside its event handler ? According delphi help it is not possible…
I want to free dynamicaly created TEdit, when Self.Text=”.
TAmountEdit = class (TEdit)
.
.
public
procedure KeyUp(var Key: Word; Shift :TShiftState);
end;
procedure TAmountEdit.KeyUp(var Key: Word; Shift :TShiftState);
begin
inherited;
if Text='' then Free; // after calling free, an exception arises
end;
How should do to achieve the same effect?
Thanx
The solution is to post a queued message to the control, which it responds to by destroying itself. Ny convention we use
CM_RELEASEwhich is the private message used byTFormin its implementation of theReleasemethod that performs an analogous task.The control is destroyed when the application next pumps its message queue.