Recent

Author Topic: InputCombo : Minor bug.  (Read 3512 times)

magu

  • New Member
  • *
  • Posts: 36
InputCombo : Minor bug.
« on: October 01, 2021, 11:51:26 pm »
InputCombo is a popup dialog much like InputBox only the user is to choose from prestated options.

However the LCL version has a minor bug because it has no minimum width, eg:

Code: Pascal  [Select][+][-]
  1. InputCombo('Try', 'this is messy', ['opt 1', 'opt 2', 'opt 3']);

Will not show the selection buttons (Ok and Cancel) properly because this dialog sets its width according to the options with no minimum.
To work properly it needs to have a minimum width, I have fixed this by inserting the following line in the calling function (DoInputcombo in the unit inputdialog.inc)

Code: Pascal  [Select][+][-]
  1. if W < frm.Scale96ToForm(200) then W := frm.Scale96ToForm(200);

Also I would suggest removing the bevel from the ButtonPanel to keep uniformity with InputBox.

ps. Don't really know how to suggest bug reports / fixes so maybe someone can handle it please
pps. also this gives some visibility to the function, didn't know it existed because it's not documented with the other Input dialog options.

wp

  • Hero Member
  • *****
  • Posts: 12593
Re: InputCombo : Minor bug.
« Reply #1 on: October 02, 2021, 12:12:13 am »
I think it would be better to anchor the controls and autosize this dialog - this way it will always be correct.

Please check out this - it works for me, but it should be tested more:

Code: Pascal  [Select][+][-]
  1. function DoInputCombo(const ACaption, APrompt: string; const AList: TStrings; AllowInput : Boolean; Out ASelected : Integer) : String;
  2. const
  3.   CBStyles : array[Boolean] of TComboBoxStyle = (csDropDownList,csDropDown);
  4. var
  5.   W,I,Sep,Margin: Integer;
  6.   Frm: TForm;
  7.   CBSelect : TComboBox;
  8.   LPrompt: TLabel;
  9.   BP: TButtonPanel;
  10.   P: TPanel;
  11. begin
  12.   Result:='';
  13.   ASelected:=-1;
  14.   frm := TForm.Create(Application);
  15.   try
  16.     Margin:= frm.Scale96ToForm(16);
  17.     Sep := frm.Scale96ToForm(8);
  18.  
  19.     frm.BorderStyle:=bsDialog;
  20.     frm.Caption:=ACaption;
  21.     frm.Position:=poScreenCenter;
  22.  
  23.     // Determine needed width
  24.     W:=frm.Canvas.TextWidth(APrompt);
  25.     W:=Max(W,frm.Canvas.TextWidth(ACaption));
  26.     for I:=0 to AList.Count-1 do
  27.       W:=Max(W,frm.Canvas.TextWidth(AList[i]+'WWW')); // WWW is just some extra.
  28.  
  29.     // Panel for controls
  30.     P := TPanel.Create(frm);
  31.     P.Parent := frm;
  32.     P.Align := alClient;
  33.     P.Borderspacing.Around := Margin;
  34.     P.Caption := '';
  35.     P.BevelOuter := bvNone;
  36.     P.AutoSize := true;
  37.  
  38.     // Prompt
  39.     LPrompt:=TLabel.Create(frm);
  40.     LPrompt.Parent:=P; //frm;
  41.     LPrompt.Caption:=APrompt;
  42.     LPrompt.AnchorSideTop.Control := P;
  43.     LPrompt.AnchorSideLeft.Control := P;
  44.     LPrompt.AnchorSideRight.Control := P;
  45.     LPrompt.AnchorSideRight.Side := asrBottom;
  46.     LPrompt.BorderSpacing.Bottom := Sep;
  47.     LPrompt.Anchors := [akLeft, akRight, akTop];
  48.     LPrompt.WordWrap:=True;
  49.     LPrompt.AutoSize:=true;
  50.  
  51.     // Selection combobox
  52.     CBSelect:=TComboBox.Create(Frm);
  53.     CBSelect.Parent:=P;
  54.     CBSelect.Style:=CBStyles[AllowInput];
  55.     CBSelect.Items.Assign(AList);
  56.     CBSelect.ItemIndex:=-1;
  57.     CBSelect.AnchorSideTop.Control := LPrompt;
  58.     CBSelect.AnchorSideTop.Side := asrBottom;
  59.     CBSelect.AnchorSideLeft.Control := P;
  60.     CBSelect.AnchorSideRight.Control := P;
  61.     CBSelect.AnchorSideRight.Side := asrBottom;
  62.     CBSelect.Anchors := [akLeft, akRight, akTop];
  63.  
  64.     // Buttons
  65.     BP:=TButtonPanel.Create(Frm);
  66.     BP.Parent:=Frm;
  67.     BP.ShowButtons:=[pbOK,pbCancel];
  68.  
  69.     // Autosize the form
  70.     frm.AutoSize := true;
  71.     frm.Constraints.MinWidth := W + 2*Margin;
  72.  
  73.     if (frm.ShowModal=mrOk) then
  74.     begin
  75.       Result:=CBSelect.Text;
  76.       ASelected:=CBSelect.ItemIndex;
  77.     end;
  78.   finally
  79.     FreeAndNil(frm);
  80.   end;
  81. end;
« Last Edit: October 02, 2021, 12:33:10 am by wp »

magu

  • New Member
  • *
  • Posts: 36
Re: InputCombo : Minor bug.
« Reply #2 on: October 02, 2021, 10:47:45 am »
This works, thanks!

wp

  • Hero Member
  • *****
  • Posts: 12593
Re: InputCombo : Minor bug.
« Reply #3 on: October 02, 2021, 01:01:20 pm »
Committed the change to Lazarus-main.

jamie

  • Hero Member
  • *****
  • Posts: 6801
Re: InputCombo : Minor bug.
« Reply #4 on: October 02, 2021, 02:43:07 pm »
Committed the change to Lazarus-main.

I never knew that existed. I could of used that not to long ago.  it looks good with Trunk.
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 12593
Re: InputCombo : Minor bug.
« Reply #5 on: October 02, 2021, 05:39:35 pm »
Don't really know how to suggest bug reports / fixes
Write a bug report on

 

TinyPortal © 2005-2018