呼び出しでfunction TWinControl.DoKeyDown(var Message: TWMKey): Boolean;
は、存在する場合は親に委任されます。
手順
procedure TWinControl.KeyDown(var Key: Word; Shift: TShiftState);
begin
if Assigned(FOnKeyDown) then FOnKeyDown(Self, Key, Shift);
end;
フォームがペアレント化されている場合は呼び出されません
function TWinControl.DoKeyDown(var Message: TWMKey): Boolean;
var
ShiftState: TShiftState;
Form, FormParent: TCustomForm;
LCharCode: Word;
begin
Result := True;
{ First give the immediate parent form a try at the Message }
Form := GetParentForm(Self, False);
if (Form <> nil) and (Form <> Self) then
begin
// >> -- the DoKeyDown of the parent (not of your form) will be called
if Form.KeyPreview and TWinControl(Form).DoKeyDown(Message) then
Exit;
{ If that didn't work, see if that Form has a parent (ie: it is docked) }
if Form.Parent <> nil then
begin
FormParent := GetParentForm(Form);
if (FormParent <> nil) and (FormParent <> Form) and FormParent.KeyPreview and
TWinControl(FormParent).DoKeyDown(Message) then
Exit;
end;
end;
......