[Lazarus] TBitBtn with Kid=bkClose and ModalResult
Bart
bartjunk64 at gmail.com
Sat Apr 21 00:23:41 CEST 2012
A TBitBtn with Kind = bkClose will not set ModalResult of the ParentForm.
As a result ShowModal on a form with such a TBitBtn will return
mrCancel if this button is clicked, and not mrClose.
This is the piece of code that is responsable for this behaviour:
in lcl/include/bitbtn.inc
procedure TCustomBitBtn.Click;
var
Form : TCustomForm;
begin
if FKind = bkClose then begin
Form := GetParentForm(Self);
if Form <> nil then begin
Form.Close;
exit;
end;
end;
inherited Click;
end;
inherited click calls (in lcl/include/buttons.inc)
procedure TCustomButton.Click;
var
Form : TCustomForm;
Begin
if ModalResult <> mrNone
then begin
Form := GetParentForm(Self);
if Form <> nil then Form.ModalResult := ModalResult;
end;
inherited Click;
end;
So if Kind <> bkClose then ModalResult of parentform is set, otherwise not.
In TCustomForm.ShowModal, when ModalResult = 0 it will the set
ModalResult to mrCancel.
Q: Is this by design?
Currently it makes MessageDlg() (more specific:
TPromptDialog.CreateMessageDialog) return wrong result if mbClose is
in Buttons (and mbClose is clciked): see
http://bugs.freepascal.org/view.php?id=21801
Bart
More information about the Lazarus
mailing list