/components/lazreport/source/lr_funct_editor_unit1.pas

http://github.com/graemeg/lazarus · Pascal · 130 lines · 95 code · 29 blank · 6 comment · 7 complexity · 6896708140a637bdb09756f00fc15435 MD5 · raw file

  1. unit lr_funct_editor_unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
  6. ExtCtrls, LR_Class, LR_Const, EditBtn, Buttons, ButtonPanel;
  7. type
  8. { TLR_FunctEditor1Form }
  9. TLR_FunctEditor1Form = class(TForm)
  10. BitBtn3: TBitBtn;
  11. BitBtn4: TBitBtn;
  12. BitBtn5: TBitBtn;
  13. ButtonPanel1: TButtonPanel;
  14. Edit1: TEdit;
  15. Edit2: TEdit;
  16. Edit3: TEdit;
  17. GroupBox1: TGroupBox;
  18. Label1: TLabel;
  19. Label2: TLabel;
  20. Label3: TLabel;
  21. Label4: TLabel;
  22. Label5: TLabel;
  23. Panel1: TPanel;
  24. procedure BitBtn5Click(Sender: TObject);
  25. procedure FormCreate(Sender: TObject);
  26. private
  27. FParCount:integer;
  28. FD:TfrFunctionDescription;
  29. public
  30. procedure SetFunctionDescription(AFD:TfrFunctionDescription);
  31. function ResultText:string;
  32. end;
  33. implementation
  34. {$R *.lfm}
  35. uses lr_expres, lr_utils;
  36. { TLR_FunctEditor1Form }
  37. procedure TLR_FunctEditor1Form.BitBtn5Click(Sender: TObject);
  38. var
  39. EF:TlrExpresionEditorForm;
  40. begin
  41. EF:=TlrExpresionEditorForm.Create(Application);
  42. try
  43. if EF.ShowModal = mrOk then
  44. case (Sender as TComponent).Tag of
  45. 1:Edit1.Text:=EF.ResultExpresion;
  46. 2:Edit2.Text:=EF.ResultExpresion;
  47. 3:Edit3.Text:=EF.ResultExpresion;
  48. end;
  49. finally
  50. EF.Free;
  51. end;
  52. end;
  53. procedure TLR_FunctEditor1Form.FormCreate(Sender: TObject);
  54. begin
  55. Caption:=sFunctionEditor;
  56. GroupBox1.Caption:=sArguments;
  57. Label3.Caption:=sArgument1;
  58. Label4.Caption:=sArgument2;
  59. Label5.Caption:=sArgument3;
  60. end;
  61. procedure TLR_FunctEditor1Form.SetFunctionDescription(AFD: TfrFunctionDescription);
  62. var
  63. S, S1:string;
  64. i:integer;
  65. begin
  66. // TODO: context sensitive inpunts, for example for
  67. // bandname use the list of available bands.
  68. FD:=AFD;
  69. S:=FD.funDescription;
  70. S1:=Copy(S, 1, Pos('/', S)-1);
  71. FParCount:=0;
  72. for i:=1 to Length(S1) do
  73. if S1[i]='<' then
  74. Inc(FParCount);
  75. Label1.Caption:=S1;
  76. Delete(S, 1, Pos('/', S));
  77. Label2.Caption:=S;
  78. Label3.Enabled:=FParCount>0;
  79. Edit1.Enabled:=FParCount>0;
  80. BitBtn3.Enabled:=FParCount>0;
  81. Label4.Enabled:=FParCount>1;
  82. Edit2.Enabled:=FParCount>1;
  83. BitBtn4.Enabled:=FParCount>0;
  84. Label5.Enabled:=FParCount>2;
  85. Edit3.Enabled:=FParCount>2;
  86. BitBtn5.Enabled:=FParCount>0;
  87. end;
  88. function TLR_FunctEditor1Form.ResultText: string;
  89. begin
  90. Result:='';
  91. if FParCount>0 then
  92. Result:=Result + '[' + lrGetUnBrackedStr(Edit1.Text) + ']';
  93. if FParCount>1 then
  94. Result:=Result + ', [' + lrGetUnBrackedStr(Edit2.Text) + ']';
  95. if FParCount>2 then
  96. Result:=Result + ', [' + lrGetUnBrackedStr(Edit3.Text) + ']';
  97. if FParCount>0 then
  98. Result:='('+Result+')';
  99. Result:=FD.funName + Result;
  100. end;
  101. end.