TBXStrEdit.pas 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. unit TBXStrEdit;
  2. // TBX Package
  3. // Copyright 2001-2004 Alex A. Denisov. All Rights Reserved
  4. // See TBX.chm for license and installation instructions
  5. //
  6. // Id: TBXStrEdit.pas 7 2004-02-21 06:07:53Z
  7. interface
  8. uses
  9. Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls;
  10. type
  11. TStrEditDlg = class(TForm)
  12. Memo: TMemo;
  13. OK: TButton;
  14. Cancel: TButton;
  15. procedure MemoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  16. protected
  17. procedure ArrangeControls;
  18. procedure Resize; override;
  19. public
  20. constructor Create(AOwner: TComponent); override;
  21. end;
  22. implementation
  23. procedure TStrEditDlg.ArrangeControls;
  24. var
  25. R, B: TRect;
  26. W, H: Integer;
  27. begin
  28. R := ClientRect;
  29. InflateRect(R, -6, -6);
  30. B := R;
  31. W := 70; H := 23;
  32. B.Left := B.Right - W;
  33. B.Top := B.Bottom - H;
  34. Cancel.BoundsRect := B;
  35. B.Right := B.Left - 4;
  36. B.Left := B.Right - W;
  37. OK.BoundsRect := B;
  38. Dec(R.Bottom, H + 8);
  39. Memo.BoundsRect := R;
  40. end;
  41. constructor TStrEditDlg.Create(AOwner: TComponent);
  42. begin
  43. inherited CreateNew(AOwner);
  44. AutoScroll := False;
  45. Constraints.MinHeight := 200;
  46. Constraints.MinWidth := 300;
  47. Scaled := False;
  48. Position := poScreenCenter;
  49. Memo := TMemo.Create(Self);
  50. with Memo do
  51. begin
  52. ScrollBars := ssBoth;
  53. OnKeyDown := MemoKeyDown;
  54. Parent := Self;
  55. end;
  56. OK := TButton.Create(Self);
  57. with OK do
  58. begin
  59. Caption := 'OK';
  60. Default := True;
  61. ModalResult := mrOk;
  62. Parent := Self;
  63. end;
  64. Cancel := TButton.Create(Self);
  65. with Cancel do
  66. begin
  67. Cancel := True;
  68. Caption := 'Cancel';
  69. ModalResult := mrCancel;
  70. Parent := Self;
  71. end;
  72. end;
  73. procedure TStrEditDlg.MemoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  74. begin
  75. if Key = VK_ESCAPE then Cancel.Click;
  76. end;
  77. procedure TStrEditDlg.Resize;
  78. begin
  79. inherited;
  80. ArrangeControls;
  81. end;
  82. end.