15th chapter-Application and programming of data access parts (i) (2)

Source: Internet
Author: User

15.2.3 tsession Parts Application Examples

Example 15.1: We create an application to get the name of the database that the current application can connect to and get the names of all the database tables in any of the databases by invoking the TSession method.

Get information about the database through the tsession part

The form mainly uses two list boxes, where the list box Databaselistbox is used to display the name of the database, and the list box Tablelistbox is used to display the name of the table in the database. After the program is run, the name of the database appears in the Databaselistbox list box, and when the user clicks the name of the database in the Databaselistbox list box, the name of the database table for the database is displayed in the Tablelistbox list box. The relevant program code is as follows:

Program Listing 15.1

Unit unit31;

Interface

Uses

Sysutils, Windows, Messages, Classes, Graphics, Controls,

Forms, Dialogs, Stdctrls, DB, Dbtables, Buttons, Comctrls, TABNOTBK;

Type

Tqueryform = Class (Tform)

BITBTN1:TBITBTN;

Datasource1:tdatasource;

table1:ttable;

Groupbox1:tgroupbox;

Checkbox1:tcheckbox;

Checkbox2:tcheckbox;

Pagecontrol1:tpagecontrol;

Tabsheet1:ttabsheet;

Label1:tlabel;

Label2:tlabel;

Label3:tlabel;

Listbox1:tlistbox;

Listbox2:tlistbox;

Listbox3:tlistbox;

Tabsheet2:ttabsheet;

Memo1:tmemo;

Procedure Formcreate (Sender:tobject);

Procedure Listbox1click (Sender:tobject);

Procedure Listbox2click (Sender:tobject);

End

Var

Queryform:tqueryform;

Implementation

{$R *. DFM}

Uses rsltform;

Procedure Tqueryform.formcreate (Sender:tobject);

Begin

Screen.cursor: = Crhourglass;

{Populate the alias list}

With ListBox1 do

Begin

Items.clear;

Session.getaliasnames (Items);

End

{Make sure there are aliases defined}

Screen.cursor: = Crdefault;

If ListBox1.Items.Count < 1 Then

Messagedlg (' There are no database aliases currently defined. You ' +

' Need at least-one alias to-use this demonstration ',

Mterror, [Mbok], 0);

End

Procedure Tqueryform.listbox1click (Sender:tobject);

Var

strvalue:string; {holds the alias selected by the user}

Bislocal:boolean; {Indicates whether or not a alias

Slparams:tstringlist; {holds the parameters of the selected alias}

Icounter:integer; {An integer counter variable for loops}

Begin

{Determine the alias name selected by the user}

With ListBox1 do

strvalue: = Items.strings[itemindex];

{Get the names of the "the" tables in the "alias" them in the

Appropriate list box, making sure the user ' s choices are reflected

In the list. }

ListBox2.Items.Clear;

Session.gettablenames (strvalue, {alias to enumerate}

', {pattern to match}

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.