[Lazarus] TBitBtn with Kid=bkClose and ModalResult

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sat Apr 21 11:10:19 CEST 2012


Bart schrieb:
> 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.

Only few button kinds have a defined ModalResult. It seems to be up to 
the developer to select the proper Kind, depending on the use in a modal 
or non-modal form.

> 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;

I'd suggest that an explicitly set ModalResult should be checked, before 
actions are invoked that are incompatible with modal forms. But Delphi 
also checks Kind *before* ModalResult, so this is a compatibility issue.

DoDi





More information about the Lazarus mailing list