PageRenderTime 17ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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