Link to home
Start Free TrialLog in
Avatar of abulka
abulka

asked on

restore inherited form's original bounds

When I create a bunch of forms based on a base form held in the repository, they all start out being the same size as the base form - until I resize the instance form.  Then the instance form has it's own bounds viz. top, left, etc. properties.

How do I tell the form to revert to using the inherited base form size?  

Similarly with components on the base form - if I move them on the instance form they forever are independent of the base form component position.  How do I tell these components to revert to the base form component's position (this applies to all the other properties, beside top,left,width etc. )
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abulka
abulka

ASKER

You are right about 'revert to inherited' for components.  However,
The menu item is always dimmed out for forms.  How do I get the form to revert?  This is the main thing I want to get working.
-A

OK - here we have to get crafty!

When viewing the form itself, press Alt-F12. This converts the form to text. Near the top you will see lines that say
left = x
top = y
width = z

etc.

To make the inherited form revert to the properties of the ancestor form delete the properties you want to be the same eg: deleting the top, left, width and height lines will make the inherited form take the size and position of the ancestor form.

once you have deleted these press alt-F12 again to convert the text back into a form.

Cheers,

Raymond.

Avatar of abulka

ASKER

Ok that sounds good.  I'll accept the answer.

If you give me some code to get the inherited form to revert to the ancestor form's size and position prior to displaying at runtime, this will give me a RUNTIME solution (as well as the design time solution that you gave me).

I've increased the points a little.
Hmm...

This may not be the best way to do this, but you could just implement it in a TForm derived class and derive all your ancestor forms from that (either that or do it in each form - but thats yucky):

TMyForm = class(TForm)
  private
    TheTop, TheLeft, TheHeight, TheWidth : Integer;
  protected //? could be public...
    procedure Loaded; override;
end;

procedure TMyForm.Loaded;

begin
  if csInherited in ComponentState then
    begin
      TheTop := Top;
      TheLeft := Left;
      TheHeight := Height;
      TheWidth := Width;
    end
  else
    SetBounds(TheLeft, TheTop, TheWidth, TheHeight);
end;

Cheers,

Raymond.

Avatar of abulka

ASKER

Looks good - just one last question.

Wouldn't I have to call
  inherited
in the TMyForm.Loaded;    of the ancestor/base form?
or is the loaded message just for notification and I don't have to pass it up?

e.g.

procedure TMyForm.Loaded;
     inherited; // parameters here???      
      begin
        if csInherited in ComponentState then
          begin
     etc...
     ...
       
Yes. I forgot to include that.

Cheers,

Raymond.
Avatar of abulka

ASKER

Ok.  Does the inherited call need parameters?  e.g. sender or something?
No - it shoudln't. It should compile just fine as it is. If not change it to:

Inherited Loaded;

Cheers,

Raymond.