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

  1.  
  2. {******************************************}
  3. {                                          }
  4. {           FastReport CLX v2.4            }
  5. {     Select Band datasource dialog        }
  6. {                                          }
  7. { Copyright (c) 1998-2001 by Tzyganenko A. }
  8. {                                          }
  9. {******************************************}
  10.  
  11. unit FR_VBnd;
  12.  
  13. interface
  14.  
  15. {$I FR.inc}
  16.  
  17. uses
  18.   SysUtils, Types, Classes, QGraphics, QControls, QForms, QDialogs,
  19.   QExtCtrls, QStdCtrls, FR_Class, FR_Pars;
  20.  
  21. type
  22.   TfrVBandEditorForm = class(TfrObjEditorForm)
  23.     Button1: TButton;
  24.     Button2: TButton;
  25.     GroupBox1: TGroupBox;
  26.     GroupBox2: TGroupBox;
  27.     Label1: TLabel;
  28.     CB1: TComboBox;
  29.     Edit1: TEdit;
  30.     LB1: TListBox;
  31.     Image1: TImage;
  32.     Image2: TImage;
  33.     procedure FormCreate(Sender: TObject);
  34.     procedure CB1Click(Sender: TObject);
  35.     procedure LB1Click(Sender: TObject);
  36.     procedure CB1Exit(Sender: TObject);
  37.     procedure LB1DrawItem(Sender: TObject; Index: Integer; ARect: TRect;
  38.       State: TOwnerDrawState; var Handled: Boolean);
  39.     procedure CB1DrawItem(Sender: TObject; Index: Integer; ARect: TRect;
  40.       State: TOwnerDrawState; var Handled: Boolean);
  41.   private
  42.     { Private declarations }
  43.     Band: TfrBandView;
  44.     List: TfrVariables;
  45.     procedure FillCombo;
  46.     procedure Localize;
  47.   public
  48.     { Public declarations }
  49.     function ShowEditor(View: TfrView): TModalResult; override;
  50.   end;
  51.  
  52.  
  53. implementation
  54.  
  55. {$R *.xfm}
  56.  
  57. uses FR_DSet, FR_Const, FR_Utils, FR_Ctrls;
  58.  
  59. function TfrVBandEditorForm.ShowEditor(View: TfrView): TModalResult;
  60. var
  61.   i, j, n: Integer;
  62.   s: String;
  63.   t1: TfrView;
  64.   b: Boolean;
  65. begin
  66.   Band := View as TfrBandView;
  67.   List := TfrVariables.Create;
  68.  
  69.   s := Band.Dataset;
  70.   b := False;
  71.   if Pos(';', s) = 0 then
  72.     b := True;
  73.  
  74.   with frDesigner.Page do
  75.   for i := 0 to Objects.Count - 1 do
  76.   begin
  77.     t1 := Objects[i];
  78.     if (t1.Typ = gtBand) and not (TfrBandView(t1).BandType in
  79.       [btReportTitle..btPageFooter, btOverlay, btCrossHeader..btCrossFooter]) then
  80.     begin
  81.       LB1.Items.Add(t1.Name + ': ' + frBandNames[t1.FrameTyp]);
  82.       n := Pos(AnsiUpperCase(t1.Name) + '=', AnsiUpperCase(s));
  83.       if n <> 0 then
  84.       begin
  85.         n := n + Length(t1.Name) + 1;
  86.         j := n;
  87.         while s[j] <> ';' do Inc(j);
  88.         List[t1.Name] := Copy(s, n, j - n);
  89.       end
  90.       else
  91.         if b then
  92.           List[t1.Name] := s else
  93.           List[t1.Name] := '0';
  94.     end;
  95.   end;
  96.   if LB1.Items.Count = 0 then
  97.   begin
  98.     List.Free;
  99.     Result := mrCancel;
  100.     Exit;
  101.   end;
  102.   FillCombo;
  103.   LB1.ItemIndex := 0;
  104.   LB1Click(nil);
  105.  
  106.   Result := ShowModal;
  107.   if Result = mrOk then
  108.   begin
  109.     CB1Exit(nil);
  110.     frDesigner.BeforeChange;
  111.     s := '';
  112.     for i := 0 to List.Count - 1 do
  113.       s := s + List.Name[i] + '=' + List.Value[i] + ';';
  114.     Band.DataSet := s;
  115.   end;
  116.   List.Free;
  117. end;
  118.  
  119. procedure TfrVBandEditorForm.FillCombo;
  120. begin
  121.   CurReport.Dictionary.GetBandDatasourceList(CB1.Items);
  122.   CB1.Items.Insert(0, (SVirtualDataset));
  123.   CB1.Items.Insert(0, (SNotAssigned));
  124. end;
  125.  
  126. procedure TfrVBandEditorForm.Localize;
  127. begin
  128.   Caption := S53485;
  129.   GroupBox1.Caption := S53486;
  130.   GroupBox2.Caption := S53487;
  131.   Label1.Caption := S53488;
  132.   Button1.Caption := (SOk);
  133.   Button2.Caption := (SCancel);
  134. end;
  135.  
  136. procedure TfrVBandEditorForm.FormCreate(Sender: TObject);
  137. begin
  138.   Localize;
  139. end;
  140.  
  141. procedure TfrVBandEditorForm.CB1Click(Sender: TObject);
  142. begin
  143.   frEnableControls([Label1, Edit1], CB1.ItemIndex = 1);
  144. end;
  145.  
  146. procedure TfrVBandEditorForm.LB1Click(Sender: TObject);
  147. var
  148.   i: Integer;
  149.   s: String;
  150. begin
  151.   s := LB1.Items[LB1.ItemIndex];
  152.   s := Copy(s, 1, Pos(':', s) - 1);
  153.   s := List[s];
  154.   if (s <> '') and (s[1] in ['1'..'9']) then
  155.   begin
  156.     i := 1;
  157.     Edit1.Text := s;
  158.   end
  159.   else
  160.   begin
  161.     i := CB1.Items.IndexOf(CurReport.Dictionary.AliasName[s]);
  162.     if i = -1 then
  163.       i := CB1.Items.IndexOf((SNotAssigned));
  164.   end;
  165.   CB1.ItemIndex := i;
  166.   CB1Click(nil);
  167. end;
  168.  
  169. procedure TfrVBandEditorForm.CB1Exit(Sender: TObject);
  170. var
  171.   s: String;
  172. begin
  173.   s := LB1.Items[LB1.ItemIndex];
  174.   s := Copy(s, 1, Pos(':', s) - 1);
  175.   if CB1.ItemIndex = 1 then
  176.     List[s] := Edit1.Text else
  177.     List[s] := CurReport.Dictionary.RealDataSourceName[CB1.Items[CB1.ItemIndex]];
  178. end;
  179.  
  180. procedure TfrVBandEditorForm.CB1DrawItem(Sender: TObject; Index: Integer;
  181.   ARect: TRect; State: TOwnerDrawState; var Handled: Boolean);
  182. var
  183.   r: TRect;
  184. begin
  185.   r := ARect;
  186.   r.Right := r.Left + 18;
  187.   r.Bottom := r.Top + 16;
  188.   OffsetRect(r, 2, 0);
  189.   with TComboBox(Sender) do
  190.   begin
  191.     Canvas.FillRect(ARect);
  192.     if Index <> 0 then
  193.       frDrawTransparent(Canvas, r.Left, r.Top, Image1.Picture.Bitmap);
  194.     Canvas.TextOut(ARect.Left + 20, ARect.Top + 1, Items[Index]);
  195.   end;
  196. end;
  197.  
  198. procedure TfrVBandEditorForm.LB1DrawItem(Sender: TObject; Index: Integer;
  199.   ARect: TRect; State: TOwnerDrawState; var Handled: Boolean);
  200. var
  201.   r: TRect;
  202. begin
  203.   r := ARect;
  204.   r.Right := r.Left + 18;
  205.   r.Bottom := r.Top + 16;
  206.   OffsetRect(r, 2, 0);
  207.   with TListBox(Sender) do
  208.   begin
  209.     Canvas.FillRect(ARect);
  210.     frDrawTransparent(Canvas, r.Left, r.Top, Image2.Picture.Bitmap);
  211.     Canvas.TextOut(ARect.Left + 20, ARect.Top + 1, Items[Index]);
  212.   end;
  213. end;
  214.  
  215.  
  216. end.
  217.  
  218.