Разработка приложений баз данных в среде Delphi. Часть 1: Методическое пособие

  • Published on
    08-Dec-2016

  • View
    233

  • Download
    11

Embed Size (px)

Transcript

  • . ., . .

    Delphi. I.

    4 / 4 /

    , 2002

  • 2

    4 - . - Delphi Windows 9X/NT/2000. Delphi - - Windows Object Pascal, ( ). - Delphi (- ) , , -, . ( Delphi Clarion, ++ Builder, Power Builder , , Visual Basic.) Delphi - , -. - , , Microsoft Access Paradox. . : , , . - Delphi . - , , - . [1-3]. SQL [4]. [1,2,5] - InterBase. - Delphi [6-9], - [10-12]. - Delphi . , 1 4 - , SQL, Delphi. - Delphi 4.0-6.0. , , Web- - www.main.vsu.ru/~pmmtkiar.

    http://www.main.vsu.ru/~pmmtkiar

  • 3

    1.1. Delphi : (DataBase

    Desktop, ReportSmith, DataBase Explorer, WISQL). Delphi . . - , , , .. Delphi - . , -, - . , - BDE (Borland DataBase Engine, - ). BDE Delphi. BDE Windows. BDE - (DLL). BDE , , SQL . , BDE, IDAPI. BDE , . BDE. . BDE - Paradox (*.db), dBase (*.dbf), ASCII, FoxPro, Access. , BDE - SQL- InterBase, Oracle, Informix . BDE . Delphi 5 Borland SQL Server InterBase 5, -/ , -. BDE . (Alias, ) - - , . , Delphi DBDEMOS - PROGRAM FILES\COMMON FILES\BORLAND SHARED\DATA\, - . - , . : - , - , , DB Explorer -

  • 4

    BDE Administrator. BDE idapi.cfg. Windows NT/2000 idapi.cfg . Paradox Inter-Base. Paradox (*.db), InterBase *.gdb. : Paradox FoxPro, , Data Base Desktop (DBD) DB Explorer, Delphi, InterBase Windows ISQL. , DBD 1) 2) InterBase. DBD , - . DB Explorer ( SQL Explorer) SQL- . InterBase, .. InterBase, . ( DB Explorer .) InterBase Windows ISQL, ( , , , , .).

    1.2. Delphi , . - 4 : Data Access ( ), Data Con-trols ( Standard Additional, ), Midas ( ), InterBase ( - , InterBase - , BDE). . 1.2.1. DataAccess , - , .. . , . .

  • 5

    DataSource . -

    . Table . -

    (). Query .

    SQL. StoredProc . , -

    , , InterBase, Oracle, MS SQL Server . .

    DataBase .

    Session . BatchMove .

    , , - Paradox InterBase.

    UpdateSQL , - SQL- .

    NestedTa-ble

    . ,

    1.2.2. DataControls DBGrid .

    DbNavigator .

    , -.

    DBText ( ) - .

    DBEdit .

    DBMemo . - (Memo).

    DBImage .

    DBListBox . - , , .

    DBComboBox . Com-boBox Standard, .

    DBCheckBox . . DBRadioGoup .

    .

  • 6

    DBLookU-pListBox

    . DBListBox , , - , DBListBox - .

    DBLokUp-ComboBox

    . DBComboBox .

    DBRichEdit RTF-. , -.

    DBCtrlGrid DBChart ,

    1.2.3. , , , - , . - , - . TTable ( ), TQuery ( SQL- ) TStored-Proc ( ). - , TDataSource, TTable TQuery - ( ) - . -, -, ( , - ., ). TTable, TDataSource TDBGrid. . TTable - - ( ). , - , TTable, : DataBaseName, String - ,

    , . TableName: TFileName - .

    TTable BDE. Name - . -

    Table1. Active, Boolean - Active True -

    . - False. : IndexName: String - , IndexFieldNames: String - .

    . 1. :

    , .

  • 7

    2. , - .

    3. IndexName , IndexFieldNames - , , .

    4. , IndexFieldNames - , .

    5. - , . MasterSource: TDataSource - TDataSource, -

    . MasterFields: String - ,

    . Filter: String - . Filtered: Boolean - True . -

    False. TTable (DataBaseName TableName), . - TDataSource c TTable. DataSet: TDataSet ( Name) - TTable. TDBGrid ( ) - . DBGrid , - DataSource TDataSource, - . TDataSource TDBGrid - , , . - . TDBGrid - , ( Table), - - .

    1. .

    1. . TTable TDataSource. Data Access - . - : - , .

    2. Table1 Da-taBaseName. DBDemos.

    3. TableName DBDemos. , TableName . , , country.db (- ).

    4. DataSource1. Table1, Table1 DataSet.

  • 8

    5. TDBGrid ( Data Control - ). DataSource1, DataSource1 DataSource. .1.

    6. Active Table1 True. (DBGrid).

    7. . 8. Active False, OnCre-

    ate Table1.Open. . , 8.

    . 1

    , . TDBEdit ( Data Control). - TDBEdit, . - : DataSource ( - - ) DataField ( - ). ( Graphics, Blob) (- Memo) TDBImage TDBMemo, -. TDBNavigator. . , - , , - . DataSource DataField.

  • 9

    2 () biolife.db, . TDBGrid TDBEdit, TDBImage, TDBMemo TDBNavigator. TLabel . - .2.

    .2

    1.3. . - - , . - . , , - - , . , CustNo. CustNo . TTable - MasterSource ( DataSource ), MasterField ( ), Index-FieldNames ( , ). , - . - , .

  • 10

    3 , - - customer.db orders.db.

    1. TTable, TDataSource TDBGrid ( ) DBNavigator .

    2. customer.db orders.db, . , MasterSource, MasterField, IndexFieldNames . - . 3.

    3. . 4. Form Wizard

    ( DataBase).

    . 3

    4 (). . , . Cus-tomer.db , Orders.db, , , Items.db. Items - . , - . Orders Items OrderNo.

  • 11

    1.4. - . - -. 2.0, Delphi - , - DataSet DataSource - (Data Module). , . - , . M - TQuery, TTable. - [2], , - , . , - , ( ). . (Data Module) (Unit) - . - , Unit.

    5 - - 1.

    1. . File | New Data Module. - . TTable TDataSource - . , . - ( Name) - CountryTables.

    2. . , - Unit2, , TDataModule, TForm. File | Save As - CountryModule. CountryModule.pas Coun-tryModule.dfm.

    3. File | Close All. . , - Country.db. , .

    1. File | New Application. 2. Project | Add to Project...

    . - , File | Use Unit CountryModule. Use Unit1 .

  • 12

    3. TDBGrid TDataSource, CountryTables.DataSource1. . - 1-4.

    2. Delphi . , TTable, - . (Record- ). TQuery, , - , SQL. - SQL- , . - TDataSet ( ) - TDataSet , . , , , , - , TTable. , - , , . 2.1. ? - , ( , . .2.2). - TField (- ). , Address Cust ( . .2.3) with Table1 do begin Edit; // FieldByName(Address).value:=;// TField Post; // end; TField ( ) , , . -, Value Variant , DisplayLabel , DisplayFormat . . (Variant , - . Variant , - . - . . [10].) TField -, - (TStringField, TBooleanField, TDateField, TFloatField, TIntegerField .). .

  • 13

    2.1.1. - TField . . TField

    , . - . , - .

    . TField ( ) . - , .

    , .. - . - , .

    2.1.2. . , -, , , - . , Country Density ( . ). Fields Editor ( ). , - . TField - .

    6. .

    1. , TTable, TDataSource TDBgrid. . DataBaseName Ta-bleName TTable DBDemos Country.db, . TDBNavigator TDataSource.

    2. Table1. , - , .. TField .

    3. - Add Fields. Available Fields . , , , Name, Area, Population. Ok.

    4. New Field. - - Density - Float, Cal-culated. k .

  • 14

    5. , - TField - . , . - . Table1Density. - : DisplayLabel - , DisplayFormat - 0.000. - .

    6. OnCalcFields TTable ( Value TField):

    procedure TForm1.Table1CalcFields(DataSet: TDataSet); begin Table1Density.Value:=Table1Population.value/Table1Area.Value end;

    .4

    7. Active True. . -

    . 4. 2.1.3. TDataSet function FieldByName(const FieldName: String): TField; TField, , . , - - TField . , - (, .) TField. , Address Cust , : Table1.FieldByName(Address).DisplayLabel:=; , FieldByName, . : + , , Table1Address.DisplayLabel:=;

  • 15

    Value Variant, AsNNN NNN. Value :

    string TstringField, LongInt TField, Double TField, Boolean TbooleanField TdataTime TdateField, TDateTimeField, TTimeField

    - - , , TEdit, . - Value , , -, Kolvo Edit1.text:=Table1.FieldByName(Kolvo).Value; Edit1.text:=IntToStr(Table1.FieldByName(Kolvo).Value); Value , , , , ( . ), . , - Table1.FieldByName(Kolvo).Value:=10; Table1.FieldByName(Kolvo).Value:=Edit1.text; // 10 Table1.FieldByName(Kolvo).Value:=StrToInt(Edit1.text);//10 Table1.FieldByName(Kolvo).Value:=Edit1.text; // 01.01.80 Table1.FieldByName(address).Value:=100. AsString: String, AsInteger: integer, AsFloat: Double, AsDateTime: TDateTime, AsCurrenty: Currenty, , ( ). AsString TField. - . , Edit1.text:=Table1.FieldByName(Date).AsString; Table1.FieldByName(Date).AsString:=Edit1.text;//10.10.89' : FieldByName TField, Value

    Variant, Value ( ).

    - TField, , Value .

    Table1Kolvo.Value := Edit1.text; (, ). Table1Kolvo.Value := StrToInt(Edit1.text);

  • 16

    Table1Kolvo.AsString := Edit1.text; , property FieldValues [F: string]: variant, , , Table1. FieldValues [Address]:=; Table1[Address]:=; FieldValues , Value: Variant. 2.1.4. - . TFieldDefs , - , - . TFieldDefs property FieldDefs: TFieldDefs, TFieldDefs. TFieldDefs: property Count: integer; TFieldDef,

    . property Items[Index: Integer]: TFieldDef;

    TFieldDef. Index 0 Count-1. TFieldDef: property DataType: TFieldType; , -

    . property FieldNo: Integer; . property Required: Boolean; True, -

    . property Size: Integer; . -

    . ( TField) Object Pascal . 7 1. TTable ( T1), TDataSource, TDBgrid. T1 - Active True. - TComboBox CB1 TLabel TEdit. 2. . OnCreate : procedure TForm1.FormCreate(Sender: TObject); var i: integer; begin // for i:=0 to T1.FieldDefs.Count-1 do cb1.Items.add(T1.FieldDefs.Items[i].Name);

  • 17

    end; OnChange CB1: procedure TForm1.CB1Change(Sender: TObject); begin // Edit1.text :=T1.FieldByName(CB1.text).AsString; Edit2.text := T1.FieldByName(CB1.text).ClassName; // if VarType(T1.FieldByName(cb1.text).value)=VarDate then Edit3.text :='TDate' else if VarType(T1.FieldByName(cb1.text).value)=VarInteger then Edit3.text :='VarInteger'

    else if VarType(T1.FieldByName(cb1.text).value)=VarDouble then Edit3.text :='VarDouble' else if VarType(T1.FieldByName(cb1.text).value)=VarString then Edit3.text :='VarString' end; 3. , . 5. 4. , - ( FieldDefs: TFieldDefs ), - ( Fields [index: integer]: TField ). , - TField, FieldName: string; , , Name. - , FieldCount: integer; 5. , - . (: TSession.) TSession . Session: TSession , - , . Session , , .. () TSession, - . Session , , [1] ( TSession - ). TSession: SessionName: String (

    DataSet, , TTable), KeepConnections: Boolean - ,

    , ,

  • 18

    NetFileDir: String - , PDOXUSRS.NET, BDE,

    PrivateDir: String - . Active (). - True, - . : Procedure GetAliasNames (List: TStrings) ; Procedure GetAliasParams (const AliasName: String; var List:

    TStrings) List ; procedure GetTableNames(const AliasName, Pattern: String; Exten-

    sions, SystemTables: Boolean; List: TStrings) - List AliasName , Pattern;

    , TSession , , , : function GetDBPath(const Alias: string): string; var AllSt: TStringList; i: integer; S: string; begin Result:=''; if Length(Alias)0 then begin AllSt := TStringList.Create;...

Recommended

View more >