home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 February / Chip_2003-02_cd1.bin / zkuste / delphi / kompon / d34567 / KADAO77.ZIP / DaoAddOns.pas < prev    next >
Pascal/Delphi Source File  |  2002-08-15  |  3KB  |  98 lines

  1. unit DaoAddOns;
  2.  
  3. {$I KADaoCommonDirectives.pas}
  4. interface
  5.  Uses Windows, Classes, SysUtils, ComObj, ActiveX{$IFDEF D6UP}, Variants {$ENDIF};
  6.  
  7. Function CopyTableStructure(Database : OleVariant; OriginalTable, NewTable : String):Boolean;
  8. Function CopyTable(Database : OleVariant; OriginalTable, NewTable : String):Boolean;
  9. Function GetAllDaoEngines(const LicenseString: String):TStringList;
  10.  
  11.  
  12. implementation
  13. Uses DaoApi;
  14.  
  15. Function CopyTableStructure(Database : OleVariant; OriginalTable, NewTable : String):Boolean;
  16. Var
  17.  SQL : String;
  18. Begin
  19.   Result := False;
  20.   SQL := Format('SELECT * INTO [%s] FROM [%s] WHERE 1=2;',[NewTable,OriginalTable]);
  21.   Try
  22.    Database.Execute(SQL,DaoApi.dbFailOnError);
  23.   Except
  24.    Exit;
  25.   End;
  26.   Result := True;
  27. End;
  28.  
  29. Function CopyTable(Database : OleVariant; OriginalTable, NewTable : String):Boolean;
  30. Var
  31.  SQL : String;
  32. Begin
  33.   Result := False;
  34.   SQL := Format('INSERT INTO [%s] SELECT * FROM [%s];',[NewTable,OriginalTable]);
  35.   Try
  36.    Database.Execute(SQL,DaoApi.dbFailOnError);
  37.   Except
  38.    Exit;                                                                
  39.   End;
  40.   Result := True;
  41. End;                                                              
  42.  
  43. Function CreateOleDBEngineObject(const ClassName, RuntimeLicense: string): IDispatch;
  44. Const
  45.   DBEngine_TGUID: TGUID = '{00000021-0000-0010-8000-00AA006D2EA4}';
  46. Var
  47.   LicenseClass       : IClassFactory2;
  48.   DWReserved         : DWORD;
  49.   LicenseString      : Widestring;
  50.   ClassID : TGUID;                                  
  51. Begin                                                       
  52.   ClassID := ProgIDToClassID(ClassName);
  53.   //****************************************************************************
  54.   LicenseClass := Nil;
  55.   OleCheck(CoGetClassObject(ClassID,CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, nil, IClassFactory2, LicenseClass));
  56.   if Assigned(LicenseClass) Then
  57.      Begin                                                                                         
  58.        SetLength(LicenseString,2000);
  59.        DWReserved:=0;
  60.        if RuntimeLicense <> '' Then
  61.           LicenseString := RuntimeLicense
  62.        Else
  63.           LicenseClass.RequestLicKey(DWReserved,LicenseString);
  64.        OleCheck(LicenseClass.CreateInstanceLic (nil, nil, DBEngine_TGUID, LicenseString, Result));
  65.      End;
  66.   //****************************************************************************
  67. End;
  68.  
  69. Function  GetAllDaoEngines(const LicenseString: String):TStringList;
  70. Var
  71.  TempDBEngine      : OleVariant;
  72. Begin
  73.   Result := TStringList.Create;
  74.   Result.Sorted:=True;
  75.   Result.Duplicates:=dupIgnore;
  76.   Try
  77.    TempDBEngine               := CreateOleDBEngineObject('DAO.PrivateDBEngine.35',LicenseString);
  78.    Result.Add('3.5');
  79.    VarClear(TempDBEngine);
  80.   Except
  81.   End;
  82.  
  83.   Try
  84.    TempDBEngine               := CreateOleDBEngineObject('DAO.PrivateDBEngine.36',LicenseString);
  85.    Result.Add('3.6');
  86.    VarClear(TempDBEngine);
  87.   Except
  88.   End;
  89.   Try
  90.    TempDBEngine               := CreateOleDBEngineObject('DAO.PrivateDBEngine',LicenseString);
  91.    Result.Add(TempDBEngine.Version);
  92.    VarClear(TempDBEngine);
  93.   Except
  94.   End;
  95. End;
  96.  
  97. end.
  98.