-1

I have a frame that is being placed on a form. I expect to be placing a number of instances of this frame on the form.

It has a drawgrid with 2 columns and in the OnResize event I make the 2nd column extend to the end of the available space. That works when the form is manually resized with the frame Align set to alTop. But when the form first appears even though FrameResize gets called it has no effect. (Though it did have the desired effect when I put a break point on it).

So, what I am doing now is calling the FrameResize from the forms OnShow handler, but that is ugly. The frame should be able to appear correctly formed without help from the Form.

Any ideas? I did try overriding SetParent, but that didn't work. Using Xe2.

TIA Mark

Bruce McGee
  • 15,076
  • 6
  • 55
  • 70
Mark Patterson
  • 417
  • 2
  • 6
  • 15
  • 1
    It does work perfectly well for me. I placed one Frame with align=alNone and one with alRight on my form. The form first gets a `WM_SIZE` message that causes the `onResize` event on each TFrame. Their `TDrawGrids` then get adjusted. Everything is fine. Can you post your `onResize` Event handler code? – Günther the Beautiful Dec 11 '13 at 11:44
  • 1
    I created an empty frame and an empty form, and added an instance of the frame to the form. I implemented an `OnResize` event for the frame that calls `Beep`. When I run the app, it beeps on startup. I think we need an SSCCE. – David Heffernan Dec 11 '13 at 11:46
  • Thanks for your efforts guys, and teaching me the SSCCE acronym. Could it be a version-specific bug? I am using XE2. Since I have solved it, I need to get on to other things. – Mark Patterson Dec 12 '13 at 02:05
  • Mark: This works as expected in XE2. – Bruce McGee Dec 15 '13 at 03:16
  • Bruce: I have an OnResize event set in a tframe. It gets called when I manually resize the form it is on and has the desired effect. In the Frame's constructor the Align properties don't seem to have had their effect yet, and my resizing was relying on that. So even calling FormResize in the contructor was not getting it right. But overriding SetBounds does the trick. – Mark Patterson Dec 16 '13 at 05:08

1 Answers1

1

I have solved it with advice from Peter Below, Delphi Team B Delphi member.

I overrode the frame's set bounds. It was getting called even before the component variables were set, so it looks like this

procedure TfaDupDisplay.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);  // Had to use SetBounds because OnRezise was not working
var grid: TDrawGrid;
begin
  inherited;
  if pnlWebData = nil then
    exit;
  pnlWebData.Width := Width div 2;
  for grid in TArray<TDrawGrid>.Create(grdData, grdDup) do
    grid.ColWidths[1] := grid.Width - grdData.ColWidths[0];
end{ SetBounds};
Mark Patterson
  • 417
  • 2
  • 6
  • 15