Example of creating a BDE alias using Delphi code

Source: Internet
Author: User
Tags paradox database

In actual applications, the program may need to automatically create BDE aliases.

Create MSSQL and Paradox database alias

// Unit code

Unit unit11; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, dbtables; Type tform11 = Class (tform) mmo1: tmemo; btn1: tbutton; Procedure btn1click (Sender: tobject); Private {private Declarations} public {public declarations} end; var form11: tform11; implementation {$ R *. DFM} procedure tform11.btn1click (Sender: tobject); var lst: tstringlist; Procedure dropalias (const aliasname: string); begin if lst. indexof (aliasname) <>-1 then begin session. deletealias (aliasname); Session. saveconfigfile; mmo1.lines. add ('drop alias ['+ aliasname +'] '); end; Procedure addparadox (const aliasname: string); begin dropalias (aliasname); try session. addstandardalias (aliasname, 'c: \ instance1', 'paradox '); Session. saveconfigfile; // Save the BDE configuration file mmo1.lines. add ('Save alias ['+ aliasname +'] '); does t on E: exception do application. messageBox (pchar (E. message), 'error', mb_iconerror + mb_ OK); end; Procedure addmssql (const aliasname: string); const serverstr = '. '; // server address (local) var aliaslst: tstringlist; begin dropalias (aliasname); try session. addstandardalias (aliasname, '', 'mssql'); Session. saveconfigfile; aliaslst: = tstringlist. create; try with aliaslst do begin add ('user name = Sa'); add ('sqlqrymode = Server'); add ('server name = '+ serverstr ); add ('database name = test'); end; Session. modifyalias (aliasname, aliaslst); Session. saveconfigfile; mmo1.lines. add ('Save alias ['+ aliasname +'] '); finally aliaslst. free; end; begin t on E: exception do application. messageBox (pchar (E. message), 'error', mb_iconerror + mb_ OK); end; begin lst: = tstringlist. create; try session. getaliasnames (LST); // get the alias list // paradox addparadox ('newparadox '); // mssq addmssql ('newsql'); finally lst. free; end.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.