프로그래밍/델파이

MDB(MS Access) 파일 생성하기

채윤아빠 2009. 3. 12. 02:15
728x90
반응형
액세스(Access) DB 파일인 MDB를 델파이에서 수동으로 생성하는 함수입니다.
{** MDB 파일을 생성한다. *}
function CreateMDB(hwndOwner:HWND; const strFileName:string):integer;
const
  ODBC_DLL    ='ODBCCP32.DLL';
  FUNC_NAME   ='SQLConfigDataSource';
var
  strSystemDir:string;
  nSize:integer;
  hLib:THandle;
  fn:TSQLConfigDataSource;
begin
  Result:=0;
  SetLength(strSystemDir, 1024);
  nSize:=GetSystemDirectory(@strSystemDir[1], 1024);
  if nSize=0 then
    Exit;
  SetLength(strSystemDir, nSize);

  strSystemDir:=strSystemDir+'\'+ODBC_DLL;
  hLib:=LoadLibrary(PChar(strSystemDir));
  if hLib=0 then
    Exit;

  fn:=GetProcAddress(hLib, FUNC_NAME);
  Result:=fn(hwndOwner, 1, LPCSTR('Microsoft Access Driver (*.mdb)'),
      LPCSTR('CREATE_DB="'+strFileName+'" General'+#0));
  FreeLibrary(hLib);
end;