0

I already found much help for writing a components which allows Hiding of components here ( THIDEPANEL. Now I suffer a first issues:

During the OnCreate event of this class I take the Panel width and height, I want to restore to the original values while hidden / unhiding the panel. Actually the hide process always decrease the size of the panel

constructor THidePanel.Create(AOwner: TComponent);
begin
  inherited;

  // The inner panel
  WorkingPanel := TPanel.Create(Self);
  WorkingPanel.Caption := '***';

  // The hide unhide
  FActivateButton := TButton.Create(Self);
  FActivateButton.Parent := self;
  FActivateButton.Caption := '<';
  FActivateButton.OnClick := H_ActivateButtonClick;
  FActivateButton.Width := BoarderSize;
  FActivateButton.Height := BoarderSize;
  WorkingPanel.Caption := '';

  // Grab the size of the hide panel, later restore to this values
  FLargeWidth := Self.Width;
  FLargeHeight := Self.Height;

  SetButtonPosition(TopRight);
end;
Community
  • 1
  • 1
Franz
  • 1,883
  • 26
  • 47
  • There are two questions now. If I can only answer one, what am I supposed to do? That's why we always prefer to have one question at a time. What's more, questions should stand alone. Do I need to look at your other questions to answer these? If so then that puts me off doing it and makes it a worse question. – David Heffernan Apr 09 '13 at 14:31
  • 1 remove the second question now; lets go for part #1 – Franz Apr 09 '13 at 14:43
  • why is the panel size getting smaller after first mimimize & restore button click – Franz Apr 09 '13 at 14:43
  • 1
    You're essentially asking other people to debug your code for you. That's not what Stack Overflow is for. Please debug your own code. The best questions are those that can be phrased to begin "How do I..." This question, on the other hand, is "What's wrong with *my* code, which is too localized. – Rob Kennedy Apr 09 '13 at 15:40

1 Answers1

2

It is because the FLargeWidth private field has an invalid value. You assign it with Self.Width during the constructor (and you presumably never update it). That is not the width you set at design time or at run time, but it is the hard coded width from TCustomPanel.Create, which is 185. Note that when a control's constructor is run, the control is not placed yet.

If you want to remember the set width, then you should "override TControl.SetWidth". But since that method is private (not virtual), you need to override either SetBounds or Resize in order to response to Width's change. I would choose the latter, probably with an additional condition:

procedure THidePanel.Resize;
begin
  if not HasCustomWidth then  //< Replace this with your own logic condition
    FLargeWidth := Width;
  inherited Resize;
end;
NGLN
  • 43,011
  • 8
  • 105
  • 200
  • +1 @Franz You can work these things out yourself. You just need to use the debugger. Why is the width small? Where is it being set? Where does that value come from? And so on. All these questions readily answered using debugger. – David Heffernan Apr 09 '13 at 23:15
  • did not Know that the Tpanel component size is filled up with default values during the create event, can do the rest now by myself, thanks fpr the help – Franz Apr 10 '13 at 09:17