unit Unit2;
interface
uses Classes, Windows, Grids;
type
TMyStringGrid =
class;
TMyStringGridExitEdit =
procedure(Sender: TMyStringGrid; Value:
string)
of object;
TMyInplaceEdit =
class(TInplaceEdit)
private
FOnHide : TNotifyEvent;
public
constructor Create(AOwner: TComponent);
override;
procedure Hide;
published
property OnHide: TNotifyEvent
read FOnHide
write FOnHide
default nil;
end;
TMyStringGrid =
class(TStringGrid)
private
FMyInplaceEdit: TMyInplaceEdit;
FOnExitEdit: TMyStringGridExitEdit;
procedure OnInplaceEditorHide(Sender: TObject);
protected
function CreateEditor: TInplaceEdit;
override;
public
constructor Create(AOwner: TComponent);
published
property OnExitEdit: TMyStringGridExitEdit
read FOnExitEdit
write FOnExitEdit;
end;
implementation
{ TMRStringGrid }
constructor TMyStringGrid.Create(AOwner: TComponent);
begin
inherited;
FOnExitEdit :=
nil;
end;
function TMyStringGrid.CreateEditor: TInplaceEdit;
begin
FMyInplaceEdit := TMyInplaceEdit.Create(Self);
FMyInplaceEdit.OnHide := OnInplaceEditorHide;
Result := FMyInplaceEdit;
end;
procedure TMyStringGrid.OnInplaceEditorHide(Sender: TObject);
var
s:
string;
begin
s := FMyInplaceEdit.Text;
if (Assigned(FOnExitEdit))
then
FOnExitEdit(Self, s);
end;
{ TMRInplaceEdit }
constructor TMyInplaceEdit.Create(AOwner: TComponent);
begin
inherited;
FOnHide :=
nil;
end;
procedure TMyInplaceEdit.Hide;
begin
if HandleAllocated
and IsWindowVisible(
Handle)
then
begin
Invalidate;
SetWindowPos(
Handle, 0, 0, 0, 0, 0, SWP_HIDEWINDOW
or SWP_NOZORDER
or
SWP_NOREDRAW);
if Focused
then Windows.SetFocus(Grid.Handle);
end;
if (Assigned(FOnHide))
then
FOnHide(Self);
end;
end.