PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

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