894

Click here to load reader

Марков - Delphi 2005 для

Embed Size (px)

Citation preview

Delphi 2 0 0 5

- - 2005

681.3.068+800.92Delphi2005 32.973.26-018.1 27 . ., . . Delphi 2005 .NET. - .: ., 2005. - 896 : . > ISBN 5-94157-701- Borland Delphi 2005 .NET. .NET Delphi, Delphi #. Windows Forms VCL.NET. . ADO.NET BDP.NET, VCL.NET, Borland DataBase Engine .NET, dbExpress .NET, InterBase Express .NET, dbGo . , MDA. . 681.3.068+800.92Delphi2005 32.973.26-018.1 : . . .

27

02429 24.07.00. 28.07.05. 700'/ 16 . . . . . 72,24. 3000 . 270 "-", 194354, -, . , 5. - 77.99.02.953..006421.11.04 11.11.2004 . . " " 190005, -, ., 29

ISBN 5-94157-701-

. ., . ., 2005

, "-". 2005

. 1. Delphi 2005 Delphi # Visual Basic .NET VCL Delphi .NET

19 2121 22 24 24 25 26 27 29 30

'.

2. Microsoft .NET .NET ' ? ? ? , . (Assembly) .NET (Common Type System) Common Language Specification

3133 34 35 37 39 40 41 43 44 45 46 46 46 ....46 47 47 47 47 47

.NET Framework Common Language Runtime .NET .NET Framework SDK ASP.NET ADO.NET Windows Forms 3. Delphi - , Abstract SealedStatic

:

48 48 51 51 52 52 53 53 54 54 54 57 57 57 60 61 62 62 63 65 65 656(>

Virtual Dynamic Override Delphi

,

66 67 69 70 71 72 72 74 76 76 78 79 80

4. # Static Virtual Override

8183 86 88 89 89

Abstract Sealed # / 91 92 93 95 95 96 96 96 97 99 101 103 105 108

:

5. .NET Delphi (Common Type System) (Common Language Specification) , , .NET Delphi Windows Forms ADO.NET ASP.NET ; '

109110 110 111 111 112 112 112 116 119 120 120 121 121 121

6. Welcome Page Sync Edit

123123 124 125 126 127 128 129 130 130 131

. WINDOWS FORMS 7. Control, UserControl, Form (Controls) (Components) (Common Dialog Boxes).:

133 135135 137 140 140 141 141 141 146

:

\

8. Label LinkLabel TextBox Button Panel CheckBox RadioButton ListB ox ComboBox CheckedListBox PictureBox , imageList HScrollBar VScrollBar NumericUpDown DomainUpDown DataTimePicker MonthCalendar Timer

147147 149 150 ...152 154 155 158 160 163 165 168 170 171 172 173 175 177 178 180

9. Drag and Drop

181181 188 189 190

10. MainMenu ContextMenu ToolBar

191191 194 197 201

11. OpenFileDialog SaveFileDialog.. Print Dialog, PrintDocument, PageSetupDialog PrintPreviewDialog FontDialog ColorDialog ^

203203 204 207 209 213 214 215

12. StatusBar ProgressBar TrackBar ToolTip Notifylcon HelpProvider ErrorProvider

217217 220 222 224 224 226 228 230

13. Font TextBox ComboBox ListBox DomainUpDown RichTextBox MonthCalendar DateTimePicker

231231 231 232 234 235 235 238 239 240 242 245 247

:

.i

14. File Filelnfo Directory Directorylnfo StreamReader

249249 250 255 257 258 260 262 264 264

8 StreamWriter FileStream MemoryStream /

266 268 270 272 273 273 275 276

15. , , ICollection /List [Enumerable [Enumerator CollectionBase

277278 279 280 280 282 282 283 283 284 285

16. TreeView TreeNode ListView ListViewltem ListViewSubitem

287288 293 296 302 304 304

17. XML XML XML , . IDOMNode nodeType, nodeName nodeValue , IDOMDocument , DOM DOM .NET XmlNode XMLElement

;

305305 308 310 311 312 313 314 316 317 V319 .320 320 322 323 328

XMLAttribute XMLDocument 329 329 334

III. VCL.NET 18. TApplication.

335 337337 345 351 352 355 356 357

19. . TActionList , , Edit Search Help File Dialog Window Tab List Internet Format Dataset Tools TActionManager

359360 361 364 367 368 369 371 372 373 376 376 376 377 377 377 377 377 379 380 380 380 381 383 384 387

,

20. TStrings TSiringList

389390 390 391

10 TList TCollection TCollectionltem

399 399 402 406 407 408 408

21. TStream THandleStream TFileStream TMemoryStream \ TStringStream 22. Delphi TFont TBrush TCanvas TGraphic TPicture TMetafile / TBitmap TImage TClipboard TScreen

411411 412 414 416 416 417 419 419 419 421 422 422 427 429 431 432 433 435 436 437 439 441

IV. .NET 23. .NET

443 445446 450 450 451 452 452 453

11

24. ADO.NET ADO ADO , , SQL .' .... , SQL Label LinkLabel Button TextBox Checkbox RadioBntton ComboBox ListBox CheckedLislBox TreeView ListView DateTimePicker , TrackBar, ProgressBar, VScrollBar HScrollBar NumericUpDown DomainUpDown GroupBox StatusBar RichTextBox

455457 459 460 464 465 470 472 472 476 477 480 483 489 491 495 498 499 501 502 503 ..504 510 513 515 519 521 525 530 532 532 532 532 533 533 533 534 534 534 534 534 535 535 535

12 DataGrid

535 535 537 538 538 539 539 540

25. BDP "" BdpCornmandBuilder

543544 547 548 549 551 554 555 556 558 560 562 563

V. VCL.NET 26. VCL.NET TParams TParam TField

565 567568 568 574 575 577 580 581 582 582 583 584 586 589 590 592 595 595 598 600

.... TDataSource

13 604 605 607 608 608 609 610 612 615 616 617 619 620

27. BDE.NET BDE BDE TBDEDataSet TDBDataSet TQnery TStoredProc

621622 626 635 640 640 645 646 652 654 656

28. dbExpress .NET dbExpress TCustomSQLDataSet TSQLDataSet TSQLTable TSQLQuery TSQLStoredProc TSimpleDataSet dbExpress ISQLDriver ISQLConnection ISQLCommand ISQLCursor

657....658 659 660 665 668 669 670 672 673 674 675 676 679 685 685 685 687 688

i

14 dbExpress dbExpress

689 691 692

29. InterBase Express .NET InterBase Express TIBDatabase TIBTransaction XSQLDA XSQLVAR TIBTable i TIBQuery TIBStoredProc TIBDataSet TIBSQL : TIBDatabaselnfo TIBSQLMonitor

693694 694 699 703 705 706 707 708 710 710 712 715 717 717 719 720

\ ,

30. dbGo

,

721721 722 723 723 728 731 734 734 735 736 736 737 739 740 742 743 743 744 745 746 747 748

dbGo ADO TADOConnection ADO ADO ADO TCustomADODataSet ADO TParameters TParameter

TADODataSet TADOTable TADOQuery TADOStoredProc ADO ADO

15 749 750 751 751 752 754 754

.' ,

VI. VCL.NET 31. -

757 759760 763 767 768 768 769 770 771 ,771 771

32. DataSnap Delphi Delphi 2005 DataSnap TDCOMConnection - TSimpleObjectBroker TLocalConnection TSharedConnection TConnectionBroker

773774 776 777 778 779 779 781 781 783 ,...783 784 785

33. TClientDataSet -

787788 789 790 792 794 795

16 BLOB XML - ""

797 .....798 799 799 800 802 804 804 805 806 809 814 815 816 818

34. XML XML XML Delphi XML Mapper XML XML

819819 820 821 822 823 824 825 826 827

VII. 35. MDA ,

829 831832 v.833 834 834 835 837 838 839 839 841 841841

PIM PSM UML OCL XMLHXMI

842

17

36. Model View UML - \ - , - ReferenceHandle VariableHandle ExpressionHandle OclVariables OclPSHandle Drag and Drop '. - - -

843844 845 850 850 851 855 857 858 859 859 861 862 862 863 865 865 866 867 868 871 872 873 874 874 875 876 877 878 879 879 880 .882 883 883 884 887 889

,

891

I 1. Delphi 2005 2. Microsoft .NET

3. Delphi 4. # 5. .NET Delphi 6.

1

Delphi 2005 , Delphi 2005, , , "". , Delphi .NET Microsoft. , Help | About Borland Developer Studio, , Borland Developer Studio for Microsoft Windows. , Windows, . , Delphi 2005 Win32 .NET, ( , ASP.NET, . .). , Visual Basic .NET. , , , N 3? , . , Delphi 2005, , Delphi.

. Basic, Pascal , . Delphi 2005 .

22

I.

( ) , , . . , Delphi (Eiffel, Pascal), . . . , . , . , . , Delphi 2005. " " Visual Basic C++, 90 % . Delphi, C++ , , . Microsoft .NET , , , , "" . #. , , Delphi 2005 . # Visual Basic. , Delphi 2005 : Delphi, C# Visual Basic. , . .

Delphi Delphi Delphi, Delphi

1. Delphi 2005

23

. . Delphi 2005 Delphi. Delphi 6. Delphi Object Pascal. Delphi 6 Borland , Object Pascal. Borland ? , () Delphi Object Pascal, , Pascal. Delphi , , . . , - () , Delphi, . Pascal Object Pascal. . . , COM (Component Object Model, ), . Object Pascal , , . . , . Object Pascal Delphi. Delphi Win32 .NET. Delphi (Visual Component Library, VCL). , Win32, , . Delphi .NET. Win32 .NET, VCL, . Delphi .NET. , , , .NET.

24

I.

VCL , .NET .NET. Delphi 3.

# # NET. (Scott Wiltamuth) (Anders Hejlsberg). # , , .NET. , .NET . , . . # C++ Java. , . . # (, "::") (, ). Pascal. # . Delphi # .NET. # 4.

Visual Basic Visual Basic , . . . , , Visual Basic. ,

1. Delphi 2005

25

Visual Basic, C++, # Delphi. Visual Basic , , . , Internet, Web- . Delphi 2005 Visual Basic, .

Delphi 8 ( ): Win32 .NET. Win32 , , . , . , . Win32 - . , () . "" : , , , . .NET 64- , , , , Intermediate Language (IL). .NET , . , Win32. . . , . .NET Win32.

26

I.

, Delphi 2005 . Delphi #. . , # .NET, a Delphi . Delphi 2005 . 1.1. 1.1. Win32 Delphi # .NET

+ -

+ +

.NET 2.

.NET VCL , Delphi 2005, . Delphi 2005 VCL Win32 Delphi (. 1.2).

Win32 VCL. , .NET. : VCL , .NET. , VCL .NET , . . .NET . , VCL Delphi 7 Delphi 2005 ( intraWeb ) , .NET ASP.NET. Delphi 2005 VCL .NET Delphi (. 1.2).

VCL .NET Delphi 2005 VCL.NET. . VCL.NET VCL .NET . -

1. Delphi 2005

27

VCL VCL.NET. Internet- (, WebBroker) . IntraWeb. Delphi 2005 .NET Delphi # (. 1.2).

"" .NET . , Windows Forms, .NET. .NET , , . . 1.2. Delphi 2005 Win32I

.NET VCL + (VCL.NET) .NET +

VCL Delphi #

.NET -

+ -

+

Delphi , Delphi 2005. , , Delphi 2005, . , ! , , "" (. ). -, , Delphi 2005, . : , , , . , , Win32, .NET . .

28

I.

, Delphi 2005. . 1.3 , , . . 1.3. Win32 .NET Win32 Delphi VCL VCL.NET Windows Forms ADO.NET ASP.NET IntraWeb WebBroker WebSnap

.NET Delphi # -

+ -

+ + + + + + + +

+ + + + + +

+ + + + + +

VCL, VCL.NET Windows Forms Windows, (. . " .NET u VCL" ). . 1.3 , . ADO.NET , .NET ADO (ActiveX Data Objects), .NET. , ADO .NET , .

1. Delphi 2005

29

Delphi , ADO.NET. , dbGo, dbExpress . . Win32. , . , .NET ADO ADO.NET, ADO Win32 dbGo. , , ADO, . ASP.NET Internet, .NET. V. IntraWeb, WebBroker WebSnap , Internet- (Web- Web-) Win32. ASP.NET. , , . .NET , . . .NET, Win32. ECO (Enterprise Core Objects) MDA (Model Driven Architecture). UML, . MDA VI. Delphi 2005 . , .

.NET , Delphi 2005, . -

30

I.

Delphi #. , , .NET, Win32. VCL Win32 VCL.NET . ( Web- Web-) VCL.NET. , , . . .NET . , , 3. , uses . internet-, . , , Win32-Bepc^x Delphi, . VCL.NET intraWeb, "" .NET ASP.NET. internet- .NET V. VCL Win32 Windows Forms .NET . VCL ( Windows Forms .NET ) , - . , , .NET . "Hello, World!", . . .NET showMessage . Windows Forms .NET .

Delphi 2005. , Delphi 2005 .NET, , , . Delphi, C# Visual Basic. Delphi 2005 ( ): .NET Win32. , .

2

Microsoft.NET13 2002 Microsoft () .NET Framework Visual Studio .NET. .NET. , . , Windows .NET, - , . , Microsoft , . Windows .NET . .NET Windows, . .NET , , . .NET dll, Windows. .NET , Web- XML Web- . ( , Pocket PC, . .), .NET Framework . , , , .

32

I.

, Microsoft, .NET : .NET Framework , .NET . ; Visual Studio .NET .NET. , , Delphi 2005; Windows .NET Server 2003 4 32- , .NET; .NET: ASP.NET, ADO.NET, Windows Forms . . , .NET Microsoft Visual Studio .NET #. Borland , , 12 2002 ( Microsoft .NET, , ) .NET. Delphi 7, .NET. Delphi 7 for .NET Preview. , DCC1L Delphi, Microsoft Intermediate Language (MS1L). .NET Framework. Delphi 8, . , .NET . , Delphi . Delphi 8 , Borland, . Delphi 2005. , . Delphi 2005 . .NET, ,

2. Microsoft .NET

33

. , .NET, , .NET Delphi. , : Common Type System; ; Microsoft Intermediate Language (MSIL); .NET Framework; Common Language Runtime; Common Language Runtime; Just In Time (JIT); ASP.NET; ADO.NET; Windows Forms.

.NET .NET (. 2.1), .NET Framework . , .NET, . .NET ( MSDN), . , , " ", " ", "" . . , .NET , . .NET , .NET Framework. .NET XML Web-. , . .NET, : 2 270

34

I.

.NET, .

(ASP.NET, ADO.NET)

.NET Framework

Windows .NET Server 2003 . 2.1. NET

? " .NET", " .NET" ".NET Framework". .NET , .NET, , , , , . . . Microsoft Visual Studio .NET. , Borland. .NET Framework (. ) . .NET Windows .NET Server 2003. , .NET Building Block Services , . .NET .NET . , .NET, , .

2. Microsoft .NET

35

.NET Framework .NET, , .NET. , " .NET" , .NET Framework. , .NET Framework .NET. 80 , . .NET, .NET Framework. .NET , , . . , MS1L. , , Windows API GUI, , . .NET XML Web-, .NET Framework. .NET Web-, (, ) .

? : " , , ?". . , Web- Windows-, , . . . . . , , . . .NET . , .

36

I.

. .NET, , . , "" . . .NET , MSIL, .NET. MSIL. .NET . , , Windows, Linux, . .NET , MSIL, , . . .NET CLR .NET Framework. . . . ASP.NET "" Web-, Web , Windows. . ADO.NET . . .NET , . . . . , . . .NET , . " ", DLL Hell, , , .

2. Microsoft .NET

37

. .NET , . .NET . .

? , , .NET, , . (. 2.2). .

Delphi, C#, C++, VB

MSIL

MSIL

CTS

CLS

CLR

.NET Framework. 2.2. .NET

, MSIL. -

38

I.

Microsoft #, C++, Visual Basic. Borland Delphi 2005 Delphi # DCCIL. 20 . , , . MSIL, . .NET . .NET . , MSIL . , , . , , . . , .NET Framework. , . . Common Language Runtime, . MSIL . . . , Visual Basic -, - ( ), . Java Java-. . " " , . .NET . .NET Framework Just In Time

2. Microsoft .NET

39_

(JIT) , MSIL . , CLR JIT. . , CLR , . , CLR . , CLR. , . . , CLR, , , , , , . . , , .NET. , .NET , .NET Framework. .NET " ": MSIL. . .NET - . .NET , .NET Framework.

, .NET, , , , MSIL. , , .

40

I.

EXE DLL . .NET Framework . .NET . .NET - , . , , , . .NET . CLR , , , . , , . Microsoft, , . . . . MSIL .

MSIL Microsoft Intermediate Language (MSIL) , . , , , , . . , MSIL , , , , . .NET MSIL.

2. Microsoft .NET

41

, MSIL. , , , . MSIL .NET .

, MSIL Visual Basic - Java, . . , . , (Interface Definition Language, IDL) CORBA, . "" , .

(Assembly) .NET dll, , Windows. -, , .NET , MSIL. -, (). .NET , . , CLR, ; ; MSIL. , . CLR . , , , , , , . , ( ) , . ? . , -

42

I.

CLR , , . , , , . . . , , : , ; , , ; , ; . : (internal) (public): : , . , : , XML, HTML . . . (major) (minor) . (build) (revision). , . , CLR, . . , , MSIL. , .NET , . . " ". . , . ! .NET . . , -

2. Microsoft

.NET

43

, . , (. 2.3).

1

)

. MSIL

. 2.3.

(private assemblies) -. (shared assemblies) . . ..WINNTVAssembly. . , .

.NET MSIL, , . , CLR. , . : ; ; ; ; . CLR . ( , , MSIL.)

44

I.

, . , , (, , ). . . , CLR. . Delphi, C#, Visual Basic . C++, , . .NET , .

.NET .NET , . .NET, . , , (Delphi, C++), (Java) ? , , ? MSIL? ( ^

. .NET "" , , , Delphi. .NET , , . .

, , .NET . 1. .NET , . 2. (Common Type System), , . 3. , Common Language Specification.

2. Microsoft .NET

45

, .NET , , . .NET. .

.NET . , . ( .NET , ) . . . , System.10

, /. , system. . , - Delphi Win32? , . , XML / .NET :System.10.XMLFileName

. .NET , system. system , .NET, .NET. . MSDN.

46

I.

(Common Type System) (Common Type System, CTS) , , .NET. , .NET, CLR, CTS . CTS , . . . . . , . , , , . .

.NET , . , ( ). . - , CLS (. ). system.

.NET ( !) = . Delphi, Win32, Name=vaiue TStrings. System. Enum.

.NET . . , . . . .

2. Microsoft .NET

47

.NET , . , , . .NET iunknown. .

.NET , . , . MulticastDeiegate. .NET .

.NET . , CLR. . , . .

.NET , . System.Array. .

Common Language Specification ( ) , , Common Language Specification (CLS). CLS , , . , , CLS-. CLS ( , ). CLS .

48

I.

- API, , , CLS .

.NET Framework , .NET . . .NET Framework. .NET Framework Windows, .NET ( Win API, COM, GUI . .), .NET Framework. .NET .( NET Framework Windows. . , Windows Windows Forms ( Windows GUI .NET) ASP.NET ( Web Microsoft Internet Information Server), . .NET, Microsoft , .NET Linux, UNIX, Solaris. .NET, Microsoft MONO (www.go-mono.net) .NET , Linux.

.NET Framework : Common Language Runtime (CLR); .NET. .NET , .

Common Language Runtime , .NET : . Borland DCCIL,

2. Microsoft .NET

49

Microsoft C#, C++, Visual Basic . Common Language Runtime .NET. mscoree.dll. .NET ( DLL .NET) (. 2.4). : 1. , . 2. . 3. . 4. MSIL - . 5. . : , , . Just In Time (JIT) MSIL ( , ) - . Native Image Generator (NGEN) . . , , : . . ; ; , .

50

I.

. 2.4. CLR

CLR. CLR CLR. , . , , , , . , . . - . ( ) , . - , , . . "" . , CLR. . , .

2. Microsoft .NET

51

CLR . . JIT , , . . . , . , , . . NGEN. Windows .

. -, . , . CLR. -, . , MSIL , . ( -). CLR SHA1. , , . -, . , .NET, , . Windows.

52

I.

.NET .NET Framework NET Framework Class Library. . . , , . . , API .NET Framework. : ; ; ; /; ; ; ; ; XML SOAP. , , . . .

.NET Framework SDK .NET (, - , ). .NET Framework SDK. SDK Microsoft. NT4 SP6 Internet Explorer 5.5.

2. Microsoft .NET

53

SDK : MSIL C++, #, Visual Basic; ; MSIL, .NET Framework MSJL; MSIL, . .NET.

.NET , . Web- ADO.NET. ADO.NET. Windows Windows Forms. .NET : System.windows. Forms Windows Forms; System.Data ADO.NET; System.Web.Services ASP.NET. .NET .NET .

ASP.NET ASP.NET Web- Web- . Active Service Pages (ASP), ASP.NET , . ASP.NET GUI Windows, ASP.NET "" cookies . ASP.NET , Web-

54

I.

.NET: , , JIT. ASP.NET .

ADO.NETADO.NET , .NET. ADO, Windows. , ADO, ADO.NET. ADO.NET .

Windows Forms .NET system.windows.Forms, Windows Forms. ( CLR) GD1+. Windows Forms . Windows Forms , Web-. Windows Forms .

.NET . , Web- Web-. .NET , Just In Time. , , .NET . .NET: . ; .NET , ;

2, Microsoft. NET

55

- ; .NET. ( , ). .NET .NET Framework. .NET , . .NET , MSIL. ( , CLR) . Just In Time, .

3

Delphi Borland Developer Studio Delphi - , - (). , .

- Delphi , , , , , : ; ; . , Delphi #, . , Delphi (, #, 4).

Delphi , , . , , . . :

58type TMyObject = class(TObject) MyField: Integer; function MyMethod: Integer; end;

I.

TMyObject, MyField MyMethod.

/ , ( ):type className = class [abstract | sealed] memberList type nestedTypeDeclaration memberList end; (ancestorType)

( 3.1) . | 3.1. type TOuterClass = class strict private myField: Integer; public type TInnerClass = class public mylnnerField: Integer; procedure innerProc; end ; procedure outerProc; end;

innerProc :procedure TOuterClass.TInnerClass.innerProc; begin end;

3. Delphi

59

(record). , . TMyObject MyField.

, . , , . , , . . Self. . , , . , . " ", . . . , 3.2.! 3.2. typeTFirstObject = class; TSecondObject - class(TObject) Fist : TFirstObject; end; TFirstObject = class(TObject) end;

, , , . , :var AMyObject: TMyObject;

AMyObject , , .AMyObject := TMyObject.Create;

60

I.

:AMyObject.Destroy;

, Nil, AMyObject. Free, Destroy.

, , . (). . . . Delphi , . , . , property. , . , , , , (color), (width, Height), (Left, ), (caption) . . , . : , /:type TAnObject = class(TObject) function GetColor: TSomeType; TSomeType); SetColor; procedure SetColor(ANewValue: end;

property AColor: TSomeType read GetColor write

AColor GetColor SetColor. , AnObject.AColor := AValue; AVariable := AnObject.AColor;

3. Delphi

61

. , , .

, Windows, . Delphi . , :property OnMyEvent: TMyEvent read FOnMyEvent write FOnMyEvent;

FOnMyEvent , . , . . , Application.OnActivate := MyActivatingMethod;

, Application ( , ) MyActivatingMethod. (RTL) Delphi , Windows. , , , , , :if Assigned(FOnMyEvent) then FOnMyEvent(Self);

. sender, - . TNotifyEvent :TNotifyEvent = procedure (Sender: TObject) of object;

, , , . . Delphi On: OnKeyPress, onMouseMove . . , Forml TLabeii. ( Onclick) TForml. LabellClick.'

62procedure TForml.LabellClick(Sender: begin end; TObject);

I.

, . . () :Objectl.OnMouseMove := Object2.OnMouseMove;

, . .

, , . , , . "" "" , . , . . - , , . .

. , , , . , TNewObject: TNewObject = class(TOldObject);

3. Delphi

63

TOldObject, , , , , , . Delphi TObject. TObject, . :TMyObject = class(TObject); TMyObject = class;

, , . - ; , , .

( 3.3). TFieid , . 3.3. type TFieid = class function GetData:string; virtual; abstract; end; TStringField = class(TFieid) FData : string; function GetData: string; override; end; TIntegerField = class(TFieid) FData : Integer; function GetData: string;override; end; TExtendedField = class(TFieid) FData : Extended; function GetData: string;override; end;

64function begin Result := FData; end; function TIntegerField.GetData; begin Result := IntToStr(FData); end; function begin Result:= FloatToStrF(FData, end; procedure ShowData(AField begin Forml.Labe11.Caption end; := AField.GetData; : TField); ffFixed, 7, 2) ; TExtendedField.GetData; TStringField.GetData;

I.

FData - "", ( GetData). ShowData . (typecasting) Delphi , . ShowData TField , TStringField, TIntegerField, TExtendedField, TField. (, ) GetData ? , . , , , . , . , , . , , . , , . , "" () - -. , ShowData, , ,

3. Delphi

65

, TField ( GetData). , , , , , - TField! Delphi. TComponent, "" . , TComponent , Delphi .

, & . .

Abstract , , , . . Delphi . :procedure NeverCallMe; virtual; abstract;

. NeverCallMe EAbstractError.

TField , . TField , -"" . showData TField, , , .

Sealed , .NET, sealed ("", "" ) :3 * 270

66

I.

type className = class [abstract ] sealed] memberList end;

(ancestorType)

(, v i r t u a l , dynamic o v e r r i d e ) f i n a l .

Static , - : . , 3.4. 3.4. type TlstObj = class i : Extended; procedure SetData(AValue: Extended); end; T2ndObj = class(TlstObj) i : Integer; procedure SetData(AValue: Integer); end; procedure TlstObj.SetData; begin i := 1.0; end; procedure T2ndObj.SetData; begin i := 1; inherited SetData(0.99); end;

, inherited. , .

Virtual Dynamic . -

3. Delphi

67

virtual dynamic. Pascal. : , . , , , showData. , . (late binding). , - . (Virtual Method Table, VMT) (Dynamic Method Table, DMT). . , , VMT . ( ). , , . , : , VMT . , . . , . ; DMT - , , TObject, .

Override , override, ( 3.5).I 3.5. type TFirstClass = class

.68FMyFieldl: Integer; FMyField2: Longint; procedure StatMethod; procedure VirtMethodl; virtual; procedure VirtMethod2; virtual; procedure DynaMethodl; dynamicprocedure DynaMethod2; dynamicend;' TSecondClass = class(TMyObject) procedure StatMethod; procedure VirtMethodl; override; procedure DynaMethodl; override; end; var Objl: TFirstClass; Obj2: TSecondClass;

I.

, . override . Delphi inline: procedure MyProc(x:Integer); inline; begin // ... end; function MyFunc(y:Char) begin // .. end; : String; inline;

, , : inline ; inline , ; inline ; inline , ;

3. Delphi

69

, " ", . . , , , , ; inline , , ; inline , r e p e a t . . . u n t i l / w h i l e . . .do.

inline {$INLINE}: {$INLINE ON} , . inline . ($INLINE AUTO} , 32 . {$INLINE OFF} inline , .

, . , . 3.6 , (. 3.4).! 3.6. type TlstObj = class FExtData : Extended; procedure SetData(AValue: Extended); end; T2ndObj = class(TlstObj) FIntData : Integer; procedure SetData(AValue: Integer); end; var Tl: TlstObj; T2 : T2ndObj;

70

I.

2 T2.SetData(1.0); T2.SetData(l);

. 2 extended " ". , overload ( 3.7). I 3.7. type TlstObj = class : FExtData . Extended; procedure SetData(AValue: Extended);overload; end; T2ndObj = class(TlstObj) FIntData : Integer; procedure SetData(AValue: Integer); overload; end;

SetData , . () . reintroduce ( 3.8).

i 3.8. type TlstObj = class FExtData : Extended; procedure SetData(AValue: Extended); overload; virtual; end; T2ndObj = class(TlstObj) FIntData : Integer; procedure SetData(AValue: Integer); reintroduce; overload; end;

Delphi : public , , , ;

3. Delphi

71

D private , ; protected , , , , ; published , , , Object Inspector; s t r i c t private protected s t r i c t :type TWinForm = class(System.Windows.Forms.Form) strict private procedure One; end;

, strict, , , . , class private protected Delphi Common Language Runtime:type className = class class private Fieldl: integer; class protected Field2: integer; end;

Fieldl className, Field2 .

Delphi 2005 . Microsoft's Common Language Runtime (CLR) , namespace, . Delphi, .

72_

I.

, . , . , Myciass MyNameSpace MyClass YourNamespace. Delphi, . , . . , :unit MyCompany.MyWidgets.MyUnit;

, , , (MyCompany.MyWidgets.MyUnit.pas, MyCompany.MyWidgets.MyUnit.dcuil). . : , , , ; ; : , ; , namespace;

; .

Delphi Delphi . , integer, cardinal real, (generic-).

3. Delphi

73

ANSichar wideChar, .NET System.Char.

. 3.1. 3.1. Delphi integer cardinal shortint smallint longint int64 byte word longword real

-2147483648... 2147483647 0...4294967295 -128...127 -32768...32767 -2147483648... 2147483647 -2 63...2 631 0...255 0 ...65535 0 ...4294967295 -5.0 324... 1.7 308

32- 32- 8- 16- 32- 64- 8- 16- 32- 64- , 15-16 48- , 11-12 32- , 7-8 64- , 15-16

.NET Int32 Uint32 SByte Int16 Int32 Int64 Byte Ulnt16 Ulnt32 Double

real48

-2.9 39... 1.7 38

single

-1.5 45... 3.4 10 38

Single

double

-5.0 1324... 1.7 1308

Double

74

I. 3.1 ()

extended

-3.6 4951 ... 1.1 x 14932

10- , 19-20 64-, 19-20 64-, 19-20 2 256

.NET Double

comp

-2 63+1 .. .2 63 1

currency

-922337203685477.5808... 922337203685477.5807 255

Decimal

ShortString

Delphi ANSI, DBCS ANSI, MBCS ANSI . . Unicode

ANSIString

~2 31

4 2

WideString

~2 30

4 2

, . System.Convert, . 3.2. 3.2. ToString . . , . 3.3

3. Delphi

75 3.2 ()

ToByte Tolntl6 Tolnt32 Tolnt64 ToUIntl6 ToUInt32 ToUInt64 ToSingle ToDouble

, . System.OverflowException , . System.OverflowException , , . System.OverflowException

system.ArgumentException Null system. FomatException . . 3.3 . 3.3. () currency . ( 10) ( !) .

() F (f) N ()

G (g) R ()

76

I.

Delphi , . . 3.4 3.4. Delphi / / (AND) (OR) (XOR) (NOT) + * / div mod + s h l shr < > < = > = i s as

and

or |xor not

:=

Delphi set (), array () record (). set , 256 , ( 255). :type TSomelnts = 1..250; TIntSet = set of TSomelnts;

, :var Setl, Set2: TIntSet; Setl := [1, 3, 5, 7, 9] ; Set2 := [2, 4, 6, 8, 10]

3. Delphi

77

Delphi ( , ) . type TMarix = array[1..10, 1..50] of real;

500 (10 50 ), var Matrix: TMatrix;

Matrix[2, 45] Matrix[2][45];

Delphi , .NET, . New ( 3.9). 3.9. var a: array[,,] of integer //3- b: begin a := New(array[3,5,7] b of integer); // := New(array[,] of integer, ((1,2,3), (4,5,6))); // array[,] of integer //2- //2- TPoint : array[,] of TPoint

:= New(array[,] of TPoint, (((X:1;Y:2), (X:3;Y:4)), ((X:5;Y:6), (X:7;Y:8)))); // TPoint end.

Delphi , . . record :type recordTypeName = record fieldListl: typel; fieldListn: typen; end

, type TDateRec = record

78Year: Integer; Month: (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec); Day: 1..31; end;

I.

: Year, Month Day, 1 31. , var Rec: TdateRec;

:Rec.Year := 1904; Rec.Month := Jun; Rec.Day := 16;

, , record ( , ), Delphi, . . - : , , .

: for = to [downto] do ; repeat until ; while do

Delphi for-element-in-coliection , , : for Element in ArrayExpr do Stmt; for Element in StringExpr do Stmt; for Element in SetExpr do Stmt; for Element in CollectionExpr do Stmt;

( 3.10) si, . . , , Length (Length (s) s).

3. Delphi \ 3.10. var : Char; SI, S2: String; begin 51 := ' '; 52 := " ; // for in SI do S2 := S2 + C; if SI = 52 then WriteLn(' !'); else WriteLn(' '); end.

79

, . , "" , , .

Delphi try..except try..finally! try // except // , end;

, , , except. , , t r y . . . finally:try{

//

80 finally { / / }

/.

, , , , , . Delphi for .NET [Delphi] type Exception = class (System.Object, Sytem.Runtime.Serialization.ISerializable) ;

Borland.Delphi.System, Delphi for Win32 [Delphi] type Exception = class (System.TObject); .

Sysutils.

- , Delphi 2005, , Delphi . Delphi.

4

# Borland Developer Studio .NET #. , Borland, .NET, - Delphi #. #, ( , , !), , # , .NET, C++, Java, SmallTalk, Visual Basic "" C++, , ( , ). , : "Hello, world!". . , , , #, , , , Delphi. Borland Delphi 2005 : File | New | Other | Console Application. Delphi 2005 :using System; namespace Project3

82class Class [STAThread] static void Main(string[] args)

I.

, , . , class Main. , #. , - , , . Main , { } ( Delphi begin end):System.Console.WriteLine("Hello, World!!!"); System.Console.WriteLine(" Enter "); System.Console.ReadLine();

. (. 4.1).PV C:\Documents and Settings\nvv\MoM \1ieet :- E3 PiqectMarvsg

63 (Bed {^J Developers Developer m Went S 3 C'/Hopei Sage Ctl*IC4tiOn

Testos . 17.2. XML-. ,

DOM. , , , . , , , . "" IDOMNode.

316

II. Windows Forms

nodeType, nodeName v\ nodeValue D O M " ": nodeType, nodeName nodeValue, . nodeType, . , nodeName nodeValue . . 17.1. 17.1. nodeType, nodeName nodeValue

ioomode nodeType 1 2 3 4 5 6ELEMENT_NODE

NodeName

NodeValue "nil nil nil

IDOMElement IDOMAttr IDOMText IDOMCDATASection IDOMEntityReference IDOMEntity

CDATA ( DTD) DTD DTD

#text #cdatasection

ATTRIBUTE_NODE

TEXT NODE

CDATA SECTION NODE ENTITY REFERENCE_NODE ENTITY_NODE

7

PROCESSING_ INSTRUCTION_ NODE COMMENT NODE

#comment

nil nil nil nil

IDOMProcessingInstruction IDOMComment

8

9 10 11 12

DOCUMENT NODE

#document DTD #documentfragment #notation

IDOMDocument IDOMDocumentType IDOMDocument Fragment IDOMNotation

DOCUMENT TYPE NODE DOCUMENT_ FRAGMENT_NODE NOTATIONJTODE

17. XML

317TEXTNODE, CDATA_

. SECTION_NODE, NOTATION_NODE ENTITY_NODE, PROCESSING__INSTRUCTION_NODE,

COMMENT_NODE

. DOCUMENT_ TYPE_NODE, DTD, NOTATION_NODE ENTITY_NODE. , , , , CDATA, (); , (). , DOM. DTD; XML-. . , , .

, , ioomode : ( owner Document ParentNode);

(previoussibiing,

nextSibling);

; ( attributes). . 17.2 . 17.2. ioomode property ownerDocument: IDOMDocument; property parentNode: IDOMNode property previousSibling: IDOMNode; property nextSibling: IDOMNode; function hasChildNodes: WordBool; property childNodes: IDOMNodeList; property f i r s t C h i l d : IDOMNode;

, ,

318

II. Windows Forms 17.2 ()

property lastChild: IDOMNode; function replaceChild(const newChild, oldChild: IDOMNode): IDOMNode; function removeChild(const ChildNode: IDOMNode): IDOMNode; function appendChild(const newChild: IDOMNode): IDOMNode; function insertBefore(const newChild, refChild: IDOMNode): IDOMNode; function cloneNode(deep: WordBool): IDOMNode;

oldChild newChild childNode newChild newChild refChild , . deep ; True , , D O M feature version

property attributes: IDOMNamedNodeMap; procedure normalize; function supports(const feature, version: DOMString): WordBool;

, (iDOMNodeList) (iDOMNamedNodeMap), (items):property item[index: Integer]: IDOMNode; property length: Integer;

, . 17.2 () , IDOMNamedNodeMap . , , . ? : , , . ... DOM . .

17. XML

319

XML . . , , . , , , . , , name class, , ? : . ,

z , a row . vendor:name product:name.

. :xmlns:[]= " URI "

. , , ADO (ADO recordset), XML:

DOM level 2, (namespace) (. 17.3). 17.3. property namespaceURI: DOMString;

URI

property p r e f i x : DOMString; property localName: DOMString

320

II. Windows Forms

IDOMDocument . , , . property documentElement: IDOMElement;

ProjectTeam. property doctype: IDOMDocumentType;

DTD , . :function createElement(const tagName: DOMString): IDOMElement; function createDocumentFragment: IDOMDocumentFragment; function createTextNode(const data: DOMString): IDOMText; function createCornment (const data: DOMString): IDOMComment; function createCDATASection(const data: DOMString): IDOMCDATASection; function createProcessinglnstruction(const IDOMProcessinglnstruction; target, data: DOMString):

function createAttribute(const name: DOMString): IDOMAttr; function createEntityReference(const name: DOMString): IDOMEntityReference;

. (standalone) .

, DOM , XML " ". XML , Treeview, . TTreeview, , Filter *.xml. imageList . , D0MNode2TreeViewNode Onclick ( 17.2).

17. XML | 17.2. XMLDemolprocedure TWinForml.D0MNode2TreeViewNode(aDOMNode: XMLNode; parentNode: TreeNode ) ; var i: Integer; ThisNode : TreeNode; begin if not Assigned(ADOMNode) then Exit; ThisNode := tvXML.Nodes.Add(ADOMNode.Name); if not Assigned(ThisNode) then Exit; ThisNode.Imagelndex := 0;

321

if Assigned(ADOMNode.Attributes) then for i := 0 to ADOMNode.Attributes.Count 1 do with ThisNode.Nodes.add(ADOMNode.Attributes.Item(i).Name) Imagelndex : = 1; ThisNode.Selectedlmagelndex := ThisNode.ImageIndex; do

if Assigned(ADOMNode.ChildNodes) then for i := 0 to ADOMNode.ChildNodes.Count - 1 do DOMNode2TreeViewNode(ADOMNode.ChildNodes[i], ThisNode); end;

procedure TWinForml.Buttonl__Click(sender: System.Object; e: System.EventArgs); var XMLDocument1: XMLDocument; begin if OpenDialogl.ShowDialog System.Windows.Forms.DialogResult.OK then Exit; XMLDocument1 := XMLDocument.Create; try XMLDocumentl.Load(OpenDialogl.OpenFile); try tvXML.Nodes.Clear; DOMNode2TreeViewNode( XMLDocumentl.DocumentElement, nil ) ; except on E: Exception do 11 . 270

322

II. Windows Forms

begin MessageBox.Show( 'Error message:'#13#10 + E.Message); end; end; finally XMLDocumentl.Free; end; end;

D0MNode2TreeViewNode:

, () L- ; , , ; . XMLDocument, . XML. ... #text? , DOM.

DOM .NET MSXML Microsoft , , , XML. Microsoft, , Internet Explorer. MS XML . 2, XSL Patterns. , 3 XSLT XPath. Microsoft , , MSXML 3 : (side-by-side). - -

17. XML

323

(ProgID). " ", . MS XML 4, . XSL. parsing suite. "" 5 . XML .NET Delphi 2005 , . XML DOM . XML xmlDocument. XML XmlNode. XML XmlReader XmlWriter.

XmlNode XmlNode XML. , : , , . . property NodeType: XmlNodeType;

, - . xmiNodeType , . 17.4. 17.4. XML None Element Attribute TextCDATA

. XmlReader , .

Entity EntityReference Processinglnstruction

324

II. Windows Forms

17.4 () Comment Document DocumentType Document Fragment Notation Whitespace SignificantWhitespace EndElement EndEntity Xml Declaration . XML . , , . , . .

, , , , CDATA. XML , XmlNode . - . property Name: string;

property Value: string;

, Hello, World! Name first, Value Hello, World!.

, property InnerText: string;

, value. , ,

17. XML property Prefix: string;

325

property LocalName: string;

. property NamespaceURI: string;

, . , . xmiNode property Attributes: XmlAttributeCollection;

XMLAttribute. , , , . XMLAttribute . property OuterXml: string;

property innerXml: string;

XML- XML . property IsReadonly: Boolean;

True, . , . XML, . property OwnerDocument: XmlDocument;

-. , . property ParentNode: XmiNode;

.

326

II. Windows Forms

, , property HasChildNodes: Boolean;

True. property ChildNodes: XmlNodeList;

, xmlNode. , . :property FirstChild: XmlNode; property LastChild: XmlNode;

, , ( xmlElement). property Item[name: string]: XmlElement; property Item[localname: string; ns: string]: XmlElement;

. . xmlNode . function AppendChild(NewChild: xmlNode): XmlNode; , Newchiid, ; function PrependChild(newChild: xmlNode): XmlNode; ; function ReplaceChild(newChild: xmlNode; oldChild: xmlNode):

XmlNode; oldChild newchiid . refchild. function InsertBefore(newChild: xmlNode; refChild: xmlNode): XmlNode; function InsertAfter(newChild: xmlNode; refChild: xmlNode): XmlNode;

17, XML

327

, , . function CloneNode(deep: Boolean): XmlNode;

. deep . function CloneNode: XmlNode;

"". function RemoveChild(NewChild: xmlNode) . XmlNode; -

oldchild. "" procedure RemoveAll;

, . property PreviousSibling: XmlNode; property NextSibling: XmlNode;

. procedure WriteTo(w: XmlWriter);

:procedure WriteContentTo(w: XmlWriter);

XPath XmlNode . function SelectSingleNode(xpath: string): XmlNode; function SelectSingleNode(xpath: string; nsmgr: XmlNamespaceManager): XmlNode;

. function SelectSingleNode(xpath: string): XmlNode; function SelectSingleNode(xpath: string; nsmgr: XmlNamespaceManager): XmlNode;

.

328

II. Windows Forms

XMLEIement XMLEIement xmiNode XML. , , . ( xmiNode Attributes.) , function HasAttribute(name: string): Boolean; function HasAttribute(localname: string; namespaceURI: string): Boolean;

, . function GetAttribute(name: string): string; function GetAttribute(localname: string; namespaceURI: string): string;

. . procedure SetAttribute(name: string; value: string); function SetAttribute(localname: string; namespaceURI: string; value: string): string;

value name. . function GetAttributeNode(name: s t r i n g ) : XmlAttribute; function GetAttributeNode(localname: string; namespaceURI: XmlAttribute; string):

XmlAttribute, . function SetAttributeNode(newAttr: XmlAttribute): XmlAttribute; function SetAttributeNode(localname: string; namespaceURI: string): XmlAttribute;

, newAttr . . , -

17. XML

329

. , .NET . procedure RemoveAttribute(name: string); procedure RemoveAttribute(localname: string; namespaceURI);

, . function RemoveAttributeNode(oldAttr: XmlAttribute): XmlAttribute; function RemoveAttributeNode(localname: string; namespaceURI: string): XmlAttribute;

, , . function RemoveAttributeAt(i: Integer): XmlNode;

. procedure RemoveAllAttributes;

.

XMLAttribute XMLAttribute XmlNode XML. XmlNode property Name: string;

property Value: string;

. property OwnerElement: XmlElement;

- .

XMLDocument XMLDocument XML .NET. -

330

II. Windows Forms

. XMLNode , , XML . , . -, , . , : constructor Create; . . procedure LoadXml(xral: s t r i n g ) ; , xml. procedure Load(: stream); , , . XML procedure WriteTo(w: XmlWriter);. :procedure WriteContentTo(w: XmlWriter);

property DocumentElement: XmlElement; property DocumentType: XmlDocumentType, xml DocumentType DTD. , . function CreateDocumentType(name: string; publicld: string; systemld: string; internalSubset: string):XmlDocumentType;

DTD: name ; publicld ;

17, XML

331

systemid ; internaisubset DTD. , xmioocument XML. function CreateXmlDeclaration(version: string; encoding: string; standalone: string): XmlDeclaration;

XmlDeclaration, : version ; encoding ; standalone . xmiDocument . function CreateElement(name: string): XmlElement; function CreateElement(prefix: string; localName: string; namespaceURI: string): XmlElement; function CreateSlement(qualifiedName: string; namespaceURI: string): XmlElement;

XmlElement. : name : prefix ( ); localName ( );_

4

namespaceURI ; quaiifiedName , xmiQualif iedName . function CreateAttribute(name: string): XmlAttribute; function CreateAttribute(prefix: string; localName: string; namespaceURI: string): XmlAttribute; function CreateAttribute(quaiifiedName: string; namespaceURI: string): XmlAttribute;

XmlAttribute. CreateElement.

332

II. Windows Forms

function CreateCDataSection(data: string): XmlCDataSection;

XmlCDataSection.

CDATA

function CreateComment(data: string): XmlComment;

xmicomment.( ^

XML . .

property Implementation: Xmllmplementation

xmllmplementation, XML. XML, . Xmllmplementation function CreateDocument: XmlDocument;

XML. , property NameTable: XMLNameTable;

XmlDocument . fucntion GetElementsByTagName(name: string): XmlNodeList; fucntion GetElementsByTagName(localName: string; namespaceURI: string): XmlNodeList;

. . fucntion GetElementByldfelementld: string): XmlElement;

, , elementld.

17. XML ( ) function CreateNode(type: XmlNodeType; prefix: string; name: string; namespaceURI: string);

333

, , . function ReadNode(reader: XmlReader): XmlNode; , reader. function ImportNode(node: XmlNode; deep: Boolean): XmlNode;

, . deep "" . False , , . True . , , , -. ( ) property Nodelnserting: procedure(sender: TObject; e: xmlNodeChangedEventArgs) of object;

property Nodelnserted: procedure(sender: TObject; e: xmlNodeChangedEventArgs) of object; property NodeDeleting: procedure(sender: TObject; e: xmlNodeChangedEventArgs) of object;

property NodeDeleted: procedure(sender: TObject; e: xmlNodeChangedEventArgs) of object;

property NodeChanging: procedure(sender: TObject; e: xmlNodeChangedEventArgs) of object; property NodeChanged: procedure(sender: TObject; e: xmlNodeChangedEventArgs) of object;

334

II. Windows Forms

XML . .NET Delphi XML. , .NET Delphi, DOM. XML System.Xml.Schema. System. Xral, System.Xml.XPath, System. Xml.Xsl

XML XML. XML xmiNode. , XML. , XmlElement XmiAttribute . XML XML. xmlDccument XML. , XML . , XML XML, . XML, XML: DTD, XSL XPath.

III

VCLNET 18. 19. 20. 21. 22.

18

VCL.NET . . , , . , , . TAppiication, . , . : ; ; TAppiication;

.

. .

338

III. VCL.NET

VCL.NET : DPR Delphi; BDSPROJ , .NET; BDSPROJ.LOCAL ; 0 CFG Delphi; RES . , . , , : , , ActiveX. DPR ( 18.1), , .NET. : uses begin.. .end. 1 18.1. VCL.NET program Project1; {%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\vl.l.4322\System.dll 1 } {%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\vl.l.4322\System.Data.dll'} {%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\vl.1.4322\System.Drawing.dll'} {%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\vl.l.4322\System.XML.dll'} usesSystem.Reflection, System.Runtime.CompilerServices, SysUtils, Forms, Unitl in 'Unitl.pas' {Forml}; ($R *.res} {$REGION 'Program/Assembly Information'} [assembly: AssemblyDescription('')] [assembly: AssemblyConfiguration('')] [assembly: AssemblyCompany('')]

18. [assembly: AssemblyProduct('')] [assembly: AssemblyCopyright('')] [assembly: AssemblyTrademark{'')] [assembly: AssemblyCulture('')] [assembly: AssemblyVersion(4.0. *')] [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile (.. J .,) '' [assembly: AssemblyKeyName('')] . {$ENDREGION} [STAThread] begin Application.Initialize; Application.CreateForm(TForml, Application.Run; end. Forml);

339

uses , , VCL.NET .NET, Delphi VCL. , uses . begin.. .end TAppiication , . Run . ( 18.2) pas. Delphi, . I 18.2. unit Unitl; interface Graphics, Controls,

usesWindows, Messages, SysUtils, Variants, Classes, Forms, Dialogs; type TForml = class(TForm) Buttonl: TButton; procedure ButtonlClick(Sender: TObject); private { Private declarations } public { Public declarations } end;

340var Forml: TForml ; implementation {$R *.nfm} const MessageStr = ' '; procedure TForml.ButtonlClick(Sender: TObject); begin ShowMessage(MessageStr); end; end.

III. VCL.NET

. interface , , . , , .NET . implementation . , , interface, , implementaion . {$R *.nfm} , , nfm. . , . ( 18.3) nfm , . 18.3. object Forml: TForml Caption = 'Forml' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] Height = 240 Width = 3 4 7 Left - 0 Top - 0 PixelsPerlnch = 96

18. TextHeight = 13 object Buttonl: TButton Caption = 'Buttonl' TabOrder = 0 Left = 112 Top = 24 Width = 7 5 Height = 25 OnClick = ButtonlClick end end

341

, . , 18.3, . 18.1.

Button!

. 18.1.

View As Text .

(. 18.1). dcuil. , . dcuil. , ~dp, ~pa ~nf . Delphi . (

342

III. VCL.NET

res), , , . . bdsproj . Delphi , , , . , , . (). ( 18.4) bdsgroup , . 18.4. n>il.0 {780DB670-DEE9-4 8C6-B40F-2F404A66EB3D} Projectl.bdsproj Name="Targets">Projectl.exe encoding="utf-8"?>

, , . , : , ProjectGroupi. , , BDSGROUP .

18.

343

Delphi . , (. 18.2). , . , . Delphi . . Activate . )

.! a

Project3.bdsproj - Project Mana.-B X (Jjl Activate ((StNew ; Remove I

File 5> ProjectGroupl

IPSS32E3S References Uniti.pas f l Unitl.nfm

~ | g a Project.,, | %FModel... | 100';

, 100 . LIKE , . * % . :CalcColumn.Expression := 'CarName LIKE '*Peugeot*''; CalcColumn.Expression := 'CarName LIKE 'Chevrolet*''; CalcColumn.Expression := 'CarName LIKE '*Cruiser'';

OR, AND, NOT. :CalcColumn.Expression := '(Population / Area > 10 AND Population / Area < 100) AND NOT Capital = 'Brazilia' 1 ;

IN , . . , :CalcColumn.Expression := 'Capital = 'Brasilia''; ( )

, , -

24. ADO.NET

503

. , . , .

, . , . . , . . , , . , . , , . , , : ( 1). , "" , . , , . . DataTabie . property PrimaryKey: array of DataColuinn;

, . , , . : d AllowDBNull True.

Unigue T r u e .

d Autolncrement True.

, . Readonly True. .

504

IV. .NET

, . , . Contains , , .

. , ADO.NET, . , . . , . . , , . . . , , . . . . . . . . . , . ADO.NET . , . , . DataTabie property Rows: DataRowCollection;

DataRowCollection . .

24. ADO.NET

505

property Item[index: Integer]: DataRow;

, . , . item :Rows := DataSetl.Tables.Item['Country'].Rows; for i := 0 to Rows.Count 1 do begin CurrentRow := Rows.Item[i]; // end;

:Rows := DataSetl.Tables.Item['Country'].Rows; Idx := 12; CurrentRow := Rows.Item[Idx];

procedure InsertAt(row: DataRow; pos; Integer);

row DataRow, pos , . , , procedure Remove(row: DataRow);

procedure RemoveAt(index: Integer);

Find: function Find(key: TObject): DataRow; function Find(keys: array of TObject): DataRow;

. , key,

506

IV. .NET

keys, . . nil. DataRow, . . DataRow. property ItemArray: array of TObject;

, . : TextBoxl.Text := string(SomeRow.ItemArray[1]); . property property property property property property Item(column: DataColumn): TObject; Item(columnlndex: I n t e g e r ) : TObject; Item(columnName: s t r i n g ) : TObject; Item(column: DataColumn; version: DataRowVersion): TObject; Item(columnlndex: Integer; version: DataRowVersion): TObject; Item(columnName: s t r i n g ; version: DataRowVersion): TObject;

, : column ; columnindex ; coiumnName . version , . , , . ( ) . DataRowVersion , : current ; Def aulf ;

24. ADO.NET

507

original , ; Proposed ( ). original Current, . : Original, current Proposed, Current ( , ), Proposed ( Proposed ). Proposed ( current), current Original . , Current = original, Original . , Current = Original, original . . 24.7 DataRow.

Original Current

Original Current Proposed

i . 24.7. DataRow

function HasVersion(version: DataRowVersion): Boolean;

, . function IsNull(column: DataRowColumn; version: ) : Boolean;

True, column version .

508

IV. .NET

, , . property RowState: DataRowState;

. DataRowState : Detached , DataRowCollection;

Unchanged ; Added - DataRowCollection; Deleted ; Modified . , , , - . , procedure BeginEdit;

procedure EndEdit;

procedure CancelEdit;

. , . Acceptchanges . "" . procedure Delete;

, Deleted. Acceptchanges. procedure Acceptchanges;

.

24. ADO.NET

509_

Unchanged, Original Current . ( Deleted Delete), . . procedure RejectChanges;

unchanged. ( Added), . . , , property HasErrors: Boolean;

True, . , - RowChanging :procedure RowChanging(sender: TObject; e: DataRowChangeEventArgs); begin if e.Row.HasErrors and (e.Action = DataRowAction.Commit) then e.Row.RejectChanges end;

property GetColumnsInError: array of DataColumn;

, . property RowError: string;

"" , . procedure ClearErrors;

. " ". -. , :

510procedure SetParentRow(parentRow: procedure SetParentRow(parentRow:

IV. .NETDataRow); DataRow; relation: DataRelation);

parentRow , .

DataSet . . Tablesproperty Tables: DataTableCollection;

, . ADO.NET , . . DataTabie. ( , , , . .) . property Columns: DataColumnCollection;

. , , , , . ( , , , , , ) property Rows: DataRowCollectlon

DataRow. , , . , , Fill , :

24. ADO.NETvar Result: Integer;

511

Result := SqlDataAdapterl.Fi.il (DataSetl) ;

Rows , . . , :for i := 0 to DataSetl.Tables.Item['Country'].Rows.Count begin // end; 1 do

, (), :var CurrentRow: Idx := 12; CurrentRow := DataSetl.Tables.Item['Country'].Rows.Item[Idx]; DataRow;

, ADO.NET , . . , , . , , . DataRow , . -, property ItemArray: array of TObject;

. , ItemArray , , , :

512 s : = ' : ';

IV. .NET

for i := 0 to DataSetl.Tables.Item['Country'].Columns.Count - 1 do s := s + string(CurrentRow.ItemArray[i]) + ' ' ; MessageBox.Show(s);

-, () . item, :CurrentValue := CurrentRow.Item(SomeColumn); // CurrentValue := CurrentRow.Item(O); // CurrentValue := CurrentRow.Item('Name'); //

, :for i := 0 to DataSetl.Tables.Item['Country'].Columns.Count - 1 do CurrentRow. IternArray [i] := null; CurrentRow.Item(O) := 'SomeValue';

, , , . , , , update . . Add , insertAt, . , :DataSetl.Tables.Item['SomeTable'].Rows.InsertAt(NewRow, NewRow.Item(l) := ' S o m e S t r i n g ' ; NewRow.Item(2) : = SomeBoolean; NewRow.Item(3) := SomeDouble; 1);

. , , , . , . . ( ) .

24. ADO.NET

513

, . . , , - .

Remove RemoveAt, , :DataSetl.Tables.Item['Country'].Remove(SomeRow); DataSetl.Tables.Item['Country'].RemoveAt(1);

DataGrid, .

, , , , . ADO.NET . Rows DataTable DataSet. , . DataRowCollection function Contains(key: TObject): Boolean; function Contains(key: array of TObject): Boolean;

. ( ) ( ). . True, . . . , , .17 270

514

IV. .NET

. function Find(key: TObject): DataRow; function Find(key: array of TObject): DataRow;

:var Rows: DataRowCollection; CurrentRow: DataRow; SetLength(PrimaryKeyValue, 2 ) ; PrimaryKeyValue[O] := TObject(123); PrimaryKeyValue[1] := TObject('somestring'); if Rows.Contains{PrimaryKeyValue) then CurrentRow := Rows.Find(PrimaryKeyVaiue);

(. ). Expression . - , , . . Expression , , , . Expression. DataviewManager, property DefaultViewManager: DataViewManager;

. , , . - , . , . . DataviewManagerproperty DataViewSettings: DataViewSettingsCollection;

DataViewSetting, .

24. ADO.NET

515

DataViewSetting Dataview . DataViewManager function CreateDataView(table: DataTable): DataView;

, table. DataViewSetting DataViewSettings.

, DefaultviewManager . , , , property CaseSensitive: Boolean;

DataSet. True, , . DataSetproperty Locale: Culturelnfo;

, , . , , Locale. Culturelnfo . DataGrid, .

. . , , , , , . . . , . , , , .

516

IV. .NET

, . . , ADO.NET. , ADO.NET , DataTable. . property Constraints: ConstraintCollection;

constraint. . , constraint. . constraint , . uniqueConstraint )' , . , Delphi . ForeignKeyConstraint , . . . . , . UniqueConstraint , . property Columns: array of DataColumns;

, property IsPrimaryKey: Boolean;

True.for i := 0 to DataTable.Constraints[i].Count - 1 do if (DataTable.Constraints[i] is UniqueConstraint) and DataTable.Constraints[I]. IsPrimaryKey then

24. ADO.NETbegin // end;

517

ForeignKeyConstraint , . . . property Columns: array of DataColumns;

property RelatedColumns: array of DataColumns;

. . property Table: DataTable;

property RelatedTable: DataTable;

ForeignKeyConstraint constructor Create(constraintName: string; parentTableName: string; parentColumnNames: array of string; childColumnNames: array of string; acceptRejectRule: AcceptRejectRule; deleteRule: Rule; updateRule: Rule);

, , , " ". . property UpdateRule: Rule;

property DeleteteRule: Rule;

Rule, : None ; Cascade ;

518

IV. .NET

SetDefault ; SetNuii (null). , . ( Acceptchanges ) property AcceptRejectRule: AcceptRejectRule;

AcceptRejectRule : None ; cascade . , .var NewConstr: ForeignKeyConstraint;

ChildTable: DataTable; NewConstr := ForeignKeyConstraint.Create('ForeignKeyl', 'ParentTable', TArrayOfString.Create('ORDER_NO') , TArrayOfString.Create('ORDER_NO'), System.Data.AcceptRej ectRule.None, System.Data.Rule.None, System.Data.Rule.None); ChildTable.Constraints.Add(NewConstr);

, , . " " . . . DataSetproperty EnforceConstraints: Boolean;

True .

24. ADO.NET

519

, " ", ( ) , ( ) . , . property Relations: DataRelationCollection;

DataRelation. . . 24.8 Relations.BiRelations Collection Editor Members; 10| Relation!' Q Relation2 ChildColumm ParentCcrfumi Mufc Da(aTablei Patenti istr. CcretiainK ParentTabte i !.

illRelation2 Properties:

:i:

' ~ ''v

'

: ! >

* '

:

:!

Edit

Close

Help

. 24.8. Relations

, DataTabie , , .

520

IV. .NET

property ParentRelations: DataRelationCollection;

, . property ChildRelations: DataRelationCollection;

, . , DataRelation. constructor Create(constraintName: string; parentTableName: string; childTableName: string; parentColumnNames: array of string; childColumnNames: array of string; nested: Boolean);

, , property RelationName: string;

property ParentTable: DataTable;

property ChildTable: DataTable;

property ParentColumns: array of DataColumns;

, . property ChildColumns: array of DataColumns;

, . , . , . DataRelation . property ParentKeyConstraint: UnqueConstraint;

( ) .

24. ADO.NET

521

property ChildKeyConstraint: ForeignKeyConstraint;

. , . , property Nested: Boolean;

True. , , ADO.NET . . DataRelation:var NewRelation: DataRelation; SomeDataSet: DataSet; NewConstr := DataRelation.Create('Relationl', 1 PARENTTABLE', 'CHILDTABLE', TArrayOfString.Create ('ORDERJSIO') , TArrayOfString.Create('ORDER_N0'), False); SomeDataSet.Relations.Add(NewRelation);

, DataTabie DataSet , , . ADO.NET , . ADO.NET . Delphi DataView, Data Components . , DataView , constructor Create; constructor Create(table: DataTabie); constructor Create(table: DataTabie; rowFilter: string; sort: string; rowState: DataViewRowState);

522

IV. .NET

. property Table: DataTable;

, . . , DefaultViewManager, . property DataViewManager: DataViewManager;

DataViewManager. , . . . . property Item[recordlndex: Integer]: DataRowView;

DataRowView . , Table . , . ADO.NET , DataView . item , . , . item. DataView ( DataGrid), . , DataRowView DataRow, , . , DataRowView , :property Row: DataRow;

24. ADO.NET

523

, (, ). DataRowView property RowVersion: DataRowVersion;

DataRowVersion , : Current ; Defaulf ; Original , ; Proposed ( ). , , . property Item[ndx: Integer]: TObject;

. :with SomeDataRowView do try BeginEdit; Item[0] := 1; Item[l] := 2; Item[2] := 'string'; EndEdit; except CancelEdit; end;

BeginEdit EndEdit , CancelEdit , BeginEdit. , . , , . property IsNew: Boolean;

, .

524

IV. .NET

property IsNew: Boolean;

True , . , . item property Count: Integer;

function AddNew: DataRowView;

property AllowNew: Boolean;

procedure Delete(index: Integer);

. property AllowDelete: Boolean;

property AllowEdit: Boolean;

, . , AllowNew, AllowEdit AllowDelete . function Find(key: TObject): Integer; function Find(key: array of TObject): Integer;

item . key , , . , , , . , function FindRows (key": TObject): array of DataRowView; function FindRows(key: array of TObject): array of DataRowView;

24. ADO.NET

525

property Sort: string;

. ( ), . , . ASC DESC :DataViewl. Sort := 'Name, Area ASC;

property RowFilter: string;

, . :DataViewl.RowFilter := 'Area > 100000'; DataViewl.RowFilter := 'Capital = 'Lima 1 '; DataViewl.RowFilter := 'Area > 1000000 OR Name = 'Argentina 1 ';

, Expression . , . property RowFilterState: DataViewRowstate;

DataViewRowstate : None ; Unchanged ; Added ; Deleted ; ModifiedCurrent ; currentRows ; ModifiedOriginal .

SQL ADO.NET SQL ( Data Definition Language, Data Manipulation Language) SQL. .

526

IV. .NET

Delphi SQL Sqicommand. . , , SQL . -, SQL . , SqlDataAdapter sqicommand, . sqicommand. ADO.NET SqlConnection Fill.SelectCommand.Connection property Connection: SqlConnection;

. SQL. , sqicommand , . SQL Fill.SelectCommand.CoramandText

property CommandText: s t r i n g ;

, Country Delphi :SELECT * FROM Country

, :SELECT Name, Capital, Population FROM Country

. INSERT, UPDATE, DELETE. SQL . CommandText . CommandText . CommandText , . CommandText , property CommandType: CommandType;

24. ADO.NET

527

: Text SQL; storedProcedure ; TableDirect . , - F i l l . SelectCommand. P a r a m e t e r s property Parameters: SqlParameterCollection;

. (. 24.9). Members . , . . , Parameters . sqicommand function CreateParameter: SqlParameter;

, .SqlParameter Collection EditorMembers: Parameteri Properties: a Dai Direction Precision Scale Size SourceColumn SourceVersion SqIDbType Value ParameterN ame input 0

Parameter!Parameter Pararneter3

00 Current NVarChar

i |

Misc

Parameter^j:

1 :Remove

|

OK

Cancel

Help

. 24.9. F i l l . SelectCommand. P a r a m e t e r s

528

IV. .NET

, , . Sqicommand . ( , ), , function ExecuteReader: SqlDataReader; function ExecuteReader(behavior: commandBehavior): SqlDataReader;

SqlDataReader. SqlDataReader . . behavior ExecuteReader. CommandBehavior : Default , ; singleResuit ; schemaOnly ( ); Keyinf ( , , ); singieRow () ; sequentialAccess , BLOB; cioseconnection . function ExecuteXmlReader: XmlReader;

, XML. XmlReader. function ExecuteScalar: TObject;

- . , . 0

24. ADO.NET

529

. SELECT , , . , function ExecuteNonQuery: Integer;

, INSERT, UPDATE, DELETE. . ( SqlDataReader, xmlReader), , . sqicommand property UpdateRowSource: UpdateRowSource;

. UpdateRowSource : None ; FirstReturnedRecord ; OutputParameter ; Both , . , , . property Comma'ndTimeout: Integer;

. . 0 . . procedure Cancel;

. , : , , . . . sqicommand procedure Prepare;

530

IV. .NET

. , . , ADO.NET . . property Transaction: SqlTransaction;

SqlTransaction.

ADO.NET Delphi , Windows Forms . , Delphi 2005 . , . , , - DataGrid, . DataGrid Data Controls . , . , ' Data.DataBinding.Text . (. 24.10), , . , DataSet, DataTabie, , Dataview. , , , . Data.DataBinding.Text , . . Data.DataBinding.Text . Data.DataBinding.Tag . , Data. DataBinding.Text,

24. ADO.NET

531

.~5~\ ,i? Object Inspector S ] jRichTextBoxl 5ysti

; j ; EiAccessibiHty ""Object Inspector f e Configurations S (DynamicPropertj

I

3i

DataBRDataBindings) j(Advanced) Tag I (None)

+ *! + t

x DBS!

1 Text dalaSet2 customer DataTablei dataSeti

[(No'nejj

SlLavout [fext!l object selected

. 24.10. , , D a t a . D a t a B i n d i n g . T e x t

DataGrid . ADO.NET . , , DataGrid, , , , , DataGrid. . Windows Forms , . . . Data. DataBinding. Tag, . : Panel, TabControl, PictureBox, Splitter, ToolBar, MonthCalendar, PrintPreviewControl, PropertyGrid, ToolTip. .

532

IV. .NET

Label LinkLabel Label, LinkLabel , Data. DataBinding. Text . " ". Data. DataBinding. Tag, .

Button Button . " ". Data.DataBinding.Text Data.DataBinding.Tag.

TextBox TextBox . " ". Data.DataBinding.Text Data.DataBinding.Tag.

CheckBox CheckBox , . Data. DataBinding. Text Data. DataBinding.Tag. , , . checkAlign ( ), Checked ( ), checkstate ( 1, ) Data.DataBinding. - . . , , Checked CheckState. " " , CheckState Indeterminate.

24. ADO.NET

533_

RadioButton RadioButton , . Data. DataBinding.Text Data. DataBinding.Tag. checkAlign, Data.DataBinding. , , Delphi , , checked, . , Delphi Data. DataBinding. Checked.

ComboBox ComboBox . Data.DataBinding.Text Data.DataBinding.Tag. , , , . Data.DataSource (, , ), Data.DispiayMember . , , . . Data.items, Data.DataSource Data. DisplayMember .

Data. DataBinding. Selectedltem ,

.

ListBox ListBox . . , , ListBox Data.DataBinding.Text. - Data.DataSource, , , . Data.DispiayMember . Data.DataBinding.Selectedlndex, Data.DataBinding.Selec tedltem Data. DataBinding. SelectedValue .

534

IV. .NET

CheckedListBox CheckedListBox . Data.DataBinding.Selectedlndex, Data.DataBinding.Selectedltem Data.DataBinding.SelectedValue. , .

TreeViewvi ListView TreeView Listview . Data. DataBinding. Tag.

, , . .

DateTimePicker DateTimePicker DateTime. Data.DataBinding.value, DateTime. Data.DataBinding.Text . , DateTimePicker Data. DataBinding.Tag.

TrackBar, ProgressBar, VScrollBar HScrollBar TrackBar, ProgressBar, VScrollBar HScrollBar : . D a t a . D a t a B i n d i n g . Value.

. , Data.DataBinding.Tag.

NumericUpDown NumericUpDown .

24. ADO.NET

535

Data.DataBinding.value. . Data. DataBinding.Tag.

DomainUpDown DomainUpDown . Data.DataBinding.Text Data.DataBinding.Tag.

GroupBox StatusBar GroupBox statusBar . " ". Data. DataBinding. Text Data.DataBinding.Tag.

RichTextBox RichTextBox , . , . Data. DataBinding.Text Data.DataBinding.Tag.

DataGrid DataGrid , . . . .

Data.DataSource, , , . , . . .

536

IV.

.NET

, , , (. 24.11). WinForm

; Jali= ''01.08.2005'' AND PartDat= :Ord A D RM HR N EmpNo = :Emp', FParams, FDataSet); if Assigned(FDataSet) then with FDataSet do

28. dbExpress .NET begin Open;while Not EOF do begin Next ; end; Close; end; finally FParams.Free; end; end;

667

, function ExecuteDirect(const SQL: string ): LongWord;

0 , . procedure GetTableNames(List: TStrings; SystemTables: Boolean = False); procedure GetTableNames(List: TStrings; SchemaName: string; SystemTables: Boolean = False);

. SystemTables List . GetTableNames TTableScope = (tsSynonym, tsSysTable, tsTable, tsView); TTableScopes = set of TTableScope; property TableScope: TTableScopes; , . , procedure GetFieldNames(const TableName: String; List: TStrings); procedure GetFieldNames(const TableName: String; SchemaName: string; List: TStrings);

procedure GetlndexNames(const TableName: string; List: TStrings); procedure GetlndexNames(const TableName: string; SchemaName: string; List: TStrings);

668

V. VCL.NET

List. procedure GetProcedureNames(List: TStrings); procedure GetProcedureNames(const PackageName: string; List: TStrings); procedure GetProcedureNames(const PackageName: string; const SchemaName: string; List: TStrings);

, procedure GetProcedureParams(ProcedureName: String; List: TList); procedure GetProcedureParams(ProcedureName: String; PackageName: string; List: TList); procedure GetProcedureParams(ProcedureName: String; PackageName: string; SchemaName: string; List: TList);

.

BDE dbGo TSQLConnection . , procedure StartTransaction(TransDesc: TTransactionDesc); procedure Commit(TransDesc: TTransactionDesc); procedure Rollback(TransDesc: TTransactionDesc);

TtransactionDesc :TTransIsolationLevel = (xilDIRTYREAD, xilREADCOMMITTED, xilREPEATABLEREAD, xilCUSTOM); TTransactionDesc packed record TransactionID LongWord; GloballD IsolationLevel Customlsolation end; LongWord; TTransIsolationLevel; LongWord;

TransactionID IsolationLevel. XHCUSTOM customlsolation. GloballD Oracle.

28. dbExpress .NET

669

, property TransactionsSupported: LongBool;

, property InTransaction: Boolean;

True. , , :var Translnfo: TTransactionDesc; if Not MyConnection.InTransaction then try MyConnection.StartTransaction(Translnfo); {} MyConnection.Commit(Translnfo); except MyConnection.Rollback(Translnfo); end;

dbExpress, , BDE, dbGo, InterBaseExpress. TSQLDataSet, TSQLTable, TSQLQuery TSQLStoredProc.

TSimpleDataSet , , .

, dbExpress, . TDataSet, , dbExpress . .

670

V. VCL.NET

, , , . , TDataSet TCustomSQLDataSet. Data Controls . TDBGrid TDBCtrlGrid, TDBNavigator. He . . . : , TSQLConnection. property SQLConnection: TSQLConnection;

dbExpress .

TCustomSQLDataSet dbExpress TDataSet, TCustomSQLDataSet , , TDataSet. , dbExpress . TCustomSQLDataSet , , . :TSQLCommandType = (ctQuery, ctTable, ctStoredProc); property CommandType: TSQLCommandType;

, ;property CommandText: string;

. SQL (CommandType = ctQuery),

CommandText . , CommandText , SQL . , CommandText .

28. dbExpress .NET

671

, , property NativeCommand: string;

property SortFieldNames: string;

. , . ORDER BY . - property LastError: string;

dbExpress. (, , , ), . property NoMetadata: Boolean;

True. , . . ( ). . TSchemaType = (stNoSchema, stTables, stSysTables, stProcedures, stColumns, stProcedureParams, stlndexes, stPackages, stUserNames); TSQLSchemalnfo = record FType Pattern end; : TSchemaType; : String; ObjectName : String; PackageName : string;

property Schemalnfo: TSQLSchemalnfo;

TCustomSQLDataSet.

672

V. VCL.NET

FType . objectName , , .

! , FType stNoSchema. CommandText .

Pattern , . , Mask . % _. , , % . % Tag TComponent, TCustomSQLDataSet property DesignerData: string;

. , , .

TSQLDataSet TSQLDataSet SQL ( TSQLQuery), ( TSQLTable) ( TSQLStoredProc). commandType (. ). ctTable, CommandText , , , . ctQuery CommandText SQL. CommandType ctstoredProc, CommandText . : Active Open. SQL , function ExecSQL(ExecDirect: Boolean = False): Integer; override;

28. dbExpress .NET

673

ExecDirect , . , ExecDirect False. sortFieidNames, . Params ParamCheck. property IndexDefs: TIndexDefs;

TSQLTable TSQLTable , TADOTabie, TiBTabie. 24. property TableName: string; , . . ( Active Open) . TSQLTable , , TCustomSQLDataSet. procedure PrepareStatement; override; , . . IndexFieldNames, IndexFields, IndexName. procedure GetlndexNames(List: TStrings); List . " " MasterFields, MasterSource.22 270

674

V. VCL.NET

TSQLTabie . : procedure DeleteRecords;

TSQLQuery TSQLQuery SQL . (. 26). property SQLConnection: TSQLConnection; TSQLConnection. property SQL: TStrings;

property Text: string;

, . property Params: TParams;

property Prepared: Boolean;

True, , :SQLQuery.Prepared := False; SQLQuery.ParamByName('SomeParaml').AsString SQLQuery.ParamByName('SomeParam2 0; dbgVendors.Enabled := Not IsEdit; end; procedure TfmMain.FormShow(Sender: TObject); begin IsEdit := False; SetCtrlState; end; procedure TfmMain.FormClose(Sender: TObject; var Action: TCloseAction); begin DM.SrvrCon.Close ; end; procedure TfmMain.tbConnectClick(Sender: TObject); begin try DM.SrvrCon.Close; DM.SrvrCon.ComputerName := edServerName.Text; DM.S rvrCon.Open; except on E: Exception do MessageDlg(E.Message, mtError, [mbOK], 0); end; SetCtrlState; end; procedure TfmMain.tbEditClick(Sender: TObject); begin IsEdit := True; dbgParts.Readonly := False; dbgParts.SetFocus; SetCtrlState; end; procedure TfmMain.tbCancelClick(Sender: TObject); begin DM.cdsParts.Cancel; DM.cdsParts.UndoLastChange(False); dbgParts.Readonly := True; IsEdit := False; SetCtrlState; end; procedure TfmMain.tbSaveClick(Sender: TObject); begin if DM.cdsParts.State in [dslnsert, dsEdit] then DM.cdsParts.Post;

814dbgParts.Readonly IsEdit := False; SetCtrlState; end;

VI. VCL.NET: = True;

DM.cdsVendorsAftefScroll(DM.cdsVendors);

procedure TfmMain.tbApplyClick(Sender: TObject); begin DM.cdsParts.ApplyUpdates(-1) ; SetCtrlState; end; procedure TfmMain.tbCloseClick(Sender: TObject); begin Close; end; procedure TfnWain.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin if DM.cdsParts.ChangeCount > 0 then if MessageDlg(SaveChangesMsg, mtConfirmation, [mbOk, mbCancel], 0) = mrOk then with DM.cdsParts do begin if State in [dslnsert, dsEdit] then Post; ApplyUpdates