Mega Code Archive

 
Categories / Delphi / ADO Database
 

Search and Create a new Alias with BDE calls

Title: Search and Create a new Alias with BDE calls. Question: Search and Create a new Alias with BDE calls. Answer: To create a temporary alias has been topic of other article similar ( http://www.delphi3000.com/article.asp?id=913 ) of Dmitri Papichev, but the difference of the previous, that here I make direct calls to the BDE and I seek an equal alias before creating one new, therefore maybe interest to you. 1. Declare BDE, Dbtables in USES section. 2. This set of sentences can be put on the part of initialization of the code of the form or maybe of a DataModule. Var AliasFound: Boolean; TmpCursor: hDBICur; Rslt: DBIResult; Database: DBDesc; Begin Check(DbiInit(nil)); try Check(DbiOpenDatabaseList(TmpCursor)); AliasFound := False; repeat {Get a DBDesc record for the next alias} rslt:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @Database, nil); if (rslt DBIERR_EOF) then if StrPas(Database.szName) = 'MyAlias' then begin {The alias MyAlias already exists} AliasFound := True; Break end; until rslt DBIERR_NONE; Check(DbiCloseCursor(TmpCursor)); if not AliasFound then {If the alias was not found, add it to IDAPI.CFG} Check(DbiAddAlias(nil,PChar('MyAlias'),nil, PChar('PATH:'+ExtractFilePath(Application.ExeName)),True)) finally DbiExit; end; end; Regards.