Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
unit StringGridPlus;
interface
uses
SysUtils, Classes, Grids, Messages, Windows;
type
TOnCellEditEvent = procedure(Sender: TObject; ACol, ARow: Integer; var Value: String) of object;
TStringGridPlus = class;
TGridPlusInplaceEdit = class(TInplaceEdit)
private
FGrid: TStringGridPlus;
InEditor: Boolean;
protected
procedure WndProc(var Message: TMessage); override;
public
constructor Create(Owner: TComponent); override;
property Grid: TStringGridPlus read FGrid;
end;
TStringGridPlus = class(TStringGrid)
private
FOnStartEdit: TOnCellEditEvent;
FOnStopEdit: TOnCellEditEvent;
protected
function CreateEditor: TInplaceEdit; override;
public
constructor Create(Owner: TComponent); override;
published
property OnStartEdit: TOnCellEditEvent read FOnStartEdit write FOnStartEdit;
property OnStopEdit: TOnCellEditEvent read FOnStopEdit write FOnStopEdit;
end;
procedure Register;
implementation
uses Mask;
procedure Register;
begin
RegisterComponents('AaroLib', [TStringGridPlus]);
end;
{ TStringGridPlus }
constructor TStringGridPlus.Create(Owner: TComponent);
begin
inherited;
DefaultRowHeight := 17;
end;
function TStringGridPlus.CreateEditor: TInplaceEdit;
begin
Result := TGridPlusInplaceEdit.Create(Self);
end;
{ TGridPlusInplaceEdit }
constructor TGridPlusInplaceEdit.Create(Owner: TComponent);
begin
inherited;
InEditor := false;
FGrid := TStringGridPlus(Owner);
end;
procedure TGridPlusInplaceEdit.WndProc(var Message: TMessage);
var
G: TStringGridPlus;
tempStr: String;
begin
if InEditor then
begin
Inherited;
Exit;
end;
case Message.Msg of
WM_SETFOCUS:
begin
InEditor := true;
try
tempStr := Text;
if Assigned(FGrid.FOnStartEdit) then
FGrid.FOnStartEdit(FGrid, G.Col, G.Row, tempStr);
finally
Text := tempStr;
Grid.HideEditor;
InEditor := false;
end;
end;
WM_KILLFOCUS:
begin
tempStr := Text;
if Assigned(FGrid.FOnStopEdit) then
begin
FGrid.FOnStopEdit(FGrid, G.Col, G.Row, tempStr);
Text := tempStr;
end;
end;
end;
inherited;
end;
end.
unit StringGridPlus;
interface
uses
SysUtils, Classes, Grids, Messages, Windows;
type
TOnCellStartEditEvent = procedure(Sender: TObject; ACol, ARow: Integer; var Value: String; var AutoClose: Boolean) of object;
TOnCellStopEditEvent = procedure(Sender: TObject; ACol, ARow: Integer) of object;
TStringGridPlus = class;
TGridPlusInplaceEdit = class(TInplaceEdit)
private
FGrid: TStringGridPlus;
InEditor: Boolean;
UndoText: String;
protected
procedure WndProc(var Message: TMessage); override;
procedure KeyPress(var Key: Char); override;
public
constructor Create(Owner: TComponent); override;
property Grid: TStringGridPlus read FGrid;
end;
TStringGridPlus = class(TStringGrid)
private
FOnStartEdit: TOnCellStartEditEvent;
FOnStopEdit: TOnCellStopEditEvent;
protected
function CreateEditor: TInplaceEdit; override;
public
constructor Create(Owner: TComponent); override;
published
property OnStartEdit: TOnCellStartEditEvent read FOnStartEdit write FOnStartEdit;
property OnStopEdit: TOnCellStopEditEvent read FOnStopEdit write FOnStopEdit;
end;
procedure Register;
implementation
uses Mask;
procedure Register;
begin
RegisterComponents('Nordlund', [TStringGridPlus]);
end;
{ TStringGridPlus }
constructor TStringGridPlus.Create(Owner: TComponent);
begin
inherited;
DefaultRowHeight := 17;
end;
function TStringGridPlus.CreateEditor: TInplaceEdit;
begin
Result := TGridPlusInplaceEdit.Create(Self);
end;
{ TGridPlusInplaceEdit }
constructor TGridPlusInplaceEdit.Create(Owner: TComponent);
begin
inherited;
InEditor := false;
FGrid := TStringGridPlus(Owner);
end;
procedure TGridPlusInplaceEdit.KeyPress(var Key: Char);
begin
try
if Key = #27 then
begin
FGrid.HideEditor;
FGrid.Cells[FGrid.Col, FGrid.Row] := UndoText;
Text := UndoText;
Key := #0;
end;
finally
inherited KeyPress(Key);
end;
end;
procedure TGridPlusInplaceEdit.WndProc(var Message: TMessage);
var
G: TStringGridPlus;
tempStr: String;
AutoClose: Boolean;
begin
if InEditor then
begin
Inherited;
Exit;
end;
case Message.Msg of
WM_SETFOCUS:
begin
InEditor := true;
try
UndoText := FGrid.Cells[FGrid.Col, FGrid.Row];
tempStr := Text;
if Assigned(FGrid.FOnStartEdit) then
begin
FGrid.FOnStartEdit(FGrid, FGrid.Col, FGrid.Row, tempStr, AutoClose);
Text := tempStr;
InEditor := false;
if AutoClose then
Grid.HideEditor;
end;
finally
InEditor := false;
end;
end;
WM_KILLFOCUS:
begin
if Assigned(FGrid.FOnStopEdit) then
begin
FGrid.FOnStopEdit(FGrid, FGrid.Col, FGrid.Row);
end;
end;
end;
inherited;
end;
end.
procedure TMainForm.menulistStartEdit(Sender: TObject; ACol,
ARow: Integer; var Value: String; var AutoClose: Boolean);
begin
if acol = 2 then
Value := Inputbox('Edit entry', MenuList.Cells[1,0]+ ': '+ MenuList.Cells[1,arow] ,Value);
end;