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

  1.  
  2. {******************************************}
  3. {                                          }
  4. {   FastReport CLX v2.4 - DB components    }
  5. {          Lookup field definition         }
  6. {                                          }
  7. { Copyright (c) 1998-2001 by Tzyganenko A. }
  8. {                                          }
  9. {******************************************}
  10.  
  11. unit FR_DBNewLookup;
  12.  
  13. interface
  14.  
  15. {$I FR.inc}
  16.  
  17. uses
  18.   Types, SysUtils, Classes, QGraphics, QControls, QForms, QDialogs,
  19.   QStdCtrls, DB;
  20.  
  21. type
  22.   TfrDBLookupFieldForm = class(TForm)
  23.     GroupBox1: TGroupBox;
  24.     Label1: TLabel;
  25.     NameE: TEdit;
  26.     Label2: TLabel;
  27.     Label3: TLabel;
  28.     TypeCB: TComboBox;
  29.     SizeE: TEdit;
  30.     GroupBox2: TGroupBox;
  31.     Label4: TLabel;
  32.     Label5: TLabel;
  33.     Label6: TLabel;
  34.     Label7: TLabel;
  35.     lFieldCB: TComboBox;
  36.     lDatasetCB: TComboBox;
  37.     lKeyCB: TComboBox;
  38.     lResultCB: TComboBox;
  39.     Button1: TButton;
  40.     Button2: TButton;
  41.     procedure FormShow(Sender: TObject);
  42.     procedure lDatasetCBChange(Sender: TObject);
  43.     procedure FormCreate(Sender: TObject);
  44.     procedure Button1Click(Sender: TObject);
  45.   private
  46.     { Private declarations }
  47.     FLookup: TDataset;
  48.     procedure Localize;
  49.   public
  50.     { Public declarations }
  51.     Dataset: TDataset;
  52.   end;
  53.  
  54. implementation
  55.  
  56. uses FR_DBUtils, FR_Const, FR_Utils;
  57.  
  58.  
  59. {$R *.xfm}
  60.  
  61. procedure TfrDBLookupFieldForm.FormShow(Sender: TObject);
  62. begin
  63.   with TypeCB.Items do
  64.   begin
  65.     Clear;
  66.     Add(SFieldType1);
  67.     Add(SFieldType2);
  68.     Add(SFieldType3);
  69.     Add(SFieldType4);
  70.     Add(SFieldType5);
  71.     Add(SFieldType6);
  72.     Add(SFieldType7);
  73.     Add(SFieldType8);
  74.     Add(SFieldType9);
  75.     Add(SFieldType10);
  76.   end;
  77.  
  78.   TypeCB.ItemIndex := 0;
  79.   Dataset.GetFieldNames(lFieldCB.Items);
  80.   frGetComponents(DataSet.Owner, TDataSet, lDataSetCB.Items, DataSet);
  81. end;
  82.  
  83. procedure TfrDBLookupFieldForm.Button1Click(Sender: TObject);
  84. var
  85.   Field: TField;
  86. begin
  87.   ModalResult := mrOk;
  88.   Field := FieldClasses[TypeCB.ItemIndex].Create(Dataset);
  89.   with Field do
  90.   begin
  91.     if Field is TStringField then
  92.       try
  93.         Size := StrToInt(SizeE.Text);
  94.       except
  95.         ModalResult := mrNone;
  96.         Application.MessageBox(SFieldSizeError, SError, [smbOk], smsCritical);
  97.         SizeE.Text := '';
  98.         ActiveControl := SizeE;
  99.         Exit;
  100.       end;
  101.     Lookup := True;
  102.     LookupDataset := FLookup;
  103.     KeyFields := lFieldCB.Text;
  104.     LookupKeyFields := lKeyCB.Text;
  105.     LookupResultField := lResultCB.Text;
  106.     FieldName := NameE.Text;
  107.     Dataset := Self.Dataset;
  108.   end;
  109. end;
  110.  
  111. procedure TfrDBLookupFieldForm.lDatasetCBChange(Sender: TObject);
  112. begin
  113.   FLookup := frFindComponent(DataSet.Owner, lDatasetCB.Text) as TDataset;
  114.   lKeyCB.Items.Clear;
  115.   lResultCB.Items.Clear;
  116.   if FLookup <> nil then
  117.   begin
  118.     FLookup.GetFieldNames(lKeyCB.Items);
  119.     lResultCB.Items.Assign(lKeyCB.Items);
  120.   end;
  121.   lKeyCB.Text := '';
  122.   lResultCB.Text := '';
  123. end;
  124.  
  125. procedure TfrDBLookupFieldForm.Localize;
  126. begin
  127.   Caption := S56070;
  128.   GroupBox1.Caption := S56071;
  129.   Label1.Caption := S56072;
  130.   Label2.Caption := S56073;
  131.   Label3.Caption := S56074;
  132.   GroupBox2.Caption := S56075;
  133.   Label4.Caption := S56076;
  134.   Label5.Caption := S56077;
  135.   Label6.Caption := S56078;
  136.   Label7.Caption := S56079;
  137.   Button1.Caption := (SOk);
  138.   Button2.Caption := (SCancel);
  139. end;
  140.  
  141. procedure TfrDBLookupFieldForm.FormCreate(Sender: TObject);
  142. begin
  143.   Localize;
  144. end;
  145.  
  146. end.
  147.  
  148.