Mega Code Archive

 
Categories / Delphi / ADO Database
 

Some BDE API calls

Title: Some BDE API calls Question: How to use BDE functions. Some examples. Answer: function dgGetAliasPath(var Session: TSession; { Returns the path for the alias passed in AliasName. This must be an alias that points to a subdirectory. This function does not verify that the alias points to a subdirectory. } const AliasName: string): string; var AliasParams: TStringList; begin Result := ''; AliasParams := TStringList.Create; with Session do try GetAliasParams(AliasName, AliasParams); Result := UpperCase(AliasParams.Values['PATH'])+'\'; finally AliasParams.Free; end; end; function dgPackParadoxTable(Tbl: TTable; Db: TDatabase):DBIResult; { Packs a Paradox table by calling the BDE DbiDoRestructure function. The TTable passed as the first parameter must be closed. The TDatabase passed as the second parameter must be connected. } var TblDesc: CRTblDesc; begin Result := DBIERR_NA; FillChar(TblDesc, SizeOf(CRTblDesc), 0); StrPCopy(TblDesc.szTblName, Tbl.TableName); TblDesc.bPack := True; Result := DbiDoRestructure(Db.Handle, 1, @TblDesc, nil, nil, nil, False); end; function dgPackDbaseTable(Tbl: TTable): DBIResult; { Pack a dBASE table by calling DbiPackTable. The table passed as a parameter will be opened if it isn't open. } begin Result := DBIERR_NA; if Tbl.Active = False then Tbl.Open; Result := DbiPackTable(Tbl.DBHandle, Tbl.Handle, nil, nil, True); end; function dgGetUserName: string; { Return the network username. } var UserNameBuff: array[0..255] of Char; pUserName: PChar; begin Result := ''; pUserName := @UserNameBuff; Check(DbiGetNetUserName(pUserName)); Result := StrPas(pUserName); end; procedure dgCopyTable(Database: TDatabase; SourceTblName, DestTblName: string; Overwrite: Boolean); { Copy a table to the same or different directory. Local table names can include a path, so you can copy tables from one directory to another. Server tables can be copied only within a database. Parameters: Database: TDatabase connected to source db. SourceTblName: Source table name. DestTblName: Destination table name. Overwrite: Overwrite destination if True. } var pSrcTblName, pDestTblName: DBITBLNAME; begin AnsiToNative(Database.Locale, SourceTblName, pSrcTblName, DBIMAXPATHLEN); AnsiToNative(Database.Locale, DestTblName, pDestTblName, DBIMAXPATHLEN); Check(DbiCopyTable( Database.handle, { Database handle. } Overwrite, { Overwrite destination table. } pSrcTblName, { Source table path & name. } nil, { Table type. } pDestTblName)); { Destination table path & name. } end;