IDE.InputQueryComboForm.pas 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. unit IDE.InputQueryComboForm;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2020 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. InputQuery with a TComboBox instead of a TEdit
  8. Unlike InputQuery it doesn't limit the value to 255 characters
  9. }
  10. interface
  11. uses
  12. Classes, Controls, StdCtrls, UIStateForm;
  13. type
  14. TInputQueryComboForm = class(TUIStateForm)
  15. OKButton: TButton;
  16. CancelButton: TButton;
  17. PromptLabel: TLabel;
  18. ValueControl: TComboBox;
  19. procedure FormCreate(Sender: TObject);
  20. private
  21. function GetValue: String;
  22. procedure SetPrompt(const APrompt: String);
  23. procedure SetValue(const AValue: String);
  24. procedure SetValues(const AValues: TStringList);
  25. public
  26. property Prompt: String write SetPrompt;
  27. property Value: String read GetValue write SetValue;
  28. property Values: TStringList write SetValues;
  29. end;
  30. function InputQueryCombo(const ACaption, APrompt: String; var AValue: String; const AValues: TStringList): Boolean;
  31. implementation
  32. uses
  33. Windows, Messages, IDE.HelperFunc, Forms;
  34. {$R *.DFM}
  35. function InputQueryCombo(const ACaption, APrompt: String; var AValue: String; const AValues: TStringList): Boolean;
  36. begin
  37. with TInputQueryComboForm.Create(Application) do try
  38. Caption := ACaption;
  39. Prompt := APrompt;
  40. Value := AValue;
  41. Values := AValues;
  42. if ShowModal = mrOk then begin
  43. AValue := Value;
  44. Result := True;
  45. end else
  46. Result := False;
  47. finally
  48. Free;
  49. end;
  50. end;
  51. procedure TInputQueryComboForm.FormCreate(Sender: TObject);
  52. begin
  53. InitFormFont(Self);
  54. InitFormTheme(Self);
  55. end;
  56. function TInputQueryComboForm.GetValue: String;
  57. begin
  58. Result := ValueControl.Text;
  59. end;
  60. procedure TInputQueryComboForm.SetPrompt(const APrompt: String);
  61. begin
  62. PromptLabel.Caption := APrompt;
  63. var MoveX := PromptLabel.Left + PromptLabel.Width + CancelButton.Left - (OkButton.Left + OkButton.Width) - ValueControl.Left;
  64. ValueControl.Left := ValueControl.Left + MoveX;
  65. ValueControl.Width := ValueControl.Width - MoveX;
  66. end;
  67. procedure TInputQueryComboForm.SetValue(const AValue: String);
  68. begin
  69. ValueControl.Text := AValue;
  70. end;
  71. procedure TInputQueryComboForm.SetValues(const AValues: TStringList);
  72. begin
  73. ValueControl.Items := AValues;
  74. end;
  75. end.