Ich wüde es z.B. so machen:
Delphi-Quellcode:
unit Unit3;
interface
uses Classes, Messages, Grids;
type
TMyStringGrid =
class(TStringGrid)
private
FOnKillFocus: TNotifyEvent;
FOnSetFocus: TNotifyEvent;
procedure WMKillFocus(
var Msg: TWMKillFocus);
message WM_KILLFOCUS;
procedure WMSetFocus(
var Msg: TWMSetFocus);
message WM_SETFOCUS;
published
property OnKillFocus: TNotifyEvent
read FOnKillFocus
write FOnKillFocus;
property OnSetFocus: TNotifyEvent
read FOnSetFocus
write FOnSetFocus;
end;
implementation
procedure TMyStringGrid.WMKillFocus(
var Msg: TWMKillFocus);
begin
inherited;
if Assigned(FOnKillFocus)
then
FOnKillFocus(Self);
end;
procedure TMyStringGrid.WMSetFocus(
var Msg: TWMSetFocus);
begin
inherited;
if Assigned(FOnSetFocus)
then
FOnSetFocus(Self);
end;
end.
Grid erzeugen:
Delphi-Quellcode:
constructor TForm2.Create(AOwner: TComponent);
begin
inherited;
StringGrid := TMyStringGrid.Create(Self);
with StringGrid do
begin
Parent := Self;
Align := alTop;
// zum Test am unteren Fensterrand ein Edit
Visible := True;
OnSetFocus := doSetFocus;
OnKillFocus := doKillFocus;
end;
end;
procedure TForm2.doSetFocus(Sender: TObject);
begin
// kein Dialog, sonst bekommst du endlose modale Messageboxen
// lieber eine Statusbar zum Testen
sBar.SimpleText := 'Focus gesetzt...';
end;
procedure TForm2.doKillFocus(Sender: TObject);
begin
sBar.SimpleText := 'Focus gekillt...';
end;
Gruß, Frank