home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kolekce / d6 / FRCLX.ZIP / SOURCE / FR_Expr.pas < prev    next >
Pascal/Delphi Source File  |  2001-07-03  |  4KB  |  159 lines

  1.  
  2. {******************************************}
  3. {                                          }
  4. {           FastReport CLX v2.4            }
  5. {           Expression builder             }
  6. {                                          }
  7. { Copyright (c) 1998-2001 by Tzyganenko A. }
  8. {                                          }
  9. {******************************************}
  10.  
  11. unit FR_Expr;
  12.  
  13. interface
  14.  
  15. {$I FR.inc}
  16.  
  17. uses
  18.   SysUtils, Classes, QGraphics, QControls, QForms, QDialogs,
  19.   FR_Ctrls, QStdCtrls, QButtons;
  20.  
  21. type
  22.   TfrExprForm = class(TForm)
  23.     GroupBox1: TGroupBox;
  24.     ExprMemo: TMemo;
  25.     GroupBox2: TGroupBox;
  26.     frSpeedButton1: TfrSpeedButton;
  27.     frSpeedButton2: TfrSpeedButton;
  28.     frSpeedButton3: TfrSpeedButton;
  29.     frSpeedButton4: TfrSpeedButton;
  30.     frSpeedButton5: TfrSpeedButton;
  31.     frSpeedButton6: TfrSpeedButton;
  32.     frSpeedButton7: TfrSpeedButton;
  33.     frSpeedButton8: TfrSpeedButton;
  34.     frSpeedButton9: TfrSpeedButton;
  35.     frSpeedButton10: TfrSpeedButton;
  36.     frSpeedButton11: TfrSpeedButton;
  37.     frSpeedButton12: TfrSpeedButton;
  38.     frSpeedButton13: TfrSpeedButton;
  39.     InsDBBtn: TfrSpeedButton;
  40.     InsVarBtn: TfrSpeedButton;
  41.     InsFuncBtn: TfrSpeedButton;
  42.     Button1: TButton;
  43.     Button2: TButton;
  44.     procedure InsFuncBtnClick(Sender: TObject);
  45.     procedure InsDBBtnClick(Sender: TObject);
  46.     procedure InsVarBtnClick(Sender: TObject);
  47.     procedure frSpeedButton1Click(Sender: TObject);
  48.     procedure FormCreate(Sender: TObject);
  49.     procedure ExprMemoKeyDown(Sender: TObject; var Key: Word;
  50.       Shift: TShiftState);
  51.   private
  52.     { Private declarations }
  53.     procedure Localize;
  54.   public
  55.     { Public declarations }
  56.   end;
  57.  
  58.  
  59. implementation
  60.  
  61. uses FR_Funcs, FR_Arg, FR_Class, FR_Const, FR_Var, FR_Flds, FR_Utils, Qt;
  62.  
  63. {$R *.xfm}
  64.  
  65. function AddBrackets(s: String): String;
  66. var
  67.   i: Integer;
  68. begin
  69.   Result := s;
  70.   s := AnsiUpperCase(s);
  71.   for i := 1 to Length(s) do
  72.     if not (s[i] in ['0'..'9', '_', '.', 'A'..'Z']) then
  73.     begin
  74.       Result := '[' + Result + ']';
  75.       break;
  76.     end;
  77. end;
  78.  
  79. procedure TfrExprForm.InsFuncBtnClick(Sender: TObject);
  80. var
  81.   sFunc, sSyntax: String;
  82.   frFuncArgForm: TfrFuncArgForm;
  83. begin
  84.   with TfrFuncForm.Create(nil) do
  85.   begin
  86.     if ShowModal = mrOk then
  87.     begin
  88.       sFunc := FuncLB.Items[FuncLB.ItemIndex];
  89.       sSyntax := FuncLabel.Caption;
  90.       if Pos('(', sSyntax) <> 0 then
  91.       begin
  92.         frFuncArgForm := TfrFuncArgForm.Create(nil);
  93.         frFuncArgForm.FuncLabel.Caption := FuncLabel.Caption;
  94.         frFuncArgForm.DescrLabel.Caption := DescrLabel.Caption;
  95.         frFuncArgForm.Func := sFunc;
  96.         if frFuncArgForm.ShowModal = mrOk then
  97.           ExprMemo.SelText := frFuncArgForm.Func;
  98.         frFuncArgForm.Free;
  99.       end
  100.       else
  101.         ExprMemo.SelText := AddBrackets(sFunc);
  102.     end;
  103.     Free;
  104.   end;
  105. end;
  106.  
  107. procedure TfrExprForm.InsDBBtnClick(Sender: TObject);
  108. begin
  109.   with TfrFieldsForm.Create(nil) do
  110.   begin
  111.     if ShowModal = mrOk then
  112.       if DBField <> '' then
  113.         ExprMemo.SelText := AddBrackets(DBField);
  114.     Free;
  115.   end;
  116. end;
  117.  
  118. procedure TfrExprForm.InsVarBtnClick(Sender: TObject);
  119. begin
  120.   with TfrVarForm.Create(nil) do
  121.   begin
  122.     if ShowModal = mrOk then
  123.       if SelectedItem <> '' then
  124.         ExprMemo.SelText := AddBrackets(SelectedItem);
  125.     Free;
  126.   end;
  127. end;
  128.  
  129. procedure TfrExprForm.frSpeedButton1Click(Sender: TObject);
  130. begin
  131.   ExprMemo.SelText := TfrSpeedButton(Sender).Caption + ' ';
  132. end;
  133.  
  134. procedure TfrExprForm.Localize;
  135. begin
  136.   Caption := S53700;
  137.   GroupBox1.Caption := S53701;
  138.   GroupBox2.Caption := S53702;
  139.   InsDBBtn.Caption := S53703;
  140.   InsVarBtn.Caption := S53704;
  141.   InsFuncBtn.Caption := S53705;
  142.   Button1.Caption := (SOk);
  143.   Button2.Caption := (SCancel);
  144. end;
  145.  
  146. procedure TfrExprForm.FormCreate(Sender: TObject);
  147. begin
  148.   Localize;
  149. end;
  150.  
  151. procedure TfrExprForm.ExprMemoKeyDown(Sender: TObject; var Key: Word;
  152.   Shift: TShiftState);
  153. begin
  154.   if Key = key_Escape then
  155.     ModalResult := mrCancel;
  156. end;
  157.  
  158. end.
  159.