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

  1.  
  2. {******************************************}
  3. {                                          }
  4. {   FastReport CLX v2.4 - DB components    }
  5. {            Various routines              }
  6. {                                          }
  7. { Copyright (c) 1998-2001 by Tzyganenko A. }
  8. {                                          }
  9. {******************************************}
  10.  
  11. unit FR_DBUtils;
  12.  
  13. interface
  14.  
  15. {$I FR.inc}
  16.  
  17. uses
  18.   Types, SysUtils, Classes, QGraphics, FR_Class, QStdCtrls,
  19.   QControls, QForms, QMenus, QDialogs, DB;
  20.  
  21. type
  22.   TfrParamKind = (pkAssignFromMaster, pkValue);
  23.  
  24. const
  25.   FieldClasses: array[0..9] of TFieldClass =
  26.    (TStringField, TSmallintField, TIntegerField, TWordField,
  27.     TBooleanField, TFloatField, TCurrencyField, TDateField,
  28.     TTimeField, TBlobField);
  29.  
  30.   ParamTypes: Array[0..10] of TFieldType =
  31.     (ftBCD, ftBoolean, ftCurrency, ftDate, ftDateTime, ftInteger,
  32.      ftFloat, ftSmallint, ftString, ftTime, ftWord);
  33.  
  34.  
  35. function frFindFieldDef(DataSet: TDataSet; FieldName: String): TFieldDef;
  36. function frGetDataSetName(Owner: TComponent; d: TDataSource): String;
  37. function frGetDataSource(Owner: TComponent; d: TDataSet): TDataSource;
  38.  
  39.  
  40. implementation
  41.  
  42. uses FR_Utils;
  43.  
  44.  
  45. function frFindFieldDef(DataSet: TDataSet; FieldName: String): TFieldDef;
  46. var
  47.   i: Integer;
  48. begin
  49.   Result := nil;
  50.   with DataSet do
  51.   for i := 0 to FieldDefs.Count - 1 do
  52.     if AnsiCompareText(FieldDefs.Items[i].Name, FieldName) = 0 then
  53.     begin
  54.       Result := FieldDefs.Items[i];
  55.       break;
  56.     end;
  57. end;
  58.  
  59. function frGetDataSetName(Owner: TComponent; d: TDataSource): String;
  60. begin
  61.   Result := '';
  62.   if (d <> nil) and (d.DataSet <> nil) then
  63.   begin
  64.     Result := d.Dataset.Name;
  65.     if d.Dataset.Owner <> Owner then
  66.       Result := d.Dataset.Owner.Name + '.' + Result;
  67.   end;
  68. end;
  69.  
  70. function frGetDataSource(Owner: TComponent; d: TDataSet): TDataSource;
  71. var
  72.   i: Integer;
  73.   sl: TStringList;
  74.   ds: TDataSource;
  75. begin
  76.   sl := TStringList.Create;
  77.   Result := nil;
  78.   frGetComponents(Owner, TDataSource, sl, nil);
  79.   for i := 0 to sl.Count - 1 do
  80.   begin
  81.     ds := frFindComponent(Owner, sl[i]) as TDataSource;
  82.     if (ds <> nil) and (ds.DataSet = d) then
  83.     begin
  84.       Result := ds;
  85.       break;
  86.     end;
  87.   end;
  88.   sl.Free;
  89. end;
  90.  
  91. end.
  92.  
  93.