Recent

Author Topic: How single procedure ends in different results  (Read 1140 times)

Marion

  • Full Member
  • ***
  • Posts: 125
How single procedure ends in different results
« on: November 28, 2024, 12:42:47 am »
I have a procedure that dynamically adds controls to a TScrollBox with the ChildSizing.ControlsPerLine = 1 so the controls stack from top to bottom. When the ScrollBox starts empty then the child controls are the correct height (See image with empty TEdit). Once a user enters text and saves the dialog, the next time they come back to the form, I repopulate the rows and add the text but now the TEdits are short. When I add a new (empty) row, all of the rows (including the previous ones) stretch to the right height. I'd like to fix this if someone knows what's going on.

Below is the procedure used to add all of the rows to the ScrollBox:
Code: Pascal  [Select][+][-]
  1. function TfrmOptions.DiceTrayRowAdd: TPanel;
  2. var
  3.   pnlRow: TPanel;
  4.   txtName, txtFormula: TEdit;
  5. begin
  6.  
  7.   pnlRow := TPanel.Create(boxDiceTray);
  8.   pnlRow.Parent := boxDiceTray;
  9.   pnlRow.Tag := FDiceRow;
  10.   pnlRow.BevelOuter := bvNone;
  11.   pnlRow.ChildSizing.ControlsPerLine := 2;
  12.   pnlRow.ChildSizing.EnlargeHorizontal := crsHomogenousChildResize;
  13.   pnlRow.ChildSizing.Layout := cclLeftToRightThenTopToBottom;
  14.   //pnlRow.Name := Format('pnlDiceRow%d', [FDiceRow]);
  15.   pnlrow.Caption := '';
  16.   pnlRow.OnEnter := @DiceTrayRowEnter;
  17.  
  18.   txtName := TEdit.Create(pnlRow);
  19.   txtName.Parent := pnlRow;
  20.   //txtName.Name := Format('txtDTName%d', [FDiceRow]);
  21.   txtName.Text := '';
  22.   txtName.MaxLength := 20;
  23.   txtName.OnKeyUp := @DiceTrayRowKeyUp;
  24.  
  25.   txtFormula := TEdit.Create(pnlRow);
  26.   txtFormula.Parent := pnlRow;
  27.   //txtFormula.Name := Format('txtDTFormula%d', [FDiceRow]);
  28.   txtFormula.Text := '';
  29.   txtFormula.MaxLength := 40;
  30.   txtFormula.OnKeyUp := @DiceTrayRowKeyUp;
  31.  
  32.   if txtName.CanFocus then txtName.SetFocus;
  33.   FDiceRow := FDiceRow+1;
  34.   result := pnlRow;
  35. end;
  36.  
Thank you,
Marion
(A recovering Windows programmer.)

CharlyTango

  • Jr. Member
  • **
  • Posts: 91
Re: How single procedure ends in different results
« Reply #1 on: November 28, 2024, 09:39:15 am »
You will certainly have a reason why you choose a solution with a TScrollbos, which is significantly more complex and problematic than other controls.

I would try to solve such “simple” inputs with a TStringgrid, for example
Lazarus stable, Win32/64

jamie

  • Hero Member
  • *****
  • Posts: 6791
Re: How single procedure ends in different results
« Reply #2 on: November 28, 2024, 05:32:17 pm »
AutoSize is set to true maybe?

in any case, I am not sure how the child sizing works but best guess is it may use the FONT height. Maybe you need to set that in the EDIT fields.

The only true wisdom is knowing you know nothing

Marion

  • Full Member
  • ***
  • Posts: 125
Re: How single procedure ends in different results
« Reply #3 on: December 03, 2024, 01:57:43 am »
I finally fixed it. I had to add a Contraints.MinHeight = 40 to each of the TEdits and now it works as expected.
« Last Edit: December 03, 2024, 02:00:03 am by Marion »
Thank you,
Marion
(A recovering Windows programmer.)

 

TinyPortal © 2005-2018