Mega Code Archive

 
Categories / Delphi / Forms
 

Get infos about aliases

Title: get infos about aliases? { Here's a demo to demonstrate how to get info about aliases in Delphi. First, create a new project with a listbox and 3 labels (called ListBox1, Label1, Label2, and Label3). Then add an OnCreate event handler for the form with this code in it: } { Das folgende Beispiel zeigt, wie man Infos von Aliasen ermitteln kann. Erstelle ein neues Projekt und platziere eine Listbox und 3 Labels (ListBox1, Label1, Label2, and Label3) auf der Form. Dann Schreibe im OnCreate Ereignis folgenden Code: } procedure TForm1.FormCreate(Sender: TObject); begin { GetAliasNames Populates a string list with the names of persistent Borland Database Engine (BDE) aliases. GetAliasNames fügt die Namen der dauerhaften Aliase der Borland Database Engine (BDE) in eine Listbox. } Session.GetAliasNames(ListBox1.Items); end; { Now add an OnClick event for the Listbox: } { Schreibe nun im OnClick Ereignis der Listbox diesen Code } procedure TForm1.ListBox1Click(Sender: TObject); var tStr: array[0..100] of char; Desc: DBDesc; { The DBDesc structure describes a database, using the following fields: szName DBINAME Specifies the database alias name. szText DBINAME Descriptive text. szPhyName DBIPATH Specifies the physical name/path. szDbType DBINAME Specifies the database type. } begin if ListBox1.Items.Count = 0 then exit; StrPLCopy(tStr, ListBox1.Items.Strings[ListBox1.ItemIndex], High(tStr)); DbiGetDatabaseDesc(tStr, @Desc); with Desc do begin Label1.Caption := StrPas(Desc.szName); Label2.Caption := StrPas(Desc.szPhyName); Label3.Caption := StrPas(Desc.szDbType); Label4.Caption := StrPas(Desc.szText); end; end; // Now add the following to the 'uses' clause at the top of the unit: // Folgende Units müssen noch in die Uses-Klausel aufgenommen werden: uses {...,}DB, DBTables, DBITypes, DBIProcs; {********************************************************************} { This Examples is just another approach to get infos about aliases Using 2 component (TListBox) and only use 1 uses clause (dbTables) } uses {...}, DBTables; type TForm1 = class(TForm) ListBox1: TListBox; ListBox2: TListBox; {..} implementation {..} procedure TForm1.FormCreate(Sender: TObject); begin {Get Alias Names} Session.GetAliasNames(ListBox1.Items); end; procedure TForm1.ListBox1Click(Sender: TObject); begin ListBox2.Items.Clear; if ListBox1.Items.Count = 0 then Exit; {Get Alias Driver Names, like Standard, MsAccess, etc} ListBox2.Items.Add('DRIVER=' + Session.GetAliasDriverName(ListBox1.Items.Strings [ListBox1.ItemIndex])); {Get Alias Parameters and add it parameters into listbox2} Session.GetAliasParams(ListBox1.Items.Strings[ListBox1.ItemIndex], ListBox2.Items); end; end.