Создание новой MS Access базы данных
|
Приведенная ниже процедура создает пустую базу данных MS Access procedure CreateMSAccessDatabase(filename: string); var DAO: Variant; i: integer; const Engines: array[0..2] of string = ('DAO.DBEngine.36', 'DAO.DBEngine.35', 'DAO.DBEngine');
function CheckClass(OLEClassName: string): boolean; var Res: HResult; begin Result := CoCreateInstance(ProgIDToClassID(OLEClassName), nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IDispatch, Res) = S_OK; end; begin for i := 0 to 2 do if CheckClass(Engines[i]) then begin DAO := CreateOleObject(Engines[i]); DAO.Workspaces[0].CreateDatabase(filename, ';LANGID=0x0409;CP=1252;COUNTRY=0', 32); exit; end; raise Exception.Create('DAO engine could not be initialized'); end; |