IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bases de données Delphi Discussion :

Comment créer des ALIAS par programme


Sujet :

Bases de données Delphi

  1. #1
    Membre du Club
    Inscrit en
    Septembre 2006
    Messages
    98
    Détails du profil
    Informations forums :
    Inscription : Septembre 2006
    Messages : 98
    Points : 50
    Points
    50
    Par défaut Comment créer des ALIAS par programme
    Bonjour

    Comment modifier les ALIAS BDE par programme. C.a.d modifier les parametres de IDAPI32.CFG sans passer par BDEADMIN.EXE ?.

    j'ai fait des recherches sur internet et j'ai pu arriver à la solution suivante qui crée l'alias de façon dynamique mais à l'exécution du programme je constate
    que l'ALIAS n'est pas opérationnel et quand je recompile j'ai des pbms.

    CHEMINFACT : mon alias que j'ai crée avec BDEADMIN.EXE

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    procedure TForm1.Button6Click(Sender: TObject);
    var
     wchemin: string;
     AParams: TStringList;
    begin
        application.processmessages;
        AParams := TStringList.Create;
        WCHEMIN:=ExtractFilePath(Application.exename); // extraire le chemin
        if not(session.IsAlias('CHEMINFACT')) then
        begin
         AParams.add('Path =' + wchemin + EDIT3.TEXT);
         Session.AddAlias('CHEMINFACT', 'PARADOX', AParams);
         Session.SaveConfigFile;
         AParams.Free;
         showmessage('Alias correctement généré := ' + WCHEMIN+edit3.text);
        end
        else
         begin
          Session.DeleteAlias('CHEMINFACT');
          AParams.add('Path =' + wchemin + EDIT3.TEXT);
          Session.AddAlias('CHEMINFACT', 'PARADOX', AParams);
          Session.SaveConfigFile;
          AParams.Free;
          showmessage('Alias existe ... sup + création ' + WCHEMIN+edit3.text);
         end;
    end;
    J'attend votre collaboration ...... et je remercie tous ceux qui nous aident à qui je souhaite beaucoup de bonheur et de réussite.

  2. #2
    Membre actif
    Avatar de castorcharly
    Homme Profil pro
    Chef de projet
    Inscrit en
    Février 2009
    Messages
    416
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Chef de projet
    Secteur : Biens de consommation

    Informations forums :
    Inscription : Février 2009
    Messages : 416
    Points : 299
    Points
    299
    Par défaut
    Salut, je ne travaille plus sous bde depuis longtemps, mais à l'époque j'utilisais cette unité pour gérer les alias.

    Tu devrais y trouver ton bonheur...

    Pour les infos sur ces API tu as http://info.borland.com/devsupport/bde/bdeapiex/

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
     
    unit UBde;
     
    interface
     
    uses
        windows,
        dialogs,
        SysUtils,
        Db,
        DBTables,
        BDE;
     
    type TinfoAlias = ^PInfoAlias;
         PInfoAlias = record
         DriverAlias,
         PathAlias,
         NameAlias: string;
    end;
     
    function fDbiOpenDatabaseList(FindAlias: string): string;
    function GetInfoAlias(FindAlias: string; Ainfo: PinfoAlias): boolean;
    function AddStandardAliasEX(AliasName, AliasPath: string): integer;//obsolète pour compatibilité ascen
    function AddStandardAliasEX2(AliasName, AliasPath, Atype : string): integer;
    function GetBdeExists: integer;
    function InitBde: boolean;
    procedure CloseInitBde;
     
     
    implementation
     
    procedure SetSlash(var value: string);
    begin
         if value = '' then exit;
         if value[length(value)] <> '\' then value:= value + '\';
    end;
     
     
    function GetWinTemp: string;
    var
       s: array[0..MAX_PATH - 1] of Char;
    begin
         GetTempPath(sizeof(s), s);
         result:= strpas(s);
         if result <> '' then
            setslash(result);
    end;
     
     
    function StrToOem(const AnsiStr: string): string;
    begin
      SetLength(Result, Length(AnsiStr));
      if Length(Result) > 0 then
        CharToOem(PChar(AnsiStr), PChar(Result));
    end;
     
     
    function fDbiOpenDatabaseList(FindAlias: string): string;
    var
      TmpCursor: hDbiCur;
      Database: DBDesc;
      rslt: DbiResult;
      tmp: string;
      infoAlias: PinfoAlias;
    begin
         FindAlias:= uppercase(FindAlias);
         Check(DbiOpenDatabaseList(TmpCursor));
         repeat
            rslt:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @Database, nil);
            if (rslt <> DBIERR_EOF) then begin
               InfoAlias.NameAlias:= StrPas(Database.szName);
               tmp:= StrPas(Database.szPhyName);
               if tmp <> '' then
                  if tmp[length(tmp)] <> '\' then tmp:= tmp + '\';
               InfoAlias.PathAlias:= tmp;
               InfoAlias.DriverAlias:= StrPas(Database.szDbType);
               if uppercase(StrPas(Database.szName)) = FindAlias then result:= InfoAlias.PathAlias;
            end;
         until rslt <> DBIERR_NONE;
         Check(DbiCloseCursor(TmpCursor));
    end;
     
    procedure initInfo(ainfo: PinfoAlias);
    begin
         ainfo.DriverAlias:= '';
         ainfo.NameAlias:= '';
         ainfo.PathAlias:= '';
    end;
     
    function GetInfoAlias(FindAlias: string; Ainfo: PinfoAlias): boolean;
    var
      TmpCursor: hDbiCur;
      Database: DBDesc;
      rslt: DbiResult;
      tmp: string;
      infoAlias: PinfoAlias;
    begin
         result:= false;
         FindAlias:= uppercase(FindAlias);
         initInfo(Ainfo);
         Check(DbiOpenDatabaseList(TmpCursor));
         try
            repeat
                  rslt:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @Database, nil);
                  if (rslt <> DBIERR_EOF) then begin
                     InfoAlias.NameAlias:= StrPas(Database.szName);
                     tmp:= StrPas(Database.szPhyName);
                     if tmp <> '' then
                        if tmp[length(tmp)] <> '\' then tmp:= tmp + '\';
                     InfoAlias.PathAlias:= tmp;
                     InfoAlias.DriverAlias:= StrPas(Database.szDbType);
                     if uppercase(StrPas(Database.szName)) = FindAlias then begin
                        Ainfo:= InfoAlias;
                        result:= true;
                        exit;
                     end;
                  end;
            until rslt <> DBIERR_NONE;
         finally
                Check(DbiCloseCursor(TmpCursor));
         end;
    end;
     
     
     
    function AddStandardAliasEX(AliasName, AliasPath: string): integer;
    var
       info: PinfoAlias;
    begin
         //ajoute/modifie un alias de type paradox
         //Si l'alias existe il est supprimé et recréé
         //avec le nouveau path
         //********************
         //Exemple :
         //AddStandardAliasEX('test9', 'C:\BDE32\EXAMPLES\TABLES');
         //AliasPath n'est pas vérifié, ni dans la pertinence du nom, ni dans l'accèssibilité
         Check(dbiInit(nil));
         try
            try
            if GetInfoAlias(AliasName, info) then begin
               //l'alias existe donc le supprime
               result:= DbiDeleteAlias(nil,pchar(AliasName));
               if result <> DBIERR_NONE then exit;
            end;
     
            AliasPath:= 'PATH:' + AliasPath;
     
            result:= DbiAddAlias(nil, PChar(AliasName), PChar(StrToOem('PARADOX')), PChar(AliasPath), True);
            if result = DBIERR_NONE then
               //Check(DbiCfgSave(nil, nil, Bool(-1)));
               result:= DbiCfgSave(nil, nil, Bool(-1));
            {Pour mémoire....
            case result of
                 DBIERR_INVALIDPARAM: msg:= ' invalid alias name. Invalid characters include a colon (":") and backslash ("\"). szASCII, szDBASE, and szPARADOX are entered as a STANDARD alias with the respective default driver.';
                 DBIERR_NONE: msg:= '    The alias was added successfully.';
                 DBIERR_NAMENOTUNIQUE    : msg:= 'Another alias with the same name already exists (applicable only when bPersistent is TRUE).';
                 DBIERR_OBJNOTFOUND: msg:= '    One (or more) of the optional parameters passed in through pszParams was not found as a valid type in the driver section of the configuration file.';
                 DBIERR_UNKNOWNDRIVER: msg:= '    No driver name found in configuration file matching pszDriverType.';
            end;}
            except
                  result:= -1;
            end;
         finally
                Check(DbiExit);
         end;
    end;
     
     
    function AddStandardAliasEX2(AliasName, AliasPath, Atype : string): integer;
    var
       info: PinfoAlias;
    begin
         //ajoute/modifie un alias de type Atype
         //Si l'alias existe il est supprimé et recréé
         //avec le nouveau path
         //********************
         //Exemple :
         //AddStandardAliasEX2('test9', 'C:\BDE32\EXAMPLES\TABLES', 'PARADOX');
         //AliasPath n'est pas vérifié, ni dans la pertinence du nom, ni dans l'accèssibilité
         Check(dbiInit(nil));
         try
            try
            if GetInfoAlias(AliasName, info) then begin
               //l'alias existe donc le supprime
               result:= DbiDeleteAlias(nil,pchar(AliasName));
               if result <> DBIERR_NONE then exit;
            end;
     
            AliasPath:= 'PATH:' + AliasPath;
     
            result:= DbiAddAlias(nil, PChar(AliasName), PChar(StrToOem(Atype)), PChar(AliasPath), True);
            if result = DBIERR_NONE then
               //Check(DbiCfgSave(nil, nil, Bool(-1)));
               result:= DbiCfgSave(nil, nil, Bool(-1));
            {Pour mémoire....
            case result of
                 DBIERR_INVALIDPARAM: msg:= ' invalid alias name. Invalid characters include a colon (":") and backslash ("\"). szASCII, szDBASE, and szPARADOX are entered as a STANDARD alias with the respective default driver.';
                 DBIERR_NONE: msg:= '    The alias was added successfully.';
                 DBIERR_NAMENOTUNIQUE    : msg:= 'Another alias with the same name already exists (applicable only when bPersistent is TRUE).';
                 DBIERR_OBJNOTFOUND: msg:= '    One (or more) of the optional parameters passed in through pszParams was not found as a valid type in the driver section of the configuration file.';
                 DBIERR_UNKNOWNDRIVER: msg:= '    No driver name found in configuration file matching pszDriverType.';
            end;}
            except
                  result:= -1;
            end;
         finally
                Check(DbiExit);
         end;
    end;
     
     
    function GetBdeExists: integer;
    begin
         //à voir pour NT - voir initBDE
         try
            result:= dbiInit(nil);
            if result  = DBIERR_NONE then begin
               DbiExit;
            end else
                raise Exception.create('');
         except
               result:= -1;
         end;
    end;
     
    function InitBde: boolean;
    var
       flag: integer;
    begin
         Flag:= -1;
         try
            //if Win32Platform = VER_PLATFORM_WIN32_NT then begin
               try
                  session.PrivateDir:= GetWinTemp;
               except
     
               end;
               session.open;
               if session.active then
                  Flag:= DBIERR_NONE;
            //end else Flag:= dbiInit(nil);
            result:=  (Flag = DBIERR_NONE);
         except
               result:= false;
         end;
    end;
     
    procedure CloseInitBde;
    begin
         try
            //if Win32Platform = VER_PLATFORM_WIN32_NT then begin
               if session.active then
                  session.close;
            //end else DbiExit;
         except
         end;
    end;
     
     
     
     
    end.
    “La perfection est atteinte, non pas lorsqu'il n'y a plus rien à ajouter, mais lorsqu'il n'y a plus rien à retirer.” Antoine de Saint-Exupéry.

    D1..D7-2005,2006-Xe2 Ent-XE7 archi-MsSql 2005..2008 & R2, FB 1.5..2.5.x.x -Win10,Win7/64-Xp-
    _____________________________________________________

Discussions similaires

  1. [WD-2003] Comment créer des listings par Publipostage
    Par lpz34 dans le forum Word
    Réponses: 5
    Dernier message: 12/12/2012, 13h37
  2. Comment créer des alias pour le terminal en python ?
    Par boubou_cs dans le forum Général Python
    Réponses: 2
    Dernier message: 11/11/2007, 22h15
  3. Comment créer plusieurs TEdit par programmation?
    Par rebelor dans le forum Delphi
    Réponses: 2
    Dernier message: 02/06/2007, 17h30
  4. Réponses: 2
    Dernier message: 07/08/2006, 16h43
  5. Comment gérer des services par programmation avec Delphi ?
    Par isachat666 dans le forum API, COM et SDKs
    Réponses: 4
    Dernier message: 18/12/2005, 18h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo