/components/lazreport/source/lr_expres.pas

http://github.com/graemeg/lazarus · Pascal · 150 lines · 127 code · 19 blank · 4 comment · 8 complexity · f8f8a91eafcb9a674a70223a186f07f7 MD5 · raw file

  1. unit lr_expres;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
  6. Buttons, ExtCtrls, ButtonPanel, SynEdit, LR_Const;
  7. type
  8. { TlrExpresionEditorForm }
  9. TlrExpresionEditorForm = class(TForm)
  10. BitBtn1: TBitBtn;
  11. BitBtn2: TBitBtn;
  12. BitBtn3: TBitBtn;
  13. Button1: TButton;
  14. Button10: TButton;
  15. Button11: TButton;
  16. Button12: TButton;
  17. Button13: TButton;
  18. Button14: TButton;
  19. Button2: TButton;
  20. Button3: TButton;
  21. Button4: TButton;
  22. Button5: TButton;
  23. Button6: TButton;
  24. Button7: TButton;
  25. Button8: TButton;
  26. Button9: TButton;
  27. ButtonPanel1: TButtonPanel;
  28. GroupBox1: TGroupBox;
  29. Label1: TLabel;
  30. Panel1: TPanel;
  31. Memo1: TSynEdit;
  32. procedure BitBtn1Click(Sender: TObject);
  33. procedure BitBtn2Click(Sender: TObject);
  34. procedure BitBtn3Click(Sender: TObject);
  35. procedure Button13Click(Sender: TObject);
  36. procedure FormCreate(Sender: TObject);
  37. private
  38. procedure AddWord(S:string);
  39. public
  40. function ResultExpresion:string;
  41. end;
  42. implementation
  43. {$R *.lfm}
  44. uses LR_Var, LR_Flds, lr_funct_editor_unit, lr_funct_editor_unit1, LR_Class;
  45. { TlrExpresionEditorForm }
  46. procedure TlrExpresionEditorForm.Button13Click(Sender: TObject);
  47. begin
  48. AddWord((Sender as TButton).Caption);
  49. end;
  50. procedure TlrExpresionEditorForm.FormCreate(Sender: TObject);
  51. begin
  52. Caption := sInsertExpression;
  53. Label1.Caption := sVar2;
  54. GroupBox1.Caption := sInsert;
  55. BitBtn3.Caption := sDBField;
  56. BitBtn2.Caption := sVariable;
  57. BitBtn1.Caption := sEditorFormFunction;
  58. end;
  59. procedure TlrExpresionEditorForm.BitBtn2Click(Sender: TObject);
  60. begin
  61. frVarForm := TfrVarForm.Create(nil);
  62. try
  63. with frVarForm do
  64. if ShowModal = mrOk then
  65. begin
  66. if SelectedItem <> '' then
  67. AddWord('[' + SelectedItem + ']');
  68. end;
  69. finally
  70. frVarForm.Free;
  71. end;
  72. end;
  73. procedure TlrExpresionEditorForm.BitBtn1Click(Sender: TObject);
  74. var
  75. LR_FunctEditorForm: TLR_FunctEditorForm;
  76. FD:TfrFunctionDescription;
  77. LR_FunctEditor1Form: TLR_FunctEditor1Form;
  78. begin
  79. FD:=nil;
  80. LR_FunctEditorForm:=TLR_FunctEditorForm.Create(Application);
  81. try
  82. if LR_FunctEditorForm.ShowModal = mrOk then
  83. FD:=LR_FunctEditorForm.CurentFunctionDescription;
  84. finally
  85. LR_FunctEditorForm.Free;
  86. end;
  87. if Assigned(FD) then
  88. begin
  89. LR_FunctEditor1Form:=TLR_FunctEditor1Form.Create(Application);
  90. try
  91. LR_FunctEditor1Form.SetFunctionDescription(FD);
  92. if LR_FunctEditor1Form.ShowModal = mrOk then
  93. AddWord(LR_FunctEditor1Form.ResultText);
  94. finally
  95. LR_FunctEditor1Form.Free;
  96. end;
  97. end;
  98. end;
  99. procedure TlrExpresionEditorForm.BitBtn3Click(Sender: TObject);
  100. begin
  101. frFieldsForm := TfrFieldsForm.Create(nil);
  102. try
  103. with frFieldsForm do
  104. begin
  105. if ShowModal = mrOk then
  106. begin
  107. if DBField <> '' then
  108. AddWord('[' + DBField + ']');
  109. end;
  110. end;
  111. finally
  112. frFieldsForm.Free;
  113. end;
  114. end;
  115. procedure TlrExpresionEditorForm.AddWord(S: string);
  116. begin
  117. if Memo1.Lines.Count = 0 then
  118. Memo1.Lines.Add(S)
  119. else
  120. begin
  121. Memo1.Lines[Memo1.Lines.Count-1]:=Memo1.Lines[Memo1.Lines.Count-1] + S;
  122. end;
  123. Memo1.CaretY:=Memo1.Lines.Count-1;
  124. Memo1.CaretX:=Length(Memo1.Lines[Memo1.Lines.Count-1])+1;
  125. Memo1.SetFocus;
  126. end;
  127. function TlrExpresionEditorForm.ResultExpresion: string;
  128. begin
  129. Result:=Trim(Memo1.Text);
  130. end;
  131. end.