318
Borland/! Builderv разработка приложений баз данных Базовые принципы и рекомендации для проектирования реляционных баз данных Варианты подключения к базам данных различных типов при помощи механизмов BDE, InterBase Express, ADO Express (dbGo) и dbExpress Максимальное использование возможностей компонентов-наборов данных (таблиц, запросов) Возможности управления сеансами связи и сессиями Приемы использования элементов управления и визуализации данных Описание языков запросов локального SQL и SQL стандарта ANSI-92 Стандартные и нестандартные приемы использования однонаправленных наборов данных из набора dbExpress Клиентские наборы данных и методы их использования с различными механизмами доступа к БД Портфельная модель данных и файловая модель MyBase Разработка отчетных и аналитических форм при помощи компонентов из наборов Quick Report и Decision Cube Большое количество примеров, иллюстрирующих описанные концепции

Borland C Builder 6

Embed Size (px)

DESCRIPTION

book

Citation preview

  • Borland/!Builderv

    BDE, InterBase Express, ADO Express (dbGo) dbExpress -

    (, )

    SQL SQL ANSI-92

    dbExpress

    MyBase

    Quick Report Decision Cube ,

  • 32.973.2 681.3.06(075)

    -68

    ..

    -68 Borland C++ Builder 6. .: , 2003 320 .

    ISBN 5-93772-094-6

    ,

    Borland C++ Bulder 6 ,

    , - .

    Paradox Interbase SQL .

    . , -

    . , ^

    . :

    BDE , . BDE, - SQL. Interbase SQL, SQL-92. - dbExpress, MyBase Briefcase. , , Quick Report Decision Cube.

    .

    32.973.2

    .

    -

    .

    -

    .

    , , , -

    . ,

    , -

    , .

    ISBN 5-93772-094-6 .., 2003 , 2003 77.99.6.953..438.2.9. 04.02.1999

  • 7

    1. C++ Builder 6 10

    12 12 14

    SQL Explorer 20 21 24

    Database Desktop 26 26

    28

    2. 29 .. 30 34

    35 36 Items 37 40 (Fields) 47 50 60 66 67 70 TDataSource 72

    TField 75, TField 78 . 82 (Calculated Fields) 85

    "

  • Borland C++ Builder 6.

    (Lookup Fields) 8i 9 9J 10(

    102

    3. () 103

    101

    TDatabase 10 TDatabase 106 BDE 10S 111 TDatabase 113

    TSession 114 TSession 115 Paradox dBASE.... 117 119 121

    128 128, 130 ( TDBChart) 131 TDBCtrlGrid 135 ( TDBGrid) 136 Columns. TColumn 136 144 149 OnTitleClick 149

    OnDrawColumnCell 153 TQuery 159

    SQL 159 160

    .' 160 760 161

  • 5

    (DML) 161 (Select) 161

    Select 161 From 762 Where 765 Group By. 768 Having 768 Order By 769

    (Delete) 169 (Insert) 169 (Update) 170 (Union) 170 171 SQL 171 (DDL) 173 (Create Table) 173 (Alter Table) 175 (Drop Table) 175 (Create Index) 175 (Drop Index) 176

    SQL TQuery. (SQL Builder) 176

    RequestLive 179 180 182

    TUpdateSQL 182 TBatchMove 189 192 193

    4. - 195 Interbase 196

    Interbase (IBConsole) 197 ISQL 202

    Interbase 204 , Interbase 204 SQL 205 206

  • Borland C++ Builder 6.

    (Domains) 209 211 216

    (Generators), (Triggers) (Stored Procedures) 277

    (Views) 226 (Exceptions) 229 230

    232 233 dbExpress 234 IBExpress 237 dbGo (ADO) 240 dbExpress 245 TSQLTable 246 TSQLQuery, TSQLStoredProc TSQLDataSet 260 TSQLCIientDataSet 263 TSQLMonitor 270

    273

    5. 275 QuickReport 275

    276 279 TQuickRep 282 291 Quick Report 296

    Decision Cube 297 302

    304

  • , ,

    , -

    . , , Oracle, ,

    (Paradox, dBASE .). -

    -

    .

    -

    .

    . -

    .

    ,

    , .

    , , .

    -

    Borland C++ Builder. ,

    BDE, C++ Builder . 6. , Borland C++ Builder 6 - . dbExpress SQL (DB2, Oracle, Interbase .). ( ) dbExpress - , - (CLX).

    C++ Builder -. BDE dbExpress, IB Express ADO Express ( dbGo). IB Express - Interbase, , . dbGo, Microsoft OLE DB, , .-, MS Access MS SQLServer ( , Microsoft).

    , BDE ( , -), ,

    ( ), . (Paradox, dBASE). - Interbase - dbExpress.

  • Borland C++ Builder 6.

    .

    , , .

    ., , ) , ,

    .

    ( ). BorlanC++ Builder , , ,

    . SQL Explorer, Database Desktop. .

    BDE. TDataSet < . , ,

    , , .

    , -

    .

    TDataSource TField, , .

    Master/Detail , - , .

    BDE - . , -

    TDatabase TSession. - , Data Controls. - TDBGrid (), . SQL, - (Paradox, dBASE, Foxpro ).

    TDataSet TQuery. .

    TUpdateSQL TBatchMove, . , -

    . Interbase. IBConsole Interactive SQL. , IBConsole Interbase, , -

    Interbase. Interactive SQL, SQL .

    Interbase. , - Interbase, SQL Interbase, - Interbase, . ,

    - :

    dbExpress, IBExpress dbGo (ADO) Interbase, - dbExpress, ,

  • MyBase. - TSQLMonitor.

    , -

    . -

    Quick Report Decision Cube. , .

    , . !

  • C++Builder

    SQL Explorer Database Desktop

    , ,

    C++, , -

    . -

    , ,

    C/C++. . -

    , ,

    - .

    C/C++ C++ Builder Borland. - Borland (BorlandDatabase Engine, , , BDE). BDE DLL,

    . BDE (Paradox, dB-ASE, ) SQL (Oracle, DB2, Informix, Interbase, MS SQLServer .). ODBC (Open Database Connectivity), , Access, Excel, FoxPro, Btrieve .

    ,

    .

    Borland C++ Builder . C++ Builder , , , -

  • 1. C++ Builder 6

    . -

    , , -

    . C++ Builder . BDE :

    G dbExpress, - SQL.

    Q ADOExpress , ADO. , Microsoft, OLE DB.

    G IBExpress , Interbase Interbase, - BDE.

    , -

    ,

    . ,

    , , -

    Windows . ( , , ..) QuickReport (QReport) Decision Cube.

    () C++ Builder 6 ( - MIDAS), ( 2, Business-To-Business, - Web Services), .

    -

    ( ) ,

    , -

    ,

    . ,

    ,

    ,

    , , ,

    ,

    .

    , -

    Borland C++ Builder 6. -

    , . -

    , , SQL Explorer DatabaseDesktop. , , .

    , -

    , .

  • I 2 Borland C++ Builder 6.

    :

    Borland C++ Builder 6 ! , .

    , ; , .

    ( ,

    , ! , , . , / ,

    , , ,

    , , .

    , ,

    -

    , . ,

    , ,

    .

    , . ,

    .

    (Database Application) , - ,

    . ,

    () , , . :

    ,

    .

    ,

    (, , ), . , () (Data Model). -

    . ,

    .

    , -

    . .

    .

    , , -

    . ,

    .

    , .

    , , -

  • 1. C++ Builder

    , . -

    (, ..), , , ,

    , .

    , OLE DB, ADO, - .

    . -

    ( !), - , -

    . .

    Q . ( ) . () .

    (, ) . , ,

    , . ,

    ,

    . -

    dBASE, FoxPro, Paradox. - , , -

    . , , -

    . (.. , ) . , -

    , . , -

    . - -

    .

    Microsoft Access.Q - , -

    , ,

    . - -

    . -

    ,

    . -

    , (-, ).

    - ,

    .

    ( - ), (- - ),

  • 14 Borland C++ Builder6.

    .

    SQL-, SQL-;. SQL-; , , Interbase, Oracle, DB2, Sybase, Informix, MS SQL Serv< , .

    Q . (multi-tiered) - . nepcnei .

    .

    , cej . ,

    .

    ,

    .

    .

    , , ,

    , . ! ,

    ,

    . ] ( , ) .

    .

    , . {, , , i . , , ?, -

    .

    , ,

    .

    . , ,

    , - (). .

    .

    - , -

    . -

    , - ,

    , -

    . , -

    , , , -

    , -

    . ,

    ,

  • 1. C++ Builder 6 15

    ,

    .

    ,

    . -

    , . ,

    ,

    . , .

    , -

    , , .

    ,

    .

    Q . , , .

    , -

    , , -

    . ,

    ,

    . ,

    -

    .

    .

    , ,

    . : .

    .

    , ,

    ,

    1-2 , . , ,

    .

    . , -

    , .

    , ,

    . . -

    , -.

    Q , -.

    , (-, ), . , -

    (), . ,

    (), .Q , .

    , -

    ,

  • 10 Borland C++ Builder 6.

    . ,

    , - .

    , , .

    , , ,

    . .

    1. , . , .

    ,

    , .

    .

    , -

    . , ,

    .

    ? ? ?

    ? ,

    , -

    .

    -

    ? , , , ,

    , ? - .

    ? ?

    ? -

    . ,

    , -

    ( ) , , ..

    -

    , , -

    ? , , , ?

    , ? ? (, -

    .

    : , ..) () , ,

    ?

  • 1. C++ Builder 17

    - , -

    . , -

    .

    2. () . -

    () . , .

    , -

    , () , , ,, .. ,

    . ,

    , , , , Web- . ,

    () . -

    . , ,

    .

    , ,

    .

    .

    (Normalization).5. () -

    . , ,

    . ,

    . , -

    .

    t. , . ,

    . ( ) (Primary Key). - -

    . ,

    , , ,

    . ,

    , , -

    , . ,

    . , ,

    . , ,

    . , ,

    , , .

    , ,

    , ,

    . . -

    () .

  • 10 Borland C++ Builder 6.

    . ,

    .

    ,

    , (Foreign Keys, , ( ), : ! ( ) !. .

    5. , !, .

    () , . , ,

    , , .

    , , ,

    .. , , ,

    : , - ! NULL (.. ), (.. *, ).

    6. }!, . -

    .

    , .

    , -

    . ,

    . -

    . ,

    , .

    , ,

    , . ,

    , Big Technologies, - 5. , 5, Big Technologies. -, - 5, ,

    5. , , - (Referential Integrity). , ,

    , .

    .

    ( Microsoft Access CASE-) SQL-. ,

    , .

  • 1. C++ Builder 6

    --. -

    ( ) . . --

    --. -- , -

    .

    .

    .

    -- -

    .

    , , , -

    --. -- -

    .

    , .

    , ,

    -. -

    , . ,

    -

    -,

    -.

    . -

    .

    7. . , ,

    ,

    . , ,

    , . ,

    , ,

    . ,

    .

    . ,

    .

    , -

    . , -

    . ,

    , -

    . ,

    ,

    , . , -

    , ,

    .

    , .

    .

    , ,

  • Borland C++ Builder .

    . ,

    , . ,

    , .

    . , ,

    , (, 100 000) .

    , 100 , .8. . ,

    ,

    ,

    . , -

    .

    :

    ; - . -

    (, , - Microsoft Access, Interbase). ,

    .

    , -

    .

    -

    ( , -

    ). - , , .

    , . : -

    , ,

    .

    , C++Builder 6, SQL Explorer (Database Explorer) Database Desktop. - ,

    . ,

    , , ,

    , .

    SQL ExplorerSQL Explorer ,

    . -

    , , ,

    . ,

    SQL-. , SQL Explorer'a - (Alias) , (Dictionary) (Attribute Set). .

  • 1. C++ Builder 6 21 SQL Explorer C++ Builder 6 Enterprise.

    Professional, Database Explorer, . SQL Explorer.

    SQL Explorer : C++ Builder (IDEC++ Builder, IDE) . Explore Database, dbexplor.exe, BIN , C++ Builder ( $()). , . , -

    Windows, Window . , - , . 1.1.

    Qbtecl

    , X .- : ' :I All Database Aliase

    Detebese s ) DicSoi Definition 1) Databases-

    +. Ho DefauHDD+ *o IBLocalt; TJ myAcceesP. Access:*j Ti Visual FoxPro"S " & Visual FoxPro-f. TJ dBASEjj TS Excel

    _

    Type STANDARDDEFAULT DRIVER PARADOXENABLE BCD FALSEPATH Deprogram Files\Common Files\Boriwid Shoied\Data

    . 1.1. SQL Explorer . 1.1, SQL Explorer'a

    (Left Pane) (Right Pane). . : Databases ( ) Dictionary (-). .

    Databases (Aliases). (Alias) , - , BDE (Borland Database Engine) - . SQL Explorer,BDE Administrator Database Desktop, . , BDE, , -

    .

    SQL Explorer , . , C++Builder BCDEMOS,DefaultDD, IBLocal (. . 1.1). Paradox,

  • 22 Borland C++ Builder 6.

    Interbase ( , , Interbase). , ! , Active = false;Tablel->DatabaseName = "MyData";Tablel->TableName = "Category";Tablel->Active = true;Tablel->Active = false;Tablel->DatabaseName = "D:\Data";Tablel->TableName = "Category";Tablel->Active = true; ,

    . ,

    , .

    Items ,

    . ,

    , BigComputer. , - Category.

    Database Desktop. Paradox 7 :

    Q ItemNo. () Autoincrement. Key, .

    Q Item. () Alpha, (Size) 50. . Required Field, .

  • 38 Borland C++ Builder 6. Q Category. () Long Integer. Required Field

    Category, . . . , Category, Category. : 1 , i. , Long Integer ; Autoincrement.

    Q Description. () Alpha, (Size) 100. , .

    Q Index. () Alpha, (Size) 5. 5 ,

    . Index , , Items .

    ( ..) , . , < , .. Inde . ,

    , ,

    . ( ) , Index , Required Fields .

    Price. () Money. Price . .

    Items . 2.5.

    . 2.5. Items . Items Category. -

    Table properties ( ) Referential Integrity Define. , .

  • 2. 39 Items (. . 2.6), (.., ). : Child fields, Parent s key. Category .

    Child fields. Category . Database Desktop Parent s key Category. , Cascade Update rule, Category - Items. , Strictreferential integrity. Paradox .

    , .. ,

    ( ).

    . 2.6. Referential Integrity Database Desktop

    .

    . , -

    , Category , . -, (Referential Integrity), R I CategoryRI.

    Items Category, Items Category. Table properties Dependent tables ( ). , Items.db , Category.

    , Items , - , .

    Table properties Secondary Indexes. , Category. .

  • 40 Borland C++ Builder 6.

    , \ Item, . >Define Define Secondary Index (Fields) - Item. , (Indexedfields) . . - ItemNDX(cM. . 2.5).

    , ,

    , , Category Item. , - , .

    Data Items DatabaseDesktop. Items , SQL Explorer - Data. , , Description, -. ( ItemNo, ) . Category , CategoryNo Category.

    Items, , Data.

    -

    . (, -, ) . TDBNavigator .

    TDBNavigator, - , Form] TTable, TDataSource TDBGrid , .

    Items Active true. TDBNavigator. -, ,

    ( Data Controls), DataSource. TDBNavigator TDataSource. .

    , TDBNavigator, SQL Explorer, . ( ). , , (. . 2.7): (First), (Prior), (Next), (Last). ,

    . 2.7 Items .

    - , .

    VisibleButtons.

  • 2. BDE 41 . -

    . false, .

    , , .

    1;SamsungML-4SQO'

    3 Epson EFt-590QL4:CanonLBP-8105 Brother HL-1 240 Mono Laser6 Epson AcuLoserCIQOO7 Epson AcuLsssrC200DB:HPLaserJet1000w

    10:HP Laser JetlZZG11 HP LaseiJet 320012:HP Laser JelZZQG13 -Epson Stylus Color CJOSXHJEpsor. Stylus Color DUX15 lEpson Stylus Color C60

    ' -

    GDI, 600dp,, a:', , ;';

    !, 16(5;-;

    :4 ! . GD '/^ (?)/''

    "4. 60'J dp-. BCD dp

    ;A4. . 720 dpl.

    -A1. . 2883x72^

    H

    . 2.7. TDBNavigator ,

    :

    voidvoidvoidvoid

    _fastcall_fastcall_fastca!1fastcall

    Fi rst(void)Prior(void)Next(void);Last(void) ;

    int fastcall MoveBy(int Distance);property bool Bof = (read = FBof, nodefault};property bool Eof = (read=FEof, nodefault};

    //

    //

    . MoveBy Distance - . Distance , . -

    (). , MoveBy(1) Next{), MoveBy(-l) Prior(). MoveBy() , . -

    Distance. , ,

    , , -

    .

    Bof (Begin of file) Eof (End of file) , - . Bof true :

    U ;Q First ( ,

    );

  • 42 Borland C++ Builder 6.

    Prior, ;Q SetRange .

    / false. Eof, true :G ;G Last; Next, ;1_1 SetRange .

    / Eof . -, , .

    (, AfterScroll TTable) / Eof, , , .

    , ,

    (Bof = = true + Prior) (Eof ' = = true + Next) .

    Bof Eof TTable, . , VCL TPanel. TPanel - , Caption. ,

    , Bevellnner - bvRaised, BevelOuter bvLowered.

    , , ( TButton). Name ( ): BFirst, BPrior, BNext BLast, Caption First, Prior, Next Last . Tag 1 (BFirst), 2 (BPrior), 3 (BNext) 4 (BLast) , ,

    . .

    TEdit, TButton. BMoveBy ( Name) (Caption) MoveBy. TEdit Text. ( ):EPlan EReally. . , , TEdit (TLabel). (Caption): Bof Eof ( ). TEdit Text : EBofu EEof. , , .

    ( TDBGrid(DBGridl)), TDataSource (DataSourcel) TTable (Tablet). , - . Table 1 Items, Active false. , - . 2.8.

  • 2. 43

    *: i Fffrfj Pnpfj Ne j^: 1!I ' ; i ~% McveByj j

    . 2.8. , Bof Eof

    , ,

    . BFirst, Events OnClick. C++ Builder BFirstClick. - OnClick ( ). :

    void fastcall TForml::BFirstCl ick(TObject *Sender)TButton * Temp;Temp=dynamic_cast(Sender);if(Temp)

    switch(Temp->Tag)case 1:

    case 2 :

    case 3:

    case 4:

    Tablel->First(); break;Tablel->Prior(); break;Tablel->Next(); break;Tablel->Last(); break;

    BFirst->Enabled=!Tablel->Bof;BPrior->Enabled=!Tablel->Bof;BNext->Enabled=!Tablel->Eof;Blast->Enabled=!Tablel->Eof;

    Temp TButton.

    TButton Sender. ,

  • 44 Borland C++ Builder 6.

    (, ). , :

    . , !Tag . , Tag 1 4. , , . ! / 0/ . /, BFirst BPrior , !Eof BNext BLast. Bofvam Eof ' false, .

    BMoveBy EPlan EReally. , -

    EPlan BMoveBy, , ,

    EReally. , OnClick BMoveBy :

    void fastcall TForml::BMoveByClick(TObject *Sender){

    EReally->Text=IntToStr(Tablel->MoveBy(StrToIntDef(EPlan->Text,0))) ;

    } StrToIntDef

    EPlan->Text AnsiString . - StrToIntDef , . , MoveBy, AnsiString EReally.

    EPlan Enter. , - OnKeyPress EPlan :

    void fastcall TForml::EPlanKeyPress(TObject Sender, char &Key){

    if(Key == VK_RETURN) BMoveByClick(NULL);} , ,

    (. . , ASCII) , . , Enter(VK_RETURN , Enter), BMoveBy NULL.

    / / , , / Eof TTable. , A/terScroll - TTable. , , , ( , ). - AfterScroll :

  • 2. 45

    void fastcall TForml::TablelAfterScroll(TDataSet *DataSet)if(DataSet->Bof) EBof->Text="true";else EBof->Text="false";if(DataSet->Eof) EEof->Text="true";else EEof->Text="false";

    AfterScroll - DataSet. .So/ ./ , / EEof. , ,

    : BFirst BPrior ( ). OnCreate Forml:

    void fastcall TForml::FormCreate(TObject *5ender)

    Tablel->0pen();BFirst->Enabled=false;BPrior->Enabled=false;

    } ( NavMethods) -

    . -

    .

    2.1 2.2. 2.1. NavMethods

    #ifndef UnitlH#defme UnitlH

    #include #include #include #include #include #include #include #include #include #include

    class TForml : public TForm

    published: // IDE-managed CdmponentsTTable *Tablel;TDataSource *DataSourcel;TDBGrid *DBGridl;TButton *BFirst;TButton *BPrior;

  • 46 Borland C++ Builder 6.

    TButton *BNext;TButton *BLast;TPanel *Panell;TPanel *Panel2;TButton *BMoveBy;TEdit *EPlan;TEdit *EReally;TPanel *Panel3;TEdit *EBof;TLabel *Labell;TLabel *Label2;TEdit *EEof;void _ fastcall FormCreate(TObject *Sender) ;void _ fastcall BFi rstClick(TObject *Sender) ;void _ fastcall BMoveByClick(TObject *Sender);void _ fastcall EPlanKeyPress(TObject *Sender, char &Key)void _ fastcall TablelAf terScroll (TDataSet *DataSet);

    private: // User declarationspublic: // User declarations

    _ fastcall TForml(TComponent* Owner);

    extern PACKAGE TForml *Forml;//-- ........ -#endif

    2.2. NavMethods

    #include #pragma hdrstop

    #include "Unitl.h"

    #pragma package(smart_init)#pragma resource "*.dfm"TForml *Forml;

    _fastcall TForml : :TForml(TComponent* Owner): TForm(Owner)

    void _ fastcall TForml : :FormCreate(TObject *Sender){

    Tablel->0pen() ;BFi rst->Enabled=false;BPrior->Enabled=false;

    void _ fastcall TForml : :BFirstClick(TObject *Sender)

  • 2. 47TButton * Temp;

    Temp=dynamic_cast(Sender);

    if(Temp)

    switch(Temp->Tag)/

    case 1:

    case 2:

    case 3:

    Tablel->First(); break;

    Tablel->Prior(); break;

    Tablel->Next(); break;case 4:

    Tablel->Last(); break;

    BFirst->Enabled=!Tablel->Bof ;BP r i or ->Enabled=! Table l->Bof;BNex t->Enabled=! Table! ->Eof;Bias t->Enabled=! Table!- >Eof ;

    void _ fastcall TForml: :BMoveByClick(TObject *Sender)t

    EReally->Text=IntToStr(Tablel->MoveBy(StrToIntDef (EPlan->Text ,0)

    void _ fastcall TForml : :EPlanKeyPress(TObject *Sender, char &Key){

    if (Key == VK_RETURN) BMoveByClick(NULL) ;

    void _ fastcall TForml: :TablelAf terScroll (TDataSet *DataSet)

    i f(DataSet->Bof)elseif (DataSet->Eof)else

    EBof->Text="true";EBof->Text="false"EEof->Text="true";EEof->Text="false"

    (Fields) Fields.

    TFields , TField. TField . TField , . TField , -

    Fields.

  • 48 Borland C++ Builder 6.

    , TFields , , .

    TFields:property int Count = {read=GetCount, nodefault};

    _property TDataSet* DataSet = {read=FDataSet};property TField* Fieldsfint Index] =

    {read=GetField, write=SetField}; . DataSe

    , Fields. - . Count : TField, . . Fields - :

    [].

    TFields . , (, TCIientDataSet), .

    AggFields.

    TFields , - (TField). :

    TField* operator [] (int Index) { return Fields[Index] ; }TField* fastcall FieldByNumber(int FieldNo);TField* fastcall FieldByName(const AnsiString FieldName); [] -

    . ( !). , . ,

    Items 0 ItemNo, 1 Item, Price - 5. Count 6. : ItemNo 0, Item \ ..

    . (Fields Editor), - .

    , ,

    . , ,

    Description , , . ,

    ,

    Add fields. - , Description ( , - Ctrl) . , Description.

  • 2. 49

    , .

    , -

    /7 FieldByNumber. , . FieldByNumber -, , [] - .

    , , . -

    , ( TLabel), TListView, . -. Items MyData. , - , -

    ( Description ). TListView. ,

    : Index, Fieldsflndex] FieldByNumber [Index]. , ViewStyle vsReport. OnCreate :

    void _ fastcall TForml: :FormCreate(TObject *Sender){

    Tablel->0pen();Labell->Caption=" Items " +IntToStr(Tablel->Fields->Count)+ " : " ;

    TListltem *Temp;

    for(int i=0;iFields->Count;i++)

    Temp=ListViewl->Items->Add() ;Temp->Caption=i ;Temp- > Subl terns ->Add (Table l->Fi eld s->Fi elds [i] ->FieldName) ;Temp- >SubI terns ->Add (Table l->Fi elds ->FieldByNumber (i+1) ->FieldName) ;

    .

    [] FieldByNumber (. . 2.9).

    Count TF/e/ds , . , ,

    Items, Tab/e7->F/e/ds->Count 5, . F/eldCount (, TDataSet). , ,

    FieldByName. TField, . ,

  • 50 Borland C++ Builder 6.

    .

    FieldByName,

    Tablel->FieldByName("Item") ' // ItemTablel->FieldByName("Description") // Description

    Hems cc

    : temNo l(?.rr''4'0: Item Iten

    2 ' Category : Category* Jridex .. _ .1 Description

    4 . Price i Index5

    : Qeacriptipn : Price

    , _

    . 2.9. FieldByNumber , ,

    ,

    ,

    . BDE . - . ,

    , , .

    :

    void fastcall ApplyRange(void);void fastcall CancelRange(void);void fastcall EditRangeEnd(void);void fastcall EditRangeStart(void);void fastcall SetRange(const System::TVarRec * StartValues,const int StartValues_Size, const System::TVarRec * EndValues,

    const int EndValues_Size);void fastcall SetRangeEnd(void);void fastcall SetRangeStart(void); , , TDataSet. ,

    () , .Q ,

    . IndexFieldNames, IndexName. IndexFieldNames AnsiString, - , .

    IndexName, , , . , ,

    , .

    Q , - .

  • 2. 51

    SetRangeStart SetRangeEnd. - EditRangeStart EditRangeEnd.

    Q , ApplyRange. CancelRange - .

    , Items Category. , Paradox . Items, Category 3 5.

    Table1 ->DatabaseName="MyData";Tablel->TableName="Items.db";Tablel->IndexFieldNames="Category";Tablel->0pen();Tablel->SetRangeStart();Tablel->FieldByName("Category")->AsInteger=3;Tablel->SetRangeEnd();Table!->FieldByName("Category")->AsInteger=5;Tablel->ApplyRange(); SetRangeStart SetRangeEnd ApplyRange -

    SetRange, . SetRange- ( ) - . :

    Tablel->DatabaseName="MyData";Tablel->TableName="Items.db";Tablel->IndexFieldNames="Category";Tablel->0pen() ;Tablel->SetRange(OPENARRAY(TVarRec,(3)), OPENARRAY(TVarRec,(5)));

    OPENARRAY , , .

    , OPENARRAY(TVarRec,(3)) SetRange, OPENARRAY(TVarRec,(5)) - . / Open/Array Object Pascal, .

    , C++ , VCL, Object Pascal, . OPENARRAY ARRAYOFCONST Borland C++ Builder.

    -

    . , ,

    TDBGrid, TDataSource, Items , . , . (TPanel). (TButton). : BPriorCat, BNextCat, BPriorRec, BNextRec, : Prior Category, NextCategory, Prior Record, Next Record. (TEdii),

  • 52 Borland C++ Builder 6. (TLabel) . BApply, BCancel Apply Rang: Cancel Range . ECat Text Category. . 2.10.

    tefrtNe|ft*m --. : '-I .,'... jCetago-ylDescrioion *]t

    iLJ

    1 MustekScariExpress1200UBPk2 Mustek ScenExpress 1200 USB F3 Mustek ScnnExpress A3 EPA HP ScanJet 2200C5 HP ScanJet 46 HP ScanJet 44COC7 HPScartJeH47QC8 HP ScanJet 540QC

    2 CCD. . .4. 36 . f \.;"2 OS. . A3, 36 , ' i.2 CCD. . 4 True Col> : !:i2

  • 2. 53

    Unit 1. :void fastcall TForml::SetFilterCat(long int Cat){

    if(Cat == 0) return;Tablel->SetRangeStart();Tablel->FieldByName("Category")->AsInteger=Cat;Tablel->SetRangeEnd();Tablel->FieldByName("Category")->AsInteger=Cat;Tablel->ApplyRange();ECat->Text=IntToStr(Cat);BApply->Enabled=false;BCancel->Enabled=true;

    } SetFilterCat , .

    Cat 0, . . SetFilterCat ECat -

    Apply Range Cancel Range. , TDBGrid , . Aslnteger TField - Integer. Aslnteger TField , .

    .

    KeyExclusive boo/; .

    ,

    . ,

    , 4 5.Tablel->SetRangeStart();Tablel->FieldByName("Category")->AsInteger=3;Tablel->KeyExclusive=false;Tablel->SetRangeEnd();Tablel->FieldByName("Category")->AsInteger=5;Tablel->ApplyRange();

    , , -

    OnClick. BPriorCat OnClick Tablel->First(), BNextCat Tablel->Last(), BPriorRec BNextRec Tablel->Prior() Tablel->Next(). , (. . - / Eof true) , .

    OnClick (BPriorCat, BNextCat, BPriorRec BNextRec) -

  • 54 Borland C++ Builder 6.

    Enabled ,

    , , .

    OnClick , . , ^

    , ECat. . -

    . ,

    .

    ,

    ,

    . 2.3 2.4.

    2.3. ApplyRangeDemo// -#ifndef UnitlH#define UnitlH//#include #include #include #include #include #include #include ^include

  • 2. 55

    private: // User declarationsvoid _ fastcall SetFiUerCat(long int Cat);

    public: // User declarations_fastcall TForml(TComponent* Owner);

    extern PACKAGE TForml *Forml;//#endif

    2.4. ApplyRangeDemo

    #include #pragma hdrstop#include "Unitl.h"

    #pragma package(smart_ini t)#pragma resource "*.dfm"TForml *Forml;long int Cat;

    _fastcall TForml: :TForml(TComponent* Owner): TForm(Owner)

    void _ fastcall TForml: :FormCreate(TObject *Sender){

    Tablel->IndexFieldNames="Category" ;Tablel->0pen() ;Cat=l;SetFilterCat(l);BPriorCat->Enabled=f alse;BPriorRec->Enabled=false;

    void _ fastcall TForml: :BPriorCatClick(TObject *Sender){

    Tablel->First() ;if (Cat != 0){

    if(Cat > 1) Cat--;SetFilterCat(Cat);ECat->Text=IntToStr(Cat) ;Tablel->Last() ;

    }if(Cat < 2) BPriorCat->Enabled=false;if (BNextCat->Enabled == false) BNextCat->Enabled=true;if (BNextRec->Enabled == false) BNextRec->Enabled=true;

  • 56 Borland C++ Builder 6.

    void _ fastcall TForml : : BNextCatClick(TObject *Sender){

    Tablel->Last() ;if(Cat != 0){

    if (Cat 12) Cat++;SetFilterCat(Cat) ;ECat->Text=IntToStr(Cat) ;

    }if(Cat == 12) BNextCat->Enabled=false;if (BPriorCat->Enabled == false) BPriorCat->Enabled=true;if (BPriorRec->Enabled == false) BPriorRec->Enabled=true;

    void _ fastcall TForml : :BNextRecClick(TObject 'Sender){

    Tablel->Next();if (Tablel->Eof){

    if ((Cat == 12) | | (Cat == 0)){

    BNextRec->Enabled=false;BNextCat->Enabled=false;

    }if(Cat != 0){

    if(Cat 12) Cat++;SetFilterCat(Cat) ;ECat->Tex.t = IntToStr(Cat) ;

    if (BPn'orRec->Enabled == false) BPriorRec->Enabled=true;if((Cat == 2) && (BPriorCat->Enabled == false))

    BPriorCat->Enabled=true;if((Cat == 12) && (BNextCat->Enabled == true))

    BNextCat->Enabled=false;

    void _ fastcall TForml : :BPriorRecClick(TObject *Sender){

    Tablel->Prior() ;if(Tablel->Bof){

    if(Cat < 2) BPriorRec->Enabled=false;else{

    if (Cat > 1) Cat--;SetFilterCat(Cat) ;ECat->Text=IntToStr(Cat) ;Tablel->Last() ;

  • 2. 57

    if(BNextRec->Enabled == false) BNextRec->Enabled=true;if((Cat == 11) && (BNextCat->Enabled == false))

    BNextCat->Enabled=true;if((Cat == 1) && (BPriorCat->Enabled == true^)

    BPriorCat->Enabled=false;

    void fastcall TForml::5etFilterCat(long int Cat)

    if(Cat == 0) return;

    Tablel->SetRangeStart();Tablel->FieldByName("Category")->AsInteger=Cat;Tablel->SetRangeEnd();Tablel->FieldByName("Category")->AsInteger=Cat;Tablel->ApplyRange();

    ECat->Text=IntToStr(Cat);BApply->Enabled=false;BCancel->Enabled=true;

    void fastcall TForml::BCancelClick(TObject *5ender)Cat=0;Tablel->CancelRange();BApply->Enabled=true;BCancel->Enabled=false;ECat->Text="All";BPriorCat->Caption="Fi rst Record";BNextCat->Caption="Last Record";

    void fastcall TForml::BApplyClick(TObject Sender)Cat=StrToIntDef(ECat->Text,0);if ((Cat < 1) || (Cat > 12)) Cat=l;SetFilterCat(Cat);BPriorCat->Caption="Prior Category";BNextCat->Caption="Next Category";

    Filter, Filtered FilterOptions. TBDEDataSet, - TDataSet . Filter Filtered , , , . .

    .

    Filter , - , . -

  • 58 Borland C++ Builder 6. :

    = .

    , Category=3, Filter, , , 3. - , , ,

    . , -

    , .

    , : [ ]. :

    (), (>), (

  • 2. 59

    OnCreate OnClose :

    void fastcall TForml::FormCreate(TObject *5ender){

    Tablel->0pen();}void fastcall TForml::FormClose(TObject *Sender,

    TCloseAction &Action){

    Tablel->Close();} , , :

    Tablel , . OnClick BApply BCancei.

    void fastcall TForml::BApplyClick(TObject *Sender){

    Tablel->Filter=ECriteria->Text;if(CBCaseInsensitive->Checked)

    Table1->FiIterOptions foCaselnsensitive;else Tablel->FilterOptions foCaselnsensitive;if(CBNoPartialCompare->Checked)

    Table1->FiIterOptions foNoPartialCompare;else Tablel->FilterOptions foNoPartialCompare;Tablel->Filtered=true;

    }void fastcall TForml::BCancelClick(TObject *Sender){

    Tablel->Filtered=false;} BCancei Filtered -

    false', . BApply , ECriteria, , ECriteria, Filter, , CBCasefnsensitive CBNoPartialCompare, FilterOption. , Filtered true.

    ! , .

    . . 2.11 Items, Item. , Case Insensitive , No Partial Compare. -

    . -

    . 2.11 , Item sam Sam ( ) (, ).

  • 60 Borland C++ Builder 6.

    OnFilterRecord . TDataSet :

    typedef void _ fastcall ( _ closure *TFilterRecordEvent)(TDataSet* DataSet, bool &Accept) ;

    ( ) DataSet , Filtered tru> , ,

    Accept - false. OnFilterRecon

    pax . Edit Edit2.

    void _ fastcall TForml: :TablelFilterRecord(TDataSet *DataSet,bool &Accept)

    {Accept=(DataSet->FieldValues["Price"J >= StrToIntDef (Edi tl->Text ,0))&&(DataSet->FieldValues["Price"] Text, 1000)) ;

    ,

    . SetKey ( EditKey GotoKey . - :

    void _ fastcall SetKey(void) ;void _ fastcall Edi tKey (void) ;bool __ fastcall GotoKey (void) ;void _ fastcall GotoNearest(void) ; , , -

    .

    IndexFieldNames ( , ), - IndexName ( ). , : Field '_ ' is not indexed and cannot be modified ('_ ' ). - SetKey. , dsSetKey. -

    . , -

    ,

    IndexFieldNames IndexName. GotoKey .

    () , true . - , GotoKey ^/^.

    EditKey , SetKey, -

  • 2. 61

    , .

    , , , ,

    . SetKey , , , ,

    . GotoKey , EditKey , , . GotoKey , - , , .

    , Item Items.

    Tablel->IndexName="ItemNDX";Tablel->SetKey();Tablel->FieldByName("Item")->AsString=ESample->Text;Tablel->GotoKey();Tablel->IndexName=""; ,

    . , Items Item ItemNDX. SetKey, , Item , ESample. GotoKey ,

    . .

    , IndexName ItemNDX, Item , ItemNDX ( ). - , ,

    , .

    -

    (. . -). , , , -

    IndexName. , ,

    GotoKey GotoNearest. - ,

    .

    . GotoNearest , - , .

    , GotoKey GotoNearest, -. FindKey FindNearest. :

    bool fastcall FindKey(const System::TVarRec * KeyValues,const int KeyValues_Size);

    void fastcall FindNearest(const System::TVarRec * KeyValues,const int KeyValues_Size);

    (- ), . . , -

  • 62 Borland C++ Builder 6.

    OPENARRAY ARRAYOFCONST. FindKey FindNearest SetKey , , . , ,

    , :

    Tablel->IndexName="ItemNDX";Tablel->FindKey(OPENARRAY(TVarRec,(ESample->Text)));Tablel->IndexName="";

    Locate. TBDEDataSet ( , TDataSet) :

    virtual bool fastcall Locate(const AnsiString KeyFields,const System::Variant &KeyValues, Db::TLocateOptions Options); , ?

    TBDEDataSet (TTable, TQuery, TStoredProc). ,

    Locate AnsiString, . .

    Variant. , .

    Variant VarArrayOf. TLocateOptiom. loCaselnsensitive ( ) loPartialKey ( - ). Options .

    , -

    Locate.

    void fastcall TForml::BLocateClick(TObject *Sender){

    TLocateOptions SearchOptions;SearchOptions.ClearQ;if(CBCaselnsensitive->Checked) SearchOptions loCaselnsensitive;if(CBPartialKey->Checked) SearchOptions loPartialKey:Tablel->Locate(EField->Text, ESample->Text, SearchOptions);

    } CBCaselnsensitive CBPartialKey -

    . -

    EField, ESample.Lookup , ,

    .

    TBDEDataSet :

    virtual System::Variant fastcall Lookup(const AnsiString KeyFields,const System::Variant SKeyValues, const AnsiString ResultFields);

    Lookup , , - .

  • 2. 63

    .

    Locate (. ). - AnsiString. , . , - Items, , :

    EField->Text=Tablel->Lookup("Item","HP LaserJet 1200","Index"); , -

    FindFirst, FindPrior, FindNext FindLast. , , ,

    , , , -

    . -

    , Find... . FindFirst, FindPrior, FindNext FindLast TDataSet :

    bool fastcall FindFirst(void);bool fastcall FindPrior(void);bool fastcall F indNext(void);bool fastcall F indLast(void); true

    false . OnFilterRecord , . Filtered false.

    . , -

    OnFilterRecord, .

    Find... OnFilterRecord, -. , -

    TDBGrid, TTable TDataSource, . Items MyData. (: EField ESample), (: Field Sample) (:BFindFirst, BFindPrior, BFindNext, FindLast; , : Find First, FindPrior, Find Next, Find Last; Tag, : 1,2,3, 4). , . 2.12.

    BFindFirst OnClick - OnClick . :

    TButton* Temp=dynamic_cast(Sender);if(Temp){

    swi tch(Temp->Tag){

    case 1: Tablel->FindF1rst(); break;case 2: Tablel->FindPrior(); break;case 3: Tablel->FindNext(); break;

  • 64 Borland C++ Builder 6. case 4: Tablel->FindLast(); break;

    };DBGrid l->SetFocus() ;

    ] ,

    .

    Sender TButton *, , , Tag, !( ). TDBGrid.

    OnFilterRecord:

    Accept=(DataSet->Fields->FieldByName(EField->Text)->As5tring.AnsiPos(ESample->Text) 0) ; ,

    EField. AsString AnsiString. AnsiPos AnsiString , , ESample, !. , AnsiPos , ( Accept true, Find... , true. FindPrior FindNext nonet , .

    5^ *SfjlSHum :JFC-PGA - V.FiBdtosr;;::.! ' FBiti^ fe

    LJ

    63 Socket A GIGA-BYTE GA-7ZXE63 Socket A GIGA-BYTE GA-7ZX Rev. 5X6< Socket A ChaJnTBchCT-7AJA2 '65 Socket A GIGA-BYTE GA-7ZMMM66 Socket A ASUS A7V133-C

    HJfl Socket 370 FC PGA/PPGA Canvon 6LEBMS68 Socket 370 FC-PGA/PPGA Canyon SLEBMS-T69 Socket 370 FC-PGA/PPGA Menli 8997C Socket 370 FC-PGA/PPOA PC ParlnerT205C71 Socket 37C FC-PGA/PPOA FoslFame 3SLAP72 Socket 370 FC-PGA/'PPGA PC Partner C203T . :-?-GetBookmark();}void fastcall TForml: :BGotoBockmarkClick(TObject *Sender){

    Tablel->GotoBookmark(MyTBookmark);Tablel->FreeBookmark(MyTBookmark);MyTBookmark=NULL;

    } BGotoBookmark

    FreeBookmark , MyTBookmark GetBookmark. MyTBookmark NULL. , , BGetBookmark . - OnClose :

    if(MyTBookmark) Tablel->FreeBookmark(MyTBookmark); ,

    MyTBookmark. NULL, , FreeBookmark.

    , ,

    .

    BookmarkValid, TBDEDataSet :

    virtual bool fastcall BookmarkValid(void * Bookmark); TBDEDataSet, -

    , TQuery. TBookmark, , , BookmarkValid - true.

    , , -

    . , (unidirectional)

  • 72 Borland C++ Builder 6.

    . ,

    , IsUniDirectional.

    TDataSource , ,

    . , Post , ,

    : Dataset not in edit or insert mode ( ). -, Post, , .

    State. TDataSet :

    property TDataSetState State = {read=F5tate, nodefault}; State, , .

    TDataSetState:

    dslnactive , - -.

    dsBrowse . .

    dsEdit . , , .

    , , .

    , Post ( ) Cancel ( ). dsBrowse.

    G dslnsert , -, Insert Append. ,

    . dsEdit, - ( , ) Post Cancel dsBrowse.

    dsSetKey - . , ,

    SetRange. dsSetKey - TClientDataSet.

    dsCalcFields OnCalcFields (. . ( ) - ). () .

    Q dsFilter - State OnFilter-Record. . .

  • 2. BDE 73

    U dsNewValue, dsOldValue dsCurVahie. , - BDE . - TField NewValue, OldValue CurValue.

    dsBlockRead - , .

    , -

    .

    Q dslnternalCalc BDE , ( FieldKind)fklnternalCalc. Tvm&fklnternalCalc , , - irniufkCalculated, . ( TField) .

    Q dsOpening. - , .

    State . TDataSource State TDataSetState, , TDataSource. -, TDataSource. , , TDataSource.

    TDataSource - , -

    . , C++ Builder, TDataSource (conduit) - . ,

    , TDataSource, . ,

    TDataSource, ,

    (Data-aware Controls) - . -

    , TDataSource -- ( / (Master/Detail)).

    TDataSource : State, AutoEdit, DataSet Enabled. State TDataSetState . State TDataSource , Enabled false - DataSet, State dslnactive .

    Enabled , .

    false . DataSet TDataSet, TDataSource. , , Enabled true, DataSet

  • 74 Borland C++ Builder 6.

    TDataSet (, , :, ).

    , ;TDBGrid , TDBGrid, (dsEdit). (- Options TDBGrid) dgAlwaysShowEditor Enter F2, ; .

    , AutoEdit TDataSource true. AutoEdit - false, Edit. .

    TDataSource, , : IsLinkedTo Edit. Edit TDataSource , . - AutoEdit. true, - . (dsBrowse), Edit . , Edit TDataSource ,

    .

    IsLinkedTo , TDataSource TDataSet. - .

    TDataSource. : OnDataChange, OnStateChange OnUpdateData. TNotifyEvent, - OnDataChange :

    typedef void fastcall ( closure *TDataChangeEvent)(TObject* Sender, TField* Field);

    OnDataChange , , -

    (, ). , Field NULL. To - Field , . .

    , , , -

    ,

    .

    OnUpdateData , , BeforePost. - -

    .

    , , OnStateChange , , -

    . -

  • 2. BDE 75

    , , ,

    .

    OnStateChange, ModifyRec, . IDE C++ Builder - TStatusBar. ( Align alBottom). SimplePanel TStatusBar true SimpleText - .

    OnStateChange - :

    void fastcall TForml::DataSourcelStateChange(TObject *Sender)AnsiString StatusText;

    switch(DataSoureel->State)

    case dslnactive: { StatusText="Inactive"; break; }case dsBrowse: { StatusText="Browse"; break; }case dsEdit: { StatusText="Edit"; break; }case dslnsert: { StatusText="Insert"; break; }case dsSetKey: { StatusText="SetKey"; break; }case dsCalcFields: { StatusText="CalcFields"; break; }case dsFilter: { StatusText="Filter"; break; }case dsNewValue: { StatusText="NewValue"; break; }case dsOldValue: { StatusText="01dValue"; break; }case dsCurValue: { StatusText="CurValue"; break; }case dsBlockRead: { StatusText="BlockRead"; break; }case dsInternalCalc: { StatusText="InternalCalc"; break; }case dsOpening: { StatusText="Opening"; break; }default: 5tatusText="Unknown" ;

    StatusBarl->SimpleText="DataSet Status: " + StatusText;

    , .

    .

    .

    ,

    .

    TField TField (,

    ..). , - . TField -, , ,

    C++ Builder. , 2.1.

  • Borland C++ Builder 6.

    2.1. TField

    TADTField

    TAggregateFi eld

    TArrayField

    TAutoIncField

    TBCDField

    TBinaryField

    TBlobField

    TBooleanField

    TBytesField

    TCurrencyField

    TDataSetField

    TDateField

    TObjectField. ADT (Abstract Data Type). ADT (), - . -

    ADT. TField. - . -

    .

    , , -

    .

    TObjectField. . -

    .

    (, ), (, ADT). TInteger Field, , ,

    TNumericField. . TNumericField. - - (Binary CodedDecimal). BCD - ,

    .

    TField. .

    TField. -, BLOB (Binary Large Object). TField. .

    TBinaryField. Byte.

    TFloatField, - TNumericField. Currency. TObjectField. , ,

    (nested) . TDateTimeField. , .

  • 2. 77

    TDateTimeField

    TFloatField

    TFMTBCDField

    TGraphicField

    TGuidField

    TIDispatchField

    TIntegerField

    TInterfaceField

    TLargelntField

    TMemoField

    TReferenceField

    TSmalllntField

    TSQLTimeStampField

    TStringField

    TTimeField

    TVarBytesField

    TField. , .

    TNumericField. , .

    TNumericField. - BCD (BinaryCoded Decimal). TFMTBCDField - TBCDField -. C++ Builder 6. TBlobField. , .

    TStringField. ,

    (GU1D Globally Unique Identifier). TInterfaceField. , IDispatch. TNumericField. .

    TField. , , -

    (lUnknown). TNumericField. large integer. TBlobField. MEMO. TObjectField. , .

    TIntegerField, -, , TNumericField. small integer. TField. Date/Time dbExpress. - C++ Builder 6. TField. .

    TDateTimeField. , .

    TBytesField, , , TBinaryField. -

    .

  • 78 Borland C++ Builder 6.

    TVariantField

    TWideStringField

    TWordField

    TField. Variant. TStringField. WideString. TInteger Field, TNumericField. Word.

    TField . , , -

    , ,

    , -

    ,

    . TField -

    . , -

    . , , TField, , TStringField, FixedChar Transliterate, .

    --

    TField: . - , ,

    .

    , TField TField . -

    , , .

    C++ Builder. TField -

    . As - , .

    , .

    .

    Ansi String Price=Tablel->FieldByName("Price")->AsString;int IntPrice=Tablel->FieldByName("Price")->AsInteger;Currency CurPrice=Tablel->FieldByName("Price")->AsCurrency; .

    .

    CurValue, OldValue NewValue ( ) , , , .

    ,

    TClientDataSet (cachedupdates). , ( Post) . OnUpdateError OnReconcileError CurValue, OldValue NewValue,

  • 2. 79

    .

    Value, DisplayText Text. Value / - ( ) . . , TCurrencyField, - Value Currency. DisplayText Text AnsiString , -

    . Text - . Text DisplayText OnGetText , .

    DataType FieldKind . DataType - . DataType TFieldType. 2.1 -- TField. , TIntegerField ftlnteger, .. FieldKind TFieldKind:

    fkData , . jkCalculated . -

    OnCalcFields. fkLookup . -

    .

    JklnternalCalc , , /kData. , SQL, , BDE - , RequestLive true.

    jkAggregate . . Calculated, Lookup,

    LookupCache, LookupDataSet, KeyFields, LookupKeyFields, LookupList LookupResultField. true Calculated , , . . - OnCalcFields . - . .

    AutoGenerateValue. , , -

    . ,

    . -

    ( Post) . AutoGenerateValue. , ,

    . AutoGenerate Value TAutoRefreshFlag: arNone ( ), arAutoInc( ), arDefault ( ). , AutoGenerateValue,

    , .

  • 80 Borland C++ Builder 6.

    DefaultExpression. , SQL, -|. ,

    , , 'No Item' '15:45'. *DefaultExpression, , ; ,

    .

    TField , (). , . CustomConstraint, ImportedConstraintConstraintErmrMessage HasConstraint. CustomConstraint - , -

    , . -

    , CustomConstraint, , ConstraintErmrMessage.

    ImportedConstraint -, . , ImportedConstraint . . ImportedConstraint, , , -

    , .

    , , ImportedConstraint, ,

    . ConstraintErrorMessage , .

    HasConstraint . true, . , : CustomConstraint, ImportedConstraint DefaultExpression.

    FieldKind - fkData, FieldName ,

    .

    TField . Islndex true, () . IsNull true, - . EditMask TEditMask ( AnsiString) .

    TEditMask C++ Builder.

    TField . BDE. , , Assign Clear. Assign Value - .

    . , TablelDateO->Assign(TablelDatel) DateO - Table 1 Datel . , Date. TablelDescription->Assign(Memol->Lines) Description Tablel, Memo, -

  • 2. BDE

    Memol, . Clear , Value NULL.

    TField , . OnChange, OnGetText, OnSetText OnValidate. OnChcmge , .

    -

    ,

    . OnChange - OnValidate, . OnChange - , ,

    . OnChange - , .

    OnValidate - .

    , . OnValidate

    . , -

    ( throw). OnChange .

    OnGetText OnSetText :

    typedef void fastcall ( closure *TFieldGetTextEvent)(TField* Sender,AnsiString &Text, bool DisplayText);

    typedef void fastcall ( closure *TFieldSetTextEvent)(TField* Sender,const AnsiStr ing T e x t ) ;

    OnGetText DisplayText Text TField. , , . -

    TDBGrid OnGetText , . Sender , , Text AnsiString.

    -

    , Text . , -

    TDBGrid, OnGetText, . , -

    OnGetText, Text. , Text AsString . OnGetText -,:

    void fastcall TForml::TablelItemGetText(TField *Sender,AnsiString &Text, bool DisplayText)

    {Text=Sender->AsString;

  • 82 Borland C++ Builder .

    OnGetText DisplayText. , , Text .

    - .

    OnSetText , Text . Text, const, Text . Text . ^ OnGetText - , OnSetText .

    .

    (Dynamic fields), (Persistent fields). , .

    . -

    . -

    , . ,

    , .

    .

    ,

    . -

    .

    , - ,

    . , -

    .

    FieldDefs . TFieldDefs , . FieldDefs , , ,

    . FieldDefs - , (CalculatedFields). ( IndexDefs), .

    (Persistentfields) , (Fields Editor). - , ,

    , , . -

    ,

    , , .

    , -

    , .

    TField ( ) .

  • 2. 83 , ( ) -

    . , ,

    . ,

    . , -

    .

    , .

    , ,

    . ,

    ,- , -

    .

    , , -

    , , .

    , , -

    .

    temMo jfcKn328 HUBCompexPS329 HUBHPPraCun330 ;331 HUBEP-ai6DX-332 Mel EthE333 Intel EthE33-1 Intel Ethe335 Intel Pro/1336 imel Pro/

    j 337 HUB Intel Stainda

  • 84 Borland C++ Builder 6.

    , ,

    .

    .

    . , Name FielName. FieldName , , Name . HMCI ,

    . , Tablelhem. . ,

    Table!->FieldByName(Item). ,

    . ; ( , ) . , Item Items TStringField, Price TCurrencyField. ] ,

    , .

    Delete.

    (Attribute Sets). ! , SQL Explorer. SQL Explorer, . -

    Associate attributes. - , .

    Dictionary SQL Explorer Attribute Sets, .

    , . ,

    , -

    , .. , -

    , , . -

    , Unassociate attributes. ,

    .

    - ,

    : Save attributes, Save attributesas Retrieve attributes. Save attributes , , , .

    Save attributes as . Retrieve attributes .

    -

    , . -

    .

  • 2.

    , ,

    . ,

    . ,

    ( ) TDBEdit, , , TDBImage. ,

    ( Tlabel), . , ,

    .

    .

    (Calculated Fields)-

    (CalculatedFields), .. , , - . , -

    , ,

    , .

    ,

    , .

    .

    .

    OnCalcFields , . ,

    ,

    , ,

    . , -

    , ,

    Visible false. OnCalcFields -

    .->1-. OnCalcFields . , -

    , . OnCalcFields - :

    Q , ;Q ( dsEdif);G (, ).

    , AutoCalcFields true, OnCalcFields

    (TDBGrid) . ,

    , AutoCalcFields false, .

    , -

  • 86 Borland C++ Builder . MyData, , . . Database Desktop Paradox 7. , 2.2.

    2.2. Employees

    (Field Name)EmployeeNo ()LName ()FName ()MName ()HireDate ( )FireDate ( )Description ()Photo ()Birthday ( )

    ()Autoincrement (+)Alpha (A)Alpha (A)Alpha (A)Date (D)Date (D)Memo (M)Graphic (G)Date (D)

    (Size)

    502025

    240

    (Key)*

    LName HireDate Required field - . Table properties Secondary Indexes Define. LName, FName MName ( ) NameNDX. , , Employees. , - . , Employees .

    , - . -

    , . (EmployeeNo) .

    . , -

    , ,

    Employees. , - , .

    TDBGrid, TTable TDataSource, . , , DBGridl DataSourcel, a Data-Sourcel Tablel. Tablel Employees MyData.

    : , -

    , , .

    , .

    , .. , FireDate () . - , ,

    FireDate NULL. Filter - : FireDate=NULL. ,

    Employees NameNDX ( - IndexName).

  • 2. 87

    () , : Name ( ), Age (), Standing (). (, )., New field , - .

    Name, ( _). String Name Smalllnt Age Standing. Size 50 Name, . Field type Calculated. . 2.14 Standing.

    . 2.14. Standing Name, Age Standing

    LName, FName, MName, HireDate Birthday. , FireDate, ( - ). Add fie Ids. - . Visible false, . ,

    false Visible ., OnCalcFields :

    void _fastcall TForml: :TablelCalcFields(TDataSet *DataSet)

    AnsiString FI.SI;unsigned short yearl, yearO, month, day;

    if (!TablelFName->IsNull)FI=" " + (TablelFName->Value). SubString(0, 1) + "." ;

    if((!Table!MName->IsNuU) && ( ! (FI . IsEmpty ()) ))SI=" " + (TablelMName->Value) . SubString(0, 1) + "." ;

    TablelName->Value=TablelLName->Value + FIDate() .DecodeDate(&yearl, &month, &day) ;(TablelBirthday->Value) .DecodeDate(&year0,TablelAge->Value=yearl-year0;(TablelHireDate->Value) .DecodeDate(&year0,TablelStanding->Value=yearl-year0;

    + SI;

    &month, &day) ;&month, &day) ;

  • Borland C++ Builder 6.

    .

    FI SI AnsiString. , i FName . , IsNull. FNar , FI , , . Substring AnsiString. , , . ,

    SI, , , ]: , . ,

    AnsiString IsEmpty.

    .

    . 2.15. ,

    Value Name , . : i , Name .

    OnCalcFields (Age Standing. ( Age) , . ( Standing) - .

    Date, TDateTime. TDateTime DecodeDat , .

    OnCreate :

    void fastcall TForml::FormCreate(TObject *Sender){

    Tablel->0pen();Tablel->Filtered=true;

    } .

    . . 2.15 .

    TDataSet TQuery. !TQuery -.

  • 2. BDE

    (Lookup Fields) (Lookup Fields)

    .

    .

    ,

    , ,

    . , Items Category, Category. , - - . ,

    .

    ,

    .

    Category Items. , ,

    TDBGrid, TTable TDataSource, . - , Tablel Items MyData. Active Tablel true, . -

    Category. (2) .

    . ,

    Tablel. Add all fields, . , -

    .

    New field. , Field properties, (Name) ( Category , CategoryName), () (Size) ( - Category, String 25).

    Field type Lookup, , . Lookup definition : Key Fields Dataset. Key Fields , , . -

    . Key Fields, , . -

    Category. Dataset

    TDataSet ( : Tablel Table!). , .

    Tablel, -, (- ). 2. : Lookup Keys Result Field.

  • 90 Borland C++ Builder 6.

    : Field ptoperties: : |CrtegoiyJome

    Type:.. ' . 'Sting

    ; Field - '

    Component |ToblelC3tegoryName2 ;.,;

    ^J Site: |re

    ''. gey field*: ' JGategoi

    Lookup Keys: jCainqoiyNo _Tj Besuft Field; fCotegoi

    . 2.16. CategoryName Lookup Keys ;

    (Lookup DataSei). , Lookup Keys, , < Key Fields. > .

    1

    , KtFields. CategoryNo.

    Lookup definition Result Field. , Result Fieh ,

    . Category. . 2.1 New Field, CategoryName.

    Tablel , . Category, , , Visible //. CategoryName , Item. , : . : DisplayLabt CategoryName Category. .

    .

    . 2.17.

    1

    1 Samsung ML-45002 SamsungML-12103 Epson EPL-59QQLA Canon LBP-81Q5 Brother HL-1Z40 Mono Lasere.EpsonAcuLossfCIOOO7 EpsonAcuLaserCZQOO8 HPLeserJetlCQQw9 HPLeserJel1200

    10 HP LaserJet 122011 HP LaserJet 3200

    J

    < GDI, 2 , 600 dpi. . J

    4. GDI, . 600 dpi, . :4. GDI, 2(1 ) . 600 ^ J4. GDI, 600 dpi. 8 pprn, i *jA4. 26. 600x600 dpi, a \A4, . 1 6(256) . ,;i.A4, , 64(51 2) , ":|

    :< ! , GDI, 600 dpi, .-*'v:| 8(72) . 1200 dpi, T" 'J4, 600 dpi 24 : ! i4. 600 dpi- 24 ,J. '.

    JLJ

    . 2.17. , Category

  • 2. 91

    CategoryName , . , -

    New field . FieldKind JkLookup, - Field type. Lookup definition , , KeyFields,LookupDataSet, LookupKeyFields LookupResultField. , , ,

    , .

    ,

    , -

    . LookupCache. true, .

    , -

    .

    , -

    .

    ,

    ,

    , .

    , -

    ,- /(Master/Detail). : , , -

    , , -

    . ,

    (Master) , (Detail). - -,

    , , .

    , . , ,

    .

    / . . , ,

    , .

    .

    TDBGrid, - TDBLookupComboBox.

    TDBLookupComboBox, TDBGrid. , TTable (Tablel 2) TDataSource (DataSourcel DataSource2). DataSourcel DataSource2 Tablel 2 . Tablel Category MyData, 2 Items -. , Tablel (Category), 2 , (Items).

  • 92 Borland C++ Builder 6. DBGridl DataSource2. DBLookupComboBoxl

    . ListSource DataSourcel, ListField Category, KeyField CategoryNo. , : DBLookupComboBoxl DataSource( Category), Category 1 ( ), DBLookupComboBoxl CategoryNo ( CategoryNo, ( KeyField), .

    , : Categor Table] DataSourcel :DBLookupComboBoxl, Items 2 DataSource! DBGridl. , Tablel 2.

    2, ;, MasterSource DataSourcel, . < , MasterField Field Link Designer ( ) Available Indexes (). , . ? Items Primary ( ), Category ( ) ItemNDX (- ). Category.

    Descripsc

    __]

    Swat* 1

    J

    (tern ; (Category JDescnpliorv . *|DfMM 64 Mb PC1 33. Infineon 5 1 69 pin. 54 bitDIMM 64 Mb NCP 5DIMM 1 28 Mb PC! 33, POI original 5DIMM 1 28 Mb PC1 33, NCR 5DIMM 1 26 Mb PCI 33. Samsung original 5 :DIMM 1 28 Mb PCI DO. Transcend 5DIMM ?SG Mb PCI 33. Spectek 5DIMM 256 Mb PCI 33. M tec 5

    .QIMM256MbPC133.PQI 5DIMM 256 Mb PCI 33. Samsung original 5 1

    68 pin. 64 bit60pm, 64 bit chip '-68 pin. 64 bit63 pin. 5-1 bit 8 chip ..,;.

    rS16MLE?2V6XN.w |6 chips68pm. 64 bit68 pin. 54 bit68 pin. 64 bit

    LLJ jr1

    . 2.18. (Field Link Editor)

    . 2.19. , .

    TDBGrid ,

    Available Indexes . Detail Fields , -. Category. Master Fields . ,

    Detail Fields Category, Master Fields CategoryNo, Add. Joined Fields (. . 2.18). -

  • 2.

    . MasterFields CategoryNo.

    , , . -

    OnCreate :

    void _fastcall TForml::FormCreate(TObject *Sender){

    DBLookupComboBoxl->KeyValue=Tablel->Field ByName("CategoryNo")->Value;

    } -

    DBLookupComboBoxl. , - . KeyValne DBLookupComboBoxl , CategoryNo. CategoryNo Tablel, .

    , Active true, - . -

    . 2.19. , TDBGrid , - .

    BDE, , , , . (Cached Updates Mode) , , ,

    , .

    ,

    , MB, ,Dell.MB Del2.MB. , . .

    BDE : - (TDatabase), ( TQuery), ( TBDEClientDataSef). .

    ,

    TBDEClientDataSet. - TDatabase (TQuery). TDatabase TBDE-ClientDataSet , - .

    ,

    CachedUpdates true. ( Post) , , ,

    (, cache). ,

    ApplyUpdates, CancelUpdates.

  • 94 Borland C++ Builder 6.

    ApplyUpdates ], , TDatabase, ! , ApplyUpdates CommitUpdate CancelUpdates , , ApplyUpdates CancelUpdati( ).

    ( 6asi ) - TI.

    . , ApplyUpdates .

    , ,

    .

    ApplyUpdates CancelUpdates . ,

    CachedUpdates true. ,

    CachedUpdates false ( ). , UpdatesPending. true, . , , ( ) < UpdatesPending. , CachedUpdates true. UpdatesPending false, < ApplyUpdates, , CancelUpdates . , , .

    TBDEDataSet , - :

    typedef void fastcall ( closure *TUpdateRecordEvent)(Db::TDataSet* DataSet, Db::TUpdateKind UpdateKind,TUpdateAction &UpdateAction);

    typedef void fastcall ( closure *TUpdateErrorEvent)(Db::TDataSet* DataSet, b::EDatabaseError * E,Db::TUpdateKind UpdateKind, TUpdateAction &Upd'ateAction) ;

    , .. ApplyUpdates - . OnUpdateRecord TUpdateRecordEvent , , .

    , -

    ,

    .

    DataSet, OnUpdateRecord . UpdateKind TUpdateKind, ,

  • 2. 95

    , . -

    : ukModify ( ), uklnsert( ) ukDelete ( ). - .

    - UpdateAction - OnUpdateRecord. , UpdateAction TUpdateAction. - : uaAbort ( -), uaApplied ( , . . ),uaFail ( , ),uaSkip ( , ). uaRetry ( ), - OnUpdateRecord. , UpdateAction uaFail. , , , -

    , .

    ,

    OnUpdateRecord UpdateAction uaApplied. - , -

    OnUpdateError. , throw, - . :

    OnUpdateRecord, (, ) EDatabaseError. - . OnUpdateError - .

    , ,

    , . , -

    TDBGrid, TTable TDataS-ource, , , -

    . Tablel Items MyData. , CachedUpdates true. .

    Q (TCheckBox) (TLabef). CBUpdatesPending Caption. : . .

    , , .

    Q () . ButtonApply , ButtonCancel . - , .

    Q - (TLabel). , : LIns : 0, LDel : 0, LMod - : 0, LErr : 0. ,

    , .

  • 96 Borland C++ Builder 6. . 2.20.

    ,

    ;CBUpdatesPending. Post, AfterPost Table! :

    CBUpdatesPending->Checked=Tael->UpdatesPending; Post CBUpdatesPending -

    UpdatesPending.

    * 1r.t. . *

    \

    _

    iLd

    ;

    jftem - - - "1 Samsung 5302 Samsung ML-1^103 Epson EPL-5900L4 Canon LBP-8105 Brother HL-1 240 Mono Lase6 Epson AcuLaser C1 OOOw? EpsonAcul_oserC20GQ8 HP LaserJet 10009 HP LaserJet ?200

    : ; ni'! &:!}-"

    |Cgp - ""- - - 1 -_ijA4. GDI. 2 . 600 dpi, ppm, 1 50 -1

    GDI. 8 . 600 dpi, ppm, 1 %'4, GDI, 2(13) , 600 dpi, 12 ppm. -: :;:4. GDL 600 dpi, 8 ppm, 1 00 . LF :.:.

    '-. 4, 2&, 600x600 dpi, 1 2 ppm, 250 ;. - '..4, , 1 6(256) . 600 dpi/2400 dpi RIT. \

    1 4, , 84(512) , 600 dpi/2400 dpi RIT. , .

    4. 1 , GDI. 600 dpi 1 D ppm, 2 |4. 0(72) . 1?00 dpi, 1 4 ppm, 250

    . 2.20. , , -

    ButtonApply ButtonCancel. ApplyUpdates CommitUpdates. , ,

    - CancelUpdates. CBUpdatesPending, CommitUpdates, CancelUpdates . , -

    , AfterPost. ButtonApply ButtonCancel

    , -

    .

    NDel, NIns, NMod NErr. Unitl.cpp, :

    TForml *Forml; :

    int NDel, NIns, NMod, NErr; 0 (

    ). NDel, NIns, NMod NErr OnUpdateRecord OnUpdateError. . , - OnUpdateRecord UpdateKind , , 1. ,

  • 2. BDE 97 UpdateAction uaApplied. - OnUpdateError 1 NErr, UpdateAction uaAbort.

    bins, LDel, LMod LErr - UpdateLabel. NIns, NDel, NMod NErr Caption . , - . , UpdateLabel ButtonApply ButtonCancel.

    - 2.7 2.8, . 2.20.

    2.5. CachedUpdates11-#ifndef UnitlHdefine UnitlH/ / - .includeincludei ncludeincludeincludeincludeincludeincludei ncludeincludeincludei ncludeinclude/ / . .

    class TForml : public TForm

    published: // IDE-managed ComponentsTDBGrid DBGridl;TTable *Tablel;TDataSource *Data5ourcel;TButton *ButtonUpdate;TButton *ButtonCancel;TCheckBox *CBUpdatesPending;TPanel *Panell;TPanel *Panel2;TLabel *LIns;TLabel *Label2;TLabel *LDel;TLabel *LMod;TLabel *LErr;void fastcall ButtonUpdateClick(TObject Sender)void fastcall ButtonCancelClick(TObject Sender)void fastcall TablelAfterPost(TDataSet *DataSet)void fastcall TablelUpdateRecord(TDataSet DataSet,TUpdateKind UpdateKind, TUpdateAction &UpdateAction);void fastcall TablelUpdateError(TDataSet *DataSet,EDatabaseError *E, TUpdateKind UpdateKind,

    4 . 319

  • 98 Borland C++ Builder 6.

    TUpdateAction &UpdateAction) ;void _ fastcall FormCloseQuery(TObject *Sender, bool &CanClose)

    private: // User declarationsvoid _ fastcall UpdateLabel(void) ;

    public: // User declarations_ fastcall TForml (TComponent* Owner);

    extern PACKAGE TForml *Forml;/ / - - -#endif

    2.6. CachedUpdates

    #include #pragma hdrstop

    #include "Unitl.h"

    #pragma package(smart_ini t)#pragma resource "*.dfm"TForml *Forml;int NDel, NIns, NMod, NErr;

    _fastcall TForml::TForml(TComponent* Owner): TForm(Owner)

    NDel=0; NMod=0;NIns=0; NErr=0;

    void _ fastcall TForml: :ButtonUpdateClick(TObject Sender){

    Tablel->ApplyUpdates() ;Tablel->CommitUpdates() ;CBUpdatesPending->Checked=Tablel->UpdatesPending;

    UpdateLabeK) ;

    void _ fastcall TForml : :ButtonCancelClick(TObject *5ender){

    Tablel->CancelUpdates() ;CBUpdatesPending->Checked=Tablel->UpdatesPending;UpdateLabeK) ;

    void _ fastcall TForml : :TablelAfterPost(TDataSet *DataSet){

    CBUpda te s Pending->Checked=Tabl el ->Updates Pending;

    void _ fastcall TForml : :TablelUpdateRecord(TDataSet *DataSet,TUpdateKind UpdateKind, TUpdateAction &UpdateAction)

  • 2. BDE 99

    UpdateAction=uaApplied;switch(UpdateKind)

    case ukModify:{ NMod++; break; }case uklnsert:{ NIns++; break;}case ukDelete:{ NDel++; break; }

    void fastcall TForml::TablelUpdateError(TDataSet *DataSet,EDatabaseError *E, TUpdateKind UpdateKind,TUpdateAction &UpdateAction)

    NErr++;UpdateAction=uaAbort;

    void fastcall TForml::UpdateLabel(void)

    15->=" : " + IntToStr(NIns);NIns=0;1->11=" : " + IntToStr(NDel);NDel=0;1->=" : " + IntToStr(NMod);NMod=0;LErr->Caption="Oujn6oK : " + IntToStr(NErr);NErr=0;

    void fastcall TForml::FormCloseQuery(TObject *Sender, bool &CanClose)if((Tablel->CachedUpdates) && (Tablel->UpdatesPending))

    swi tch(Application->MessageBox(" ! ?","!", MB_YESNOCANCEL + MB_ICONQUESTION))

    case IDYES:{ Tablel->ApplyUpdates();

    Tablel->CommitUpdatesO ;break;}

    case IDCANCEL:{ CanClose=false;

    break; }case IDNO:{ Tablel->CancelUpdates();

    break; }

  • 100 Borland C++ Builder 6.

    . , RevertRecord , ! UpdateObject - TUpdateSQL, , . . ! , Using the BDto cache updates C++ Builder.

    (Database Desktop ), , .

    , , SQL. BDI .

    ,

    , . AddAlia TSession. Session TSession , , BDE. !TSession . STANDARL(Paradox, dBASE, ) AddStandardAlias TSession, AddAHas. , MyDatal Paradox :

    if ( !Sess ion->IsAl ias("MyData l" ) ) Session->AddStandardAl ias("MyDatal", " D : \ \ M y D a t a l " , "PARADOX");

    AddStandardAlias , , .

    AnsiString : "PARADOX""DBASE", "ASCUDRV" ( ). , ,

    IsAlias TSession. , . ! , true.

    new.

    , delete:

    * Tablel= new TTable(this);d e l e t e ( T a b l e l ) ; ,

    :

    Tablel->DatabaseName="MyDatal";Tablel->TableName="Itemsl.db";Tablel->TableType=ttParadox; . -

  • 2. 101

    FieldDefs IndexDefs . - , Clear. FieldDefs, AddFieldDef, - TFieldDef. , ,

    . Item:NewFieldDef->Name="Item";NewFieldDef->DataType=ftString;NewFieldDef->Size=50;NewFieldDef->Requi red=true; .

    MQToaAddlndexDef, TIndexDef. . ,

    ItemNo:NewIndexDef->Name="";NewlndexDef->FieIds="ItemNo";NewIndexDef->Options=TIndexOptions() ixPrimary ixUnique

    CreateTable. 2.7 - Item, .

    2.7. Item

    Table* Tablel= new TTable(this);if (!Session->IsAlias("MyDatal"

    Session->AddStandardAlias("MyDatal", "D:\\MyDatal", "PARADOX");Tablel->DatabaseName="MyDatal";Tablel->TableName="Itemsl.db";Tablel->TableType=ttParadox;Tablel->FieldDefs->Clear();Tablel->IndexDefs->Clear();TFieldDef* NewFieldDef=Tablel->FieldDefs->AddFieldDef();NewFieldDef->Name="ItemNo";NewFieldDef->DataType=ftAutoInc;NewFieldDef=Tablel->FieldDefs->AddFieldDef();NewFieldDef->Name="Item";NewFieldDef->DataType=ftSt ing;NewFieldDef->Size=50;NewFieldDef->Requi red=true;NewFieldDef=Tablel->FieldDefs->AddFieldDef();NewFieldDef->Name="Category";NewFieldDef->DataType=ftlnteger;NewFieldDef->Requi red=true;NewFieldDef=Tablel->FieldDefs->AddFieldDef();NewFieldDef->Name="Description";

  • 102 Borland C++ Builder 6.

    NewFieldDef->DataType=ftString;NewFieldDef->Size=100;NewFieldDef=Tablel->FieldDefs->AddFieldDef();NewFieldDef->Name="Index";NewFieldDef->DataType=ftString;NewFieldDef->Size=5;NewFieldDef->Requi red=true;NewFieldDef=Tablel->FieldDefs->AddFieldDef();NewFieldDef->Name="Price";NewFieldDef->DataType=ftCurency;NewFi eldDef->Required=true;

    TIndexDef* NewIndexDef=Tablel->IndexDefs->Add!ndexDef();NewIndexDef->Name="";NewIndexDef->Fields="ItemNo";NewIndexDef->Options=TIndexOptions() ixllnique;NewIndexDef=Tablel->IndexDefs->AddIndexDef();NewIndexDef->Name="ItemNDX";NewIndexDef->Fields="Item";NewIndexDef->Options=TIndexOptions() ixUnique;Tablel->CreateTable();delete(Tablel); BDE

    , TSession, TDatabase, TQuery, (Data Controls), .

    BDE .

    , .

    : / , , -, , . ,

    TDataSource TField. , TDataSource ! , -

    , ..

    (Dynamic) (Persistent) . -, .

    , -

    . , (Calculated) (Lookup Fields).

    (Master/Detail), , , .. .

  • BDE()

    TDataba.se TSession

    SQL TQuery TUpdateSQL TBatchMove

    Borland Database Engine(BDE) . - .

    TDataSmirce TField. - -

    BDE. , TDataSet - TQuery. TQuery , . -

    TQuery, - SQL, TSession, TDatabase, TUpdateSQL, TBatchMove, (TDataModule) (TBDECHentDataSet).

    , , .

    ( TDataModule) , . ,

    ,

    .

    , (,, ).

    .

    , TDataSource, TQuery, TDatabase, TSession, TStoredProc .. Data Access,

  • 104 Borland C++ Builder 6. , (BDE, dbExpress, ADCInterBase). , , , , TTimer, TOpenDialog, TSaveDialo^ Dialogs.

    ,

    ,

    - . ] ,

    (-) , .

    , TDataSource , , : !^, ,

    . ,

    TDataSource, . , , ,

    ,

    . -

    , .

    , Data Module File \ New. C++ Builder 6 , +Builder 4 (. . 3.1). / ,

    , (Diagram). C++ Builder Diagram , Object TreeViev .

    . 3.1.

    Umtl cpp UniG.cpp jlUnliltedl 3 J ii

    li J1 Modified 'Insert :\Umt2 '-1 | h ADiagretri./

    . .2. (Diagram), , - Master/Detail

  • 3. BDE () 105

    , -

    ,

    . Include Unit Hdr File. ->__, ,DModl->Tablel. - . ,

    ,

    ,

    Diagram . . 3.2 , Master/Detail Category Items.

    , : OnCreate OnDe-stroy. TNotifyEvent. . OnCreate -, , .

    OnDestroy : , - ..

    -

    .

    '

    TDatabase BDE

    TDatabase. TDatabase ,

    DatabaseName . , TDatabase,

    . TDatabase - .

    , MyData - TDatabase, - , BCDEMOS, TDatabase. TDatabase Database, TDBDataSet.,

    Edit] TDatabase :

    Editl->Text=Tablel->Database->DataSetCount; , MyData Tablel

    2, Editl - 2.

  • 106 Borland C++ Builder 6.

    , BI TDatabase. ,

    , ,

    .

    TDatabase TDatabase >

    (alias). ! ( SQL Explorer BDE Administrator), , AliasName. DatabaseName DatabaseName .

    . ^

    , DriverName, . , STANDARD ( Paradox dBASE), INTRBASE (: InterBase) . . , , !DatabaseName , ( TQuery) . AliasName - , , AliasName DriverName . .

    DriverName, , TDatabase. Params, ( TStrings). Params =. , > (. . ) , Params , - .

    -

    . STANDARD (Paradox dBASE)INTRBASE MSACCESS :

    PATH=d:\MyData //STANDARDSERVER NAME=d:\IBase\MyIBase.gdb //INTRBASEDATABASE NAME=d:\Data\Northwind.mdb / / M S A C C E S S

    , .

    , Params , ,

    , . .

    ODBC SQL Links, BDE. , SQL, , , - .

  • 3. () 107

    . 3.3. Params TDatabase (Value List editor)

    Params, TString, (Value List editor). Params. - , . Key , Value (.. 3.3). Code Editor..., , ,

    ( =, , ).

    TDatabase , . , -

    . . 3.4 - TDatabase photodatabase.gdb INTRBASE, Temp D:. TDatabase Name, Alias Name Driver Name. TDatabase DatabaseName, AliasName DriverName. DatabaseName - Name ( ). ( Alias Name), ( Driver Name), , .

    j-jMyOOBEammeler overridesSERVER NAME'd\Temp\photodatabase gdbUSER NAME-SYSDBAP*SSWORD=rrmsterkey

    Login prampt 17 beep inactive connection

    . .4. TDatabase photodatabase.gdb INTRBASE

  • 108 Borland C++ Builder 6.

    TDatabase MEMO, c< . ,

    (Parameter overrides), Params 061 TDatabase. (, ). , :

    . , ; (TDatabase). Driver Name, Defaults. Parameter ovenides , .

    (, , ,

    .

    .

    Login prompt Keep inactive connection. LoginPrompt KeepConnection . LoginPrompt , .

    true, false, . LoginPrompt false, :, Params ;TDatabase ( ).

    , TDatabase ' .

    TDatabase , (. ). TDatabase ! Connected. Connected true , false, . , Opei Close .

    TDatabast ,

    ( DatabaseName ). } , , ! : ? - ? KeepConnection true, , () . - TDatabase . ! ,

    .

    TDatabase , . DataSets DataSetCount - (. . ) ,

  • 3. () 109

    TDatabase. . DataSetCount - , a DataSets - ( TDBDataSei). - , DataSetCount DataSets:

    Memol->Clear();for (int i = 0; i < Databasel->DataSetCount; i++)

    {TTabTe* MyTable;MyTable=dynamic_cast(Databasel->DataSets[i]);if(MyTable) Memol->Lines->Add(MyTable->TableName);}

    ,

    (Memo!), TDatabase (Database!) - . .

    , Memol. , Database!. - * (. . , ). , Memol , .

    Locale , TDatabase. . IsSQLBased , TDatabase ODBC SQL Links. InTransaction . true , . -

    , .

    ,

    TDatabase - , TDatabase . HandleShared. TDatabase , true.

    {Transaction) ( ). - , ,

    . , , -

    , , , -

    , , .

    , , -

    , . -

    . -

    , , ,

    ( ). ( ),

  • 110 Borland C++ Builder 6.

    ( ). - ().

    . -

    />- ( ), . .

    Q (Atomicity). - , , -

    .

    Q (Consistency). - .

    Q (Isolation). (-) .

    LI (Durability). - , , . .

    BDE . , -

    , .

    ,

    .

    (, , ), - , TDatabase.

    ( ) TDatabase . , , StartTransaction. - Commit , - Rollback . try...catch. . StartTransaction TDatabase. try . Commit . - , catch Rollback . ,

    (cached updates):Databasel->StartTransaction() ;try{

    Tablel->ApplyUpdates() ;Databasel->Commit() ;

    }catch (...){

    Databasel->Rollback() ;throw;

    }Tablel->Commi tUpdatesQ ;

  • 3. ()

    , Rollback th-row . ,

    CommitUpdates, . Tramlsolation TDatabase.

    TTranslsolation. :

    tiDirtyRead . , .

    Q tiReadCommitted SQL. (committed) .

    Q tiRepeatableRead' . , .

    STANDARD (Paradox, dBASE), tiDirtyRead. (ASCIIDRV) .

    GetTableNames GetFieldNames TDatabase. :

    void fastcall GetTableNames(Classes::TStrings* List,bool SystemTables = false);

    void fastcall GetFieldNames(const AnsiString TableName,Classes::TStrings* List);

    GetTableNames (TStrings*). TStrings , , TDatabase. (. . Connected false). SystemTables . - true, . (, Microsoft Access, Interbase .) (). SystemTables , .

    GetFieldNames . ( AnsiString) . TString* ( ). .

    , GetTableNames GetFieldNames, .

    ( TListView). ( File->New->Data Module) TDatabase. , DModl ( Name). Database! MyData ( - ).

  • 112 Borland C++ Builder 6. Database! Forml, ] . Include Unit Hdr MI File. , (Unit2) . (Unitl) erpi ^include "Uni2.h". , .

    ListViewl, , . ,

    OnCreate:

    void fastcall TForml::FormCreate(TObject *Sender){

    DModl->Databasel->GetTableNames(ListBoxl->Iterns);ListBoxl->ItemIndex=0;DModl->Databasel->GetFieldNames(Li stBoxl->Iterns->Strings[ListBoxl->ItemIndex],ListBox2->Items);

    } GetTableNames,

    Items ListBoxl , Database!'. ( 0) GetFieldNames, Items ListView2 , (. . , ). , Database! -> DModl.

    Category

    Suppliers

    EmployeeNoLNomeFNameMNomeHireDtfeFireDetaDescriptionPhotoBirthday

    I

    . .5. GetTableNames GetFieldNames

    ListView. ListViewl. OnClick TListView. 1

    , ; . OnClick ListViewl :

    void fastcall TForml::ListBoxlClick(TObject *Sender){

    DModl->Databasel->GetFieldNames(ListBoxl->Items->Strings[ListBoxl->ItemIndex] ,ListBox2->Items) ;

  • 3. BDE () 113

    , ,

    (. . 3.5).

    , -

    :Access violation at address 00407C59 in module 'PROJECT! F.XE'. , OnCreate DModl. . , -

    . Options Project. Project Options Forms. (Auto-create forms). - Form? - , FormJ. - ,

    DModl . .

    Project View Source. ^Project).. CreateForm Application. , :

    Application->CreateForm( classid(TDModl), &DModl);Appl1cation->CreateForm( classld(TForml), &Forml);

    TDatabase TDatabase ,

    . -

    TDatabase OnLogin. BeforeConnect, AfterConnect,BeforeDisconnect AfterDisconnect TCustomConnection, - TDatabase. TNotifyEvent, OnLogin :

    typedef void fastcall ( closure *TDatabaseLoginEvent)(TDatabase* Database, Classes::TStrings* LoginParams);

    OnLogin , , LoginPrompt true ( ). - ,

    , , -

    , Params TDatabase. LoginParams, TStrings. , OnLogin INTRBASE:

    void fastcall TForml::DatabaselLogin(TDatabase *Database,TStrings *LoginParams)

    {LoginParams->Add("USER NAME=SYSDBA");LoginParams->Add("PASSWORD=masterkey");

  • 114 Borland C++ Builder 6.

    OnLogin , Params , .

    BeforeConnect AfterConnect . -

    - , . ,

    ,

    BeforeConnect Params TDatabase. , .

    , .

    void fastcall TForml::DatabaselBeforeConnect(TObject *Sender){

    Databasel->Params->Clear();Databasel->Params->Add("SERVER NAME=" + DBName);Databasel->Par