home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d6 / RX275D6.ZIP / Units / RxBDEReg.pas < prev    next >
Pascal/Delphi Source File  |  2001-06-24  |  9KB  |  345 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {         Delphi VCL Extensions (RX)                    }
  4. {                                                       }
  5. {         Copyright (c) 1995, 1996 AO ROSNO             }
  6. {         Copyright (c) 1997, 1998 Master-Bank          }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. { Note:
  11.   - in Delphi 5.0 you must add DCLRX5 to the requires page of the
  12.     package you install this components into.
  13.   - in Delphi 4.0 you must add DCLRX4 to the requires page of the
  14.     package you install this components into.
  15.   - in Delphi 3.0 you must add DCLRXCTL to the requires page of the
  16.     package you install this components into.
  17.   - in C++Builder 4.0 you must add DCLRX4 to the requires page of the
  18.     package you install this components into.
  19.   - in C++Builder 3.0 you must add DCLRXCTL to the requires page of the
  20.     package you install this components into. }
  21.  
  22. unit RxBDEReg;
  23.  
  24. {$I RX.INC}
  25. {$D-,L-,S-}
  26.  
  27. interface
  28.  
  29. uses Classes, RTLConsts, DesignIntf, DesignEditors, VCLEditors, SysUtils, DB, DBTables;
  30.  
  31. { Register data aware custom controls }
  32.  
  33. procedure Register;
  34.  
  35. implementation
  36.  
  37. {$IFDEF WIN32}
  38.  {$R *.D32}
  39. {$ELSE}
  40.  {$R *.D16}
  41. {$ENDIF}
  42.  
  43. uses TypInfo, DBLists, RXLConst, DBQBE, DBIndex, DBPrgrss, 
  44.   RxLogin, DBSecur, RXQuery, VCLUtils, DbExcpt, RxDsgn,
  45.   {$IFDEF DCS} SelDSFrm, {$ENDIF} {$IFDEF RX_MIDAS} RxRemLog, {$ENDIF}
  46.   {$IFDEF RX_D3} QBndDlg, {$ELSE} 
  47.   {$IFNDEF WIN32} QBndDlg, {$ELSE} QBindDlg, {$ENDIF} {$ENDIF}
  48.   Consts, LibHelp, MemTable;
  49.  
  50. {$IFDEF WIN32}
  51.  
  52. { TSessionNameProperty }
  53.  
  54. type
  55.   TSessionNameProperty = class(TRxDBStringProperty)
  56.   public
  57.     procedure GetValueList(List: TStrings); override;
  58.   end;
  59.  
  60. procedure TSessionNameProperty.GetValueList(List: TStrings);
  61. begin
  62.   Sessions.GetSessionNames(List);
  63. end;
  64.  
  65. {$ENDIF WIN32}
  66.  
  67. { TDatabaseNameProperty }
  68.  
  69. type
  70.   TDatabaseNameProperty = class(TRxDBStringProperty)
  71.   public
  72.     procedure GetValueList(List: TStrings); override;
  73.   end;
  74.  
  75. procedure TDatabaseNameProperty.GetValueList(List: TStrings);
  76. {$IFDEF WIN32}
  77. var
  78.   S: TSession;
  79. {$ENDIF}
  80. begin
  81. {$IFDEF WIN32}
  82.   if (GetComponent(0) is TDBDataSet) then
  83.     (GetComponent(0) as TDBDataSet).DBSession.GetDatabaseNames(List)
  84.   else if (GetComponent(0) is TSQLScript) then begin
  85.     S := Sessions.FindSession((GetComponent(0) as TSQLScript).SessionName);
  86.     if S = nil then S := Session;
  87.     S.GetDatabaseNames(List);
  88.   end;
  89. {$ELSE}
  90.   Session.GetDatabaseNames(List);
  91. {$ENDIF}
  92. end;
  93.  
  94. { TTableNameProperty }
  95. { For TFieldList, TIndexList components }
  96.  
  97. type
  98.   TTableNameProperty = class(TRxDBStringProperty)
  99.   public
  100.     procedure GetValueList(List: TStrings); override;
  101.   end;
  102.  
  103. procedure TTableNameProperty.GetValueList(List: TStrings);
  104. begin
  105. {$IFDEF WIN32}
  106.   (GetComponent(0) as TCustomTableItems).DBSession.GetTableNames((GetComponent(0)
  107.     as TCustomTableItems).DatabaseName, '', True, False, List);
  108. {$ELSE}
  109.   Session.GetTableNames((GetComponent(0) as TCustomTableItems).DatabaseName,
  110.     '', True, False, List);
  111. {$ENDIF WIN32}
  112. end;
  113.  
  114. {$IFNDEF RX_D4}
  115.  
  116. {$IFNDEF VER90}
  117.  {$IFNDEF VER93}
  118. function EditQueryParams(DataSet: TDataSet; List: TParams): Boolean;
  119. begin
  120.   Result := QBndDlg.EditQueryParams(DataSet, List, hcDQuery);
  121. end;
  122.  {$ENDIF}
  123. {$ENDIF}
  124.  
  125. { TRxParamsProperty }
  126.  
  127. type
  128.   TRxParamsProperty = class(TPropertyEditor)
  129.   public
  130.     procedure Edit; override;
  131.     function GetValue: string; override;
  132.     function GetAttributes: TPropertyAttributes; override;
  133.   end;
  134.  
  135. function TRxParamsProperty.GetValue: string;
  136. var
  137.   Params: TParams;
  138. begin
  139.   Params := TParams(Pointer(GetOrdValue));
  140.   if Params.Count > 0 then
  141. {$IFDEF WIN32}
  142.     Result := Format('(%s)', [GetPropInfo.Name])
  143. {$ELSE}
  144.     Result := Format('(%s)', [GetPropInfo^.Name])
  145. {$ENDIF}
  146.   else
  147.     Result := ResStr(srNone);
  148. end;
  149.  
  150. function TRxParamsProperty.GetAttributes: TPropertyAttributes;
  151. begin
  152.   Result := [paMultiSelect, paDialog];
  153. end;
  154.  
  155. procedure TRxParamsProperty.Edit;
  156. var
  157.   List, Params: TParams;
  158.   Query: TDataSet;
  159.   QueryCreated: Boolean;
  160.   I: Integer;
  161. begin
  162.   QueryCreated := False;
  163.   if GetComponent(0) is TDataSet then
  164.     Query := GetComponent(0) as TDataSet
  165.   else begin
  166.     Query := TQuery.Create(GetComponent(0) as TComponent);
  167.     QueryCreated := True;
  168.   end;
  169.   try
  170.     Params := TParams(GetOrdProp(GetComponent(0), GetPropInfo));
  171.     if QueryCreated then TQuery(Query).Params := Params;
  172.     List := TParams.Create;
  173.     try
  174.       List.Assign(Params);
  175.       if EditQueryParams(Query, List) {$IFDEF WIN32} and not
  176.         List.IsEqual(Params) {$ENDIF} then
  177.       begin
  178. {$IFDEF WIN32}
  179.         Modified;
  180. {$ELSE}
  181.         if Designer <> nil then Designer.Modified;
  182. {$ENDIF}
  183.         Query.Close;
  184.         for I := 0 to PropCount - 1 do begin
  185.           Params := TParams(GetOrdProp(GetComponent(I),
  186.             TypInfo.GetPropInfo(GetComponent(I).ClassInfo,
  187. {$IFDEF WIN32}
  188.             GetPropInfo.Name)));
  189. {$ELSE}
  190.             GetPropInfo^.Name)));
  191. {$ENDIF}
  192.           Params.AssignValues(List);
  193.         end;
  194.       end;
  195.     finally
  196.       List.Free;
  197.     end;
  198.   finally
  199.     if QueryCreated then Query.Free;
  200.   end;
  201. end;
  202.  
  203. {$ENDIF RX_D4}
  204.  
  205. { TUserTableNameProperty }
  206. { For TDBSecurity component }
  207.  
  208. type
  209.   TUserTableNameProperty = class(TRxDBStringProperty)
  210.     procedure GetValueList(List: TStrings); override;
  211.   end;
  212.  
  213. procedure TUserTableNameProperty.GetValueList(List: TStrings);
  214. var
  215.   Security: TDBSecurity;
  216. begin
  217.   Security := GetComponent(0) as TDBSecurity;
  218.   if Security.Database <> nil then begin
  219. {$IFDEF WIN32}
  220.     Security.Database.Session.GetTableNames(Security.Database.DatabaseName,
  221.       '*.*', True, False, List);
  222. {$ELSE}
  223.     Session.GetTableNames(Security.Database.DatabaseName, '*.*',
  224.       True, False, List);
  225. {$ENDIF}
  226.   end;
  227. end;
  228.  
  229. { TLoginNameFieldProperty }
  230. { For TDBSecurity component }
  231.  
  232. type
  233.   TLoginNameFieldProperty = class(TRxDBStringProperty)
  234.     procedure GetValueList(List: TStrings); override;
  235.   end;
  236.  
  237. procedure TLoginNameFieldProperty.GetValueList(List: TStrings);
  238. var
  239.   Security: TDBSecurity;
  240.   Table: TTable;
  241. begin
  242.   Security := GetComponent(0) as TDBSecurity;
  243.   if (Security.Database <> nil) and (Security.UsersTableName <> '') then begin
  244.     Table := TTable.Create(Security);
  245.     try
  246.       Table.DatabaseName := Security.Database.DatabaseName;
  247.       Table.TableName := Security.UsersTableName;
  248.       Table.GetFieldNames(List);
  249.     finally
  250.       Table.Free;
  251.     end;
  252.   end;
  253. end;
  254.  
  255. {$IFDEF DCS}
  256.  
  257. { TMemoryTableEditor }
  258.  
  259. type
  260.   TMemoryTableEditor = class(TMemDataSetEditor)
  261.   protected
  262.     function CopyStructure(Source, Dest: TDataSet): Boolean; override;
  263.   end;
  264.  
  265. function TMemoryTableEditor.CopyStructure(Source, Dest: TDataSet): Boolean;
  266. begin
  267.   Result := Dest is TMemoryTable;
  268.   if Result then
  269.     TMemoryTable(Dest).CopyStructure(Source);
  270. end;
  271.  
  272. {$ENDIF DCS}
  273.  
  274. { Designer registration }
  275.  
  276. procedure Register;
  277. begin
  278. {$IFDEF RX_D4}
  279.   { Database Components are excluded from the STD SKU }
  280.   if GDAL = LongWord(-16) then Exit;
  281. {$ENDIF}
  282.  
  283. { Data aware components and controls }
  284.   RegisterComponents(LoadStr(srRXDBAware), [TRxQuery, TSQLScript,
  285.     TMemoryTable, TQBEQuery, TDBIndexCombo, TDBProgress, 
  286.     TDBSecurity]);
  287. {$IFDEF RX_MIDAS}
  288. { MIDAS components }
  289.   RegisterComponents(LoadStr(srRXDBAware), [TRxRemoteLogin]);
  290.   RegisterNonActiveX([TRxRemoteLogin], axrComponentOnly);
  291. {$ENDIF}
  292. { Database lists }
  293.   RegisterComponents(LoadStr(srRXDBAware), [TBDEItems, TDatabaseItems,
  294.     TTableItems]);
  295. {$IFNDEF CBUILDER}
  296.  {$IFDEF USE_OLD_DBLISTS}
  297.   RegisterComponents(LoadStr(srRXDBAware), [TDatabaseList, TLangDrivList,
  298.     TTableList, TStoredProcList, TFieldList, TIndexList]);
  299.  {$ENDIF USE_OLD_DBLISTS}
  300. {$ENDIF CBUILDER}
  301.  
  302. {$IFDEF RX_D3}
  303.   RegisterNonActiveX([TRxQuery, TSQLScript, TMemoryTable, TQBEQuery,
  304.      TDBIndexCombo, TDBProgress, TDBSecurity, TBDEItems,
  305.     TDatabaseItems, TTableItems], axrComponentOnly);
  306. {$ENDIF RX_D3}
  307.  
  308. { Property and component editors for data aware controls }
  309.  
  310.   RegisterPropertyEditor(TypeInfo(TFileName), TCustomTableItems, 'TableName',
  311.     TTableNameProperty);
  312.   RegisterPropertyEditor(TypeInfo(TFileName), TDBSecurity,
  313.     'UsersTableName', TUserTableNameProperty);
  314.   RegisterPropertyEditor(TypeInfo(string), TDBSecurity,
  315.     'LoginNameField', TLoginNameFieldProperty);
  316.  
  317. {$IFDEF DCS}
  318.   RegisterComponentEditor(TMemoryTable, TMemoryTableEditor);
  319. {$ENDIF}
  320.  
  321. {$IFNDEF RX_D4}
  322.   RegisterPropertyEditor(TypeInfo(TParams), TQBEQuery, 'Params',
  323.     TRxParamsProperty);
  324.   RegisterPropertyEditor(TypeInfo(TParams), TRxQuery, 'Macros',
  325.     TRxParamsProperty);
  326.   RegisterPropertyEditor(TypeInfo(TParams), TSQLScript, 'Params',
  327.     TRxParamsProperty);
  328. {$ENDIF}
  329.  
  330.   RegisterPropertyEditor(TypeInfo(string), TSQLScript, 'DatabaseName',
  331.     TDatabaseNameProperty);
  332. {$IFDEF WIN32}
  333.   RegisterPropertyEditor(TypeInfo(string), TCustomBDEItems, 'SessionName',
  334.     TSessionNameProperty);
  335.   RegisterPropertyEditor(TypeInfo(string), TSQLScript, 'SessionName',
  336.     TSessionNameProperty);
  337.   RegisterPropertyEditor(TypeInfo(string), TDBProgress, 'SessionName',
  338.     TSessionNameProperty);
  339. {$ELSE}
  340.   DbErrorIntercept;
  341. {$ENDIF WIN32}
  342.  
  343. end;
  344.  
  345. end.