More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Wednesday, 10 November 2010 12:28:45 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 522

The following code checks whether a database alias exists in BDE. If exists, it updates the alias parameters. Otherwise it creates alias. The Paradox database driver is used in this example.
Code:
var
  AliasList: TStringList;
  lDatabase: TDatabase;
  lSession :TSession;
begin
  lSession := TSession.Create(Application);
         With lSession do
         begin
            AutoSessionName := true;
            Active := true;
         end;

  lDatabase := TDatabase.Create(nil);
  AliasList := TStringList.Create;

  //If alias doesn't exist, add alias
  if (lSession.IsAlias('myDb') = false) then
  begin
      try
         with AliasList do
         begin
            Add(format('PATH=%s', [dbPath]));
         end;
         lSession.AddAlias('myDb', 'PARADOX', AliasList);
      finally
         AliasList.Free;
      end;
  end
  else
        //If alias exists, change the alias with a different path
        //lSession.GetAliasParams('myDb', AliasList);
        AliasList.Clear;
        AliasList.Add(format('PATH=%s', [dbPath]));
        lSession.ModifyAlias('myDb', AliasList);
        Session.SaveConfigFile;

      with lDatabase do
      begin
         //Configure database
         LoginPrompt := false;
         SessionName := lSession.SessionName;
         AliasName := 'myDb';
         DatabaseName := 'myDatabase';
         Connected := true;
      end;

Edited by user Wednesday, 10 November 2010 12:30:05 PM(UTC)  | Reason: Not specified

Sponsor
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.