The following example demonstrates emulation of an overwrite capability of a TMemo component. The state of the overwrite mode can be toggled by pressing the insert key.
Example:
~~~~~~~~~~~~~~~~~~~~~~~~~
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure Memo1KeyDown
(Sender: TObject; var Key: Word;
Shift: TShiftState) ;
procedure Memo1KeyPress
(Sender: TObject; var Key: Char) ;
private
{ Private declarations }
InsertOn : bool;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Memo1KeyDown
(Sender: TObject; var Key: Word; Shift: TShiftState) ;
begin
if (Key = VK_INSERT) and
(Shift = []) then
InsertOn := not InsertOn;
end;
procedure TForm1.Memo1KeyPress
(Sender: TObject; var Key: Char) ;
begin
if ((Memo1.SelLength = 0) and
(not InsertOn)) then
Memo1.SelLength := 1;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
Sometimes we need to clear all the Edit components that are on the form. The task is easy with the following procedure:
~~~~~~~~~~~~~~~~~~~~~~~~~
procedure ClearEdits;
var j : Integer;
begin
for j := 0 to ComponentCount-1 do
if (Components[j] is TEdit) then
(Components[j] as TEdit).Text := '';
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
Delphi tips navigator:
» Make an application window full screen
« Detecting and preventing Windows shut down

