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

/components/lazreport/source/lr_flds.pas

http://github.com/graemeg/lazarus
Pascal | 167 lines | 123 code | 24 blank | 20 comment | 11 complexity | acb089a17421d76ce355ce896379227a MD5 | raw file
  1
  2{*****************************************}
  3{                                         }
  4{             FastReport v2.3             }
  5{               Fields list               }
  6{                                         }
  7{  Copyright (c) 1998-99 by Tzyganenko A. }
  8{                                         }
  9{*****************************************}
 10
 11unit LR_Flds;
 12
 13interface
 14
 15{$I LR_Vers.inc}
 16
 17uses
 18  Classes, SysUtils, LResources,
 19  Forms, Controls, Graphics, Dialogs,
 20  StdCtrls,LCLType;
 21
 22type
 23
 24  { TfrFieldsForm }
 25
 26  TfrFieldsForm = class(TForm)
 27    ValCombo: TComboBox;
 28    ValList: TListBox;
 29    Label1: TLabel;
 30    procedure ValComboClick(Sender: TObject);
 31    procedure FormActivate(Sender: TObject);
 32    procedure FormCreate(Sender: TObject);
 33    procedure FormDeactivate(Sender: TObject);
 34    procedure ValListDblClick(Sender: TObject);
 35    procedure ValListKeyDown(Sender: TObject; var Key: Word;
 36      {%H-}Shift: TShiftState);
 37    procedure FormKeyDown(Sender: TObject; var Key: Word;
 38      {%H-}Shift: TShiftState);
 39    procedure ValListSelectionChange(Sender: TObject; {%H-}User: boolean);
 40  private
 41    { Private declarations }
 42    procedure FillValCombo;
 43    procedure UpdateDBField;
 44  public
 45    { Public declarations }
 46    DBField: String;
 47  end;
 48
 49var
 50  frFieldsForm: TfrFieldsForm;
 51implementation
 52
 53{$R *.lfm}
 54
 55uses LR_Class, LR_Const, LR_Utils, LR_DBRel, DB;
 56
 57var
 58  LastDB: String;
 59
 60
 61procedure TfrFieldsForm.ValListKeyDown(Sender: TObject; var Key: Word;
 62  Shift: TShiftState);
 63begin
 64  if Key = vk_Return then
 65  begin
 66    UpdateDBField;
 67    ModalResult := mrOk;
 68  end;
 69end;
 70
 71procedure TfrFieldsForm.FillValCombo;
 72var
 73  Lst : TStringList;
 74begin
 75  Lst := TStringList.Create;
 76  try
 77    if Curreport.DataType = dtDataSet then
 78      frGetComponents(CurReport.Owner, TDataSet, Lst, nil)
 79    else
 80      frGetComponents(CurReport.Owner, TDataSource, Lst, nil);
 81    Lst.Sort;
 82    ValCombo.Items.Assign(Lst);
 83    ValCombo.Enabled:=(Lst.Count>0);
 84  finally
 85    Lst.Free;
 86  end;
 87end;
 88
 89procedure TfrFieldsForm.UpdateDBField;
 90begin
 91  if ValCombo.Items.Count>0 then
 92  begin
 93    LastDB := ValCombo.Items[ValCombo.ItemIndex];
 94    if ValList.ItemIndex <> -1 then
 95       DBField:=LastDB + '."' + ValList.Items[ValList.ItemIndex] + '"';
 96  end
 97  else DBField:='';
 98end;
 99
100procedure TfrFieldsForm.ValComboClick(Sender: TObject);
101var
102  DataSet: TfrTDataSet;
103begin
104  ValList.Items.Clear;
105  if ValCombo.Items.Count>0 then
106  begin
107    DataSet := nil;
108    DataSet := frGetDataSet(ValCombo.Items[ValCombo.ItemIndex]);
109    if Assigned(DataSet) then
110    begin
111      try
112        frGetFieldNames(DataSet, ValList.Items);
113      except
114      end;
115    end;
116  end;
117end;
118
119procedure TfrFieldsForm.FormKeyDown(Sender: TObject; var Key: Word;
120  Shift: TShiftState);
121begin
122  if Key = vk_Escape then
123    ModalResult := mrCancel;
124end;
125
126procedure TfrFieldsForm.ValListSelectionChange(Sender: TObject; User: boolean);
127begin
128{  if User then
129  begin
130    UpdateDbField;
131    if DBField<>'' then
132      ModalResult := mrOk;
133  end;}
134end;
135
136procedure TfrFieldsForm.FormCreate(Sender: TObject);
137begin
138  Caption := sFieldsFormInsert;
139  Label1.Caption := sFieldsFormAviableDB;
140end;
141
142procedure TfrFieldsForm.FormActivate(Sender: TObject);
143begin
144  FillValCombo;
145  if ValCombo.Items.Count>0 then
146  begin
147    if ValCombo.Items.IndexOf(LastDB) <> -1 then
148      ValCombo.ItemIndex := ValCombo.Items.IndexOf(LastDB)
149    else
150      ValCombo.ItemIndex := 0;
151    ValComboClick(nil);
152  end;
153end;
154
155procedure TfrFieldsForm.FormDeactivate(Sender: TObject);
156begin
157  //UpdateDBField;
158end;
159
160procedure TfrFieldsForm.ValListDblClick(Sender: TObject);
161begin
162  UpdateDbField;
163  if DBField<>'' then
164    ModalResult := mrOk;
165end;
166
167end.