Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a form is modal before it's drawn?

Tags:

forms

delphi

Some of my forms can be shown both as normal and modal forms. In case they're showing as modal forms, I have to hide some components which are not usefull in modal state.

if(fsModal in Self.FormState) then
begin 
  //hiding some components...
end;

I would like to execute my code before the form is drawn, in order to avoid it's drawn more times unnecessarily.

like image 696
Fabrizio Avatar asked Oct 20 '25 14:10

Fabrizio


1 Answers

I thought that OnShow executed before the form is visible, but it seems that is not so. So you can do this:

TMyForm = class( TForm )  // this will already be in your source
public
  function ShowModal: Integer; override;
end;

function TMyForm.ShowModal: Integer;
begin
  // hide some components
  Result := inherited;
  // show them again in case next time it is a Show
end;

You can't override Show in the same way - you would have to override the visible property, so easier to reset the visibility of the components as shown.

like image 136
Dsm Avatar answered Oct 22 '25 04:10

Dsm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!