Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to get a list of all BDE alias (native and ODBC)just like Database Explorer do?

Posted on 1998-05-15
2
717 Views
Last Modified: 2010-07-27
How can I get the alias list from the BDE using Delphi 3.0.
I need to create database connections at run-time and I need to be able to get the alias
and the params of each driver type just like Delphi do when you config
a TDatabase object from the object inspector (the function of the window that
appears when you double click over a TDatabase component)

0
Comment
Question by:Mak042298
2 Comments
 

Expert Comment

by:chrb
ID: 1345950
Hi,

There is an article on how to get all the alias names on Delphi32.com (www.delphi32.com). Look under D32 Magazine.

With kind regards
 Christian Bøhn
0
 
LVL 2

Accepted Solution

by:
Waldek earned 100 total points
ID: 1345951
Here is a unit . In this unit exist method GetAliasNames

//  Filename: AliasEd.pas
//  Version : 01.02
//  Date    : 29/03/97
//  Author  : Glenn Davies
//
//  Description:
//    BDE alias management component.
//
//  History:
//    14/06/97 - V01.03
//      Revised for compatibility with Delphi 3.
//    29/03/97 - V01.02
//      Added GetDriverList and GetDriverParams methods for completeness.
//    30/05/96 - V01.01
//      Now uses methods and properties of Session rather than BDE functions.
//      As a result, most methods are now procedures which raise exceptions if
//      an error occurs rather than Boolean functions. Methods now accept
//      TStrings objects as parameters rather than only TStringList objects.
//    16/05/96 - V01.00
//      Initial version.

unit AliasEd;

interface

uses
  SysUtils, Classes, DBTables;

//------------------------------------------------------------------------------

type

  {TAliasEditor class declaration}

  TAliasEditor = class(TComponent)
  private
    fParams: TStringList;
    fConfigMode: TConfigMode;
    fOldConfigMode: TConfigMode;
  protected
    procedure InitBDE;
    procedure RestoreConfigMode;
    procedure SetConfigMode;
  public
    constructor Create(owner: TComponent); override;
    destructor Destroy; override;
    procedure Add(const alias, driver: String; the_params: TStrings);
    procedure Delete(const alias: String);
    function Exists(const alias: String): Boolean;
    procedure Modify(const alias: String; the_params: TStrings);
    procedure GetAliasList(the_params: TStrings);
    function GetDriver(const alias: String): String;
    procedure GetDriverParams(const driver_name: String; the_params: TStrings);
    procedure GetDriverList(the_params: TStrings);
    procedure GetParams(const alias: String; the_params: TStrings);
    function GetPath(const alias: String): String;
    function GetType(const alias: String): String;
    property Params: TStringList read fParams write fParams;
  published
    property ConfigMode: TConfigMode read fConfigMode write fConfigMode default [cfmPersistent];
  end;

//------------------------------------------------------------------------------

procedure Register;

//------------------------------------------------------------------------------

implementation

//------------------------------------------------------------------------------

{TAliasEditor class implementation}

//------------------------------------------------------------------------------

procedure TAliasEditor.InitBDE;
begin
  if not(Session.Active) then
    Session.Active := True;
end;

//------------------------------------------------------------------------------

procedure TAliasEditor.RestoreConfigMode;
begin
  Session.ConfigMode := fOldConfigMode;
end;

//------------------------------------------------------------------------------

procedure TAliasEditor.SetConfigMode;
begin
  fOldConfigMode := Session.ConfigMode;
  Session.ConfigMode := fConfigMode;
end;

//------------------------------------------------------------------------------

constructor TAliasEditor.Create(owner: TComponent);
begin
  inherited Create(owner);
  fParams := TStringList.Create;
  fConfigMode := [cfmPersistent];
end;

//------------------------------------------------------------------------------

destructor TAliasEditor.Destroy;
begin
  fParams.Free;
  inherited Destroy;
end;

//------------------------------------------------------------------------------

//  Add a new alias.

procedure TAliasEditor.Add(const alias, driver: String; the_params: TStrings);
begin
  InitBDE;
  SetConfigMode;
  try
    Session.AddAlias(alias, driver, the_params);
    Session.SaveConfigFile;
  finally
    RestoreConfigMode;
  end;
end;

//------------------------------------------------------------------------------

//  Delete an existing alias.

procedure TAliasEditor.Delete(const alias: String);
begin
  InitBDE;
  SetConfigMode;
  try
    Session.DeleteAlias(alias);
    Session.SaveConfigFile;
  finally
    RestoreConfigMode;
  end;
end;

//------------------------------------------------------------------------------

//  Check if an alias exists.

function TAliasEditor.Exists(const alias: String): Boolean;
begin
  result := False;
  InitBDE;
  SetConfigMode;
  try
    result := Session.IsAlias(alias);
  finally
    RestoreConfigMode;
  end;
end;

//------------------------------------------------------------------------------

//  Modify an existing alias.

procedure TAliasEditor.Modify(const alias: String; the_params: TStrings);
begin
  InitBDE;
  SetConfigMode;
  try
    Session.ModifyAlias(alias, the_params);
    Session.SaveConfigFile;
  finally
    RestoreConfigMode;
  end;
end;

//------------------------------------------------------------------------------

//  Get a list of available aliases.

procedure TAliasEditor.GetAliasList(the_params: TStrings);
begin
  InitBDE;
  SetConfigMode;
  try
    Session.GetAliasNames(the_params);
  finally
    RestoreConfigMode;
  end;
end;

//------------------------------------------------------------------------------

//  Get the driver name for an alias.

function TAliasEditor.GetDriver(const alias: String): String;
begin
  InitBDE;
  SetConfigMode;
  try
    result := Session.GetAliasDriverName(alias);
  finally
    RestoreConfigMode;
  end;
end;

//------------------------------------------------------------------------------

//  Get the default parameters for specified driver

procedure TAliasEditor.GetDriverParams(const driver_name: String; the_params: TStrings);
begin
  InitBDE;
  Session.GetDriverParams(driver_name,the_params);
end;

//------------------------------------------------------------------------------

//  Get a list of currently installed drivers

procedure TAliasEditor.GetDriverList(the_params: TStrings);
begin
  InitBDE;
  Session.GetDriverNames(the_params);
end;

//------------------------------------------------------------------------------

//  Get the parameters for an alias.

procedure TAliasEditor.GetParams(const alias: String; the_params: TStrings);
begin
  InitBDE;
  SetConfigMode;
  try
    Session.GetAliasParams(alias, the_params);
  finally
    RestoreConfigMode;
  end;
end;

//------------------------------------------------------------------------------

//  Get the path for an alias.

function TAliasEditor.GetPath(const alias: String): String;
var
  the_params: TStringList;
begin
  the_params := TStringList.Create;
  try
    GetParams(alias,the_params);
    result := the_params.Values['PATH'];
  finally
    the_params.Free;
  end;
end;

//------------------------------------------------------------------------------

//  Get the type of an alias.

function TAliasEditor.GetType(const alias: String): String;
var
  the_params: TStringList;
begin
  the_params := TStringList.Create;
  try
    GetParams(alias,the_params);
    result := the_params.Values['TYPE'];
  finally
    the_params.Free;
  end;
end;

//------------------------------------------------------------------------------

procedure Register;
begin
  RegisterComponents('Samples', [TAliasEditor]);
end;

//------------------------------------------------------------------------------

end.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mobile Keyboard covers the display of the TMemo 3 96
Dev Express grid collapse 2 45
Delphi: Connect to running MS Outlook 4 118
Tvertscrollbox like a whatsapp layout 5 34
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question