Академический Документы
Профессиональный Документы
Культура Документы
I. DELPHI
1. Delphi
1.1.
1.1.1.
1.1.2.
1.1.3.
1.1.4.
1.1.5.
1.1.6.
1.2.
1.3.
1.3.1.
1.3.2.
1.3.3.
1.4.
1.4.1.
1.4.2.
1.4.3.
1.4.4.
2. Object Pascal
2.1.
2.1.1.
2.1.2.
2.1.3.
2.1.4.
2.1.5.
2.1.6.
2.1.7.
2.2.
2.2.1.
2.2.2.
2.2.3.
2.2.4.
2.2.5.
2.3.
2.3.1.
2.3.2.
2.3.3.
'.
10
10
11
12
14
15
15
15
17
17
19
24
27
27
28
29
30
31
31
31
32
33
36
36
36
37
38
38
38
39
39
39
40
40
40
41
IV
2.4.
2.4.1.
2.4.2.
2.4.3.
2.5.
2.5.1.
2.5.2.
2.5.3.
2.5.4.
2.6.
2.6.1.
2.6.2.
2.6.3.
2.6.4.
,.
2.6.5.
2.7.
2.7.1.
2.7.2.
2.7.3.
2.8. -
2.8.1.
2.8.2.
2.8.3.
2.8.4.
2.8.5.
2.8.6.
3.
3.1.
3.2.
3.3.
3.4.
3.5.
TControl
4.
4.1. TStrings
4.2.
4.3.
4.4.
4.5.
4.6.
4.6.1.
4.6.2.
4.6.3.
5.
5.1.
5.1.1.
5.1.2.
42
42
44
45
47
47
48
49
49
49
49
50
50
51
53
54
56
57
58
60
60
62
63
63
64
65
67
67
70
71
79
84
85
85
89
90
93
95
98
98
100
102
105
105
105
108
-
-
2003
681.3.06
32.973.26-018
74
74
. ., . .
Delphi. . .: -, 2003. 288 : .
ISBN
5-94157-165-8
:
.
I S B N 5-94157-165-8
. ., . ., 2002
, "-", 2002
5.2.
5.2.1.
5.2.2.
5.3.
5.3.1.
5.3.2.
5.3.3.
6.
6.1.
6.2.
6.3.
6.4.
6.5.
6.6.
,
.....
7.
7.1.
7.2.
7.3.
7.4.
II.
8.
8.1.
8.1.1.
8.1.2.
8.2.
8.2.1.
8.2.2.
8.2.3.
8.2.4.
8.2.5.
8.2.6. -
8.2.7.
8.3.
8.3.1.
8.3.2.
8.4.
8.5.
8.5.1.
8.5.2.
8.5.3.
8.5.4.
8.5.5.
8.5.6.
111
113
115
116
116
117
119
120
134
136
140
142
146
148
150
151
152
153
155
157
157
157
159
160
160
163
165
166
169
170
171
174
174
175
178
178
180
181
184
184
185
185
Vl_
8.5.7.
8.5.8.
8.6.
9.
9.1.
9.1.1.
9.1.2.
9.1.3.
9.1.4.
9.1.5. Table
9.1.6. Query
9.1.7.
9.1.8.
9.1.9.
9.1.10.
9.2.
9.2.1.
9.2.2.
9.2.3.
9.2.4.
10.
10.1.
10.2.
10.3.
10.4.
10.4.1.
10.4.2.
10.5.
10.5.1.
10.5.2.
10.5.3.
10.6.
10.6.1.
10.6.2.
11.
11.1.
11.1.1. -
11.1.2.
11.1.3. ,
11.2.
11.2.1.
11.2.2.
11.2.3.
11.2.4.
185
186
187
190
190
190
193
195
197
198
200
204
206
208
210
211
213
213
217
222
225
225
228
232
237
237
239
239
241
246
249
250
251
260
262
262
262
268
269
272
274
274
275
275
276
- Delphi, Object Pascal. Delphi
.
Delphi . Delphi, ( ,
),
.
, Delphi. , .
, . ,
4-6- Delphi.
6-
.
.
I. Delphi.
, . Object Pascal: , , , - .
,
. , ;
TControi, , .
()
, .
Tstrings,
; Label, (,
); Edit, MaskEdit, Memo RichEdit, ; .
. , , , ,
.
, , Windows. , .
( ),
.
II. .
;
(, , ,
, .);
; ; .
: .
, . , .
Table Query. TFieid, ,
. ,
. ,
(
, ).
, Table Query. ,
: , , ,
, .
.
,
,
. ,
; ; .
.
Delphi
1. Delphi
2. Object Pascal
3.
4.
5.
6.
7.
Delphi
, , Delphi
IDE
(Integrated
Development
Environment). IDE ,
.
,
.
, , .
Delphi . ()
. Delphi
, . 1.1, :
(Delphi 6 Projectl);
G (Object TreeView);
G (Object Inspector);
G (Forml);
G (Unitl.pas);
G (Exploring Unitl.pas).
, , ,
, ,
(Image Editor). Delphi,
( ),
.
, Delphi (
Delphi.
).
.
6- Delphi. . ,
5- .
..-'1
- -
J'iiSSSb'JKSkr 1
1 4 ia 1
i
*
- '*
'I*
1"
t
1
,
-
.1
l"
. 1.1.
Delphi ,
Delphi . Delphi :
;
;
.
Delphi,
.
, , File | Open ( | ) Run
Run ( | ).
I. Delphi
, .
, Run | Run ( | )
<F9>, View | Units ( | )
<Ctrl>+<F12>.
6 :
Standard ();
View ();
Debug ();
Custom ();
Desktop ( );
Internet ().
.
,
.
Component Palette ( ).
,
. ,
.
, , .
. :
Standard ();
Additional ();
Win32 (32- Windows);
System ( );
Data Access ( );
Data'Controls ( );
BDE ( BDE ( 6- ));
QReport ( );
Dialogs ( ).
Forml. ,
Delphi.
.
,
.
" ",
,
.
( Unit I.pas)
. ()
, , , . , .
Code
Unitl Formi
.
<F12>.
(Exploring Unitl.pas)
.
, , (. 1.2).
, .
Code Explorer ( )
View ().
1Expl
oring Unit 1.pas
i_J Classes
- *$ TFormlfTForm)
fe _! Fublished
Button1:TButton
DataSource1:TDataSource
> DBGrid1:TDBGrid
't Edit1:TEdit
i FormCreate(Sender:TObject)
y> LabelVTLabel
/ Table! :TTeble
_J Variables/Constants
!
~p Formi TFormi
I ) Uses
_*j
. 1.2.
Formi.
I. Delphi
10
Delphi.
View ()
. ,
View | Code Explorer ( | ).
1.1.
1.1.1.
Delphi ,
. (
):
(DPR);
(DFM);
(PAS);
(PAS);
(DOF);
(RES).
()
. 1.3.
()
\i
<
/
V
. 1.3.
,
, , : ~DP DPR; ~ PAS.
I. Delphi
Delphi Projecti,
Delphi.
Formi, . ,
, , Delphi , .
.
,
,
, .
1.1.2.
. ,
, :
program Projecti;
uses
Forms,
Unitl in 'Unitl.pas' {Forml};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm{TForml, Forml);
Application.Run;
end.
()
, Projecti. To
,
.
.
(-) (DLL-) .
, , .
12
Delphi.
uses Forms,
,
. , uses
, unitl Formi.
$R ,
, .
*.
,
$R .
, , Formi . .
-
Delphi . ,
,
,
. ,
. , ,
, Application
Delphi
.
Project | View
Source ( | ).
,
.
1.1.3.
(DFM) (PAS).
Delphi
.
.
.
, View as Text ( )
. , -
I. Delphi
13
.
,
, .
, () TForml .
View | Forms ( | ) <Shift>+<F12>,
View Form ( )
(. 1.4), .
Iview Form
. 1.4.
.
File | Close ( | )
.
. ,
,
:
unit Unitl;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs;
type
TForml = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
Delphi.
end;
var Forml: TForml;
implementation
{$R *.dfm}
end.
Delphi
. TForm,
.
interface ,
implementation $R . , .
Delphi , .
, ,
.
. ,
File | Open ( | )
View Unit ( ),
View | Units ( | )
<Ctrl>+<F12>. .
( )
.
, ( ) , , ,
.
DCU, .
, ,
Delphi
.
1.1.4.
, , , - . -
I. Delphi
15
Object Pascal
. uses
, .
, , , .
1.1.5.
(RES) , .
:
;
;
.
Windows.
, .
Delphi Image Editor 3.0, Tools | Image Editor
( | ).
1.1.6.
(Project Options), Project | Options ( | ) <Ctrl>+<Shift>+<FH>. ,
,
.
1.2.
,
()
(DLL). -.
, , ,
Delphi.
Project | Compile
<Projectl> ( | <>)
16
Delphi.
<Ctrl>+<F9>. ,
, Projectl.
.
. ,
. :
,
. DCU. - ,
;
,
,
u s e s ;
(OBJ) (INC),
;
.
.
, , ,
.
Project | Build <Projectl> ( | <1>).
Delphi
Windows.
Delphi Run | Run
( | ) <F9>.
.
,
. ,
Delphi, :
;
;
()
Delphi Run | Program Reset
( | )
<Ctrl>+<F2>.
I. Delphi
77
Delphi
.
Windows
, , .
1.3.
Delphi ,
RAD (Rapid Application Development,
). Delphi
:
;
.
, () , , . , ().
.
, , , .
,
.
1.3.1.
. ""
, . Delphi , .
Delphi "" .
Windows: Forml, ,
, .
_/S
Delphi.
Delphi .
Windows
,
, . Delphi
Windows, (),
.
,
. , , Windows,
.
, .
, ,
. ,
. Delphi, , " ".
" " . ,
, ,
, . ,
. ,
, ,
, , .
,
Windows .
Windows , ,
,
, .
Windows, Delphi .
, Delphi ,
( 6- 355 ).
, , .
I. Delphi
19
1.3.2.
, ,
. WYSIWYG (What You See Is What
You Get, , ), , .
() ().
,
.
, , , , .
,
.
.
, , , , Timer
Table. Timer
, Table .
:
;
.
, . ,
, .
, .
, , Button,
.
, ,
.
,
. ,
.
20
Delphi.
Delphi, , . , .
, , Button, TButton, Label,
TLabel.
Delphi
.
( )
< >:
< >;
Name, . , Button
:
Buttonl: TButton;
<Shift>.
, .
.
. ,
.
.
<Shift>.
,
,
(. 1.5).
,
. ()
, .
,
, .
,
.
, .
, . -
I. Delphi
Buttoni
Properties j Events
Action^ _ !
iBAnehors._
i[akLeflakTop]
BiDiMode "' bdLeffToRight
Cancel
.False
21
_] -:
;
'
-:
. 1.5.
. , ,
, ,
.
,
.
.
.
("") .
,
. , . ,
caption ()
.
<Enter> .
<Esc>.
, , . ,
, Name
.
, , Color
(), Caption () visible (),
.
Name
TComponentName, . ,
22
Delphi.
TComponentName string. ,
, ,
. , Edit
Editi, Edit2 . .
.
. ,
.
.
, , Edit edt, Label 1,
Form fin. To ,
, N a m e E d i t
edtName. ,
, ,
.
, , Labell, Edit2 Button3.
, (,
Left width),
.
, , .
.
:
()
,
Delphi. , Caption,
Left, Height Hint;
. ,
. ,
,
, . , . ,
FormStyle,Visible ModalResult;
I. Delphi
23
.
+. ,
. ,
True False. True , , a False . , Borderlcons Anchors;
, ,
(),
. , Font, items Lines.
- ,
, (TFont) (TSrings). -
+,
. ,
, .
. ,
, . , Font Windows .
(
) , , . ,
Buttoni :
Buttoni.Caption := '';
,
, ,
,
.
,
,
.
, ,
. , ,
RecordCount canvas
.
Delphi.
24
1.3.3.
. , , .
, , ,
. Windows.
. , , , ,
, , . .
, Button, .
Buttoni, (
caption)
. Buttoni
. , , , . , - , .
- , ,
.
, ,
,
(. 1.6).
Object Inspector
[Buttoni
Properties Events
Action
i
OnClick
OnContextPopupj
OtiDragDrop
OnDragOver I
OnEndDock \
i OnEndDrag !
!AII shown
'1
TSuU'.-n
. 1.6.
I. Delphi
25
Onclick,
.
Onclick, Delphi
-.
,
, ,
Buttoni. ,
Formi.close close.
:
unit Uhitl;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForml = class(TForm)
Buttoni: TButton;
procedure ButtonlClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var Formi: TForml;
implementation
{$R *.DFM}
procedure TForml.ButtonlClick(Sender: TObject);
begin
Formi.Close;
end;
end.
, ,
Delphi , - Formi.
26
Delphi.
Delphi
.
end;
private public
.
Delphi
Object Pascal.
,
, . <1>+<>
. .
, ,
.
<Ctrl>+<J>. . ,
:
if
then
else
TForml.ButtonlClick
on. , ,
onclick.
(DFM PAS) .
. .
- ,
.
.
I. Delphi
27
-
.
, .
, . .
,
.
.
,
.
()
.
,
.
1.4.
, .
Delphi.
1.4.1.
,
.
Run () View | Debug Windows ( | ) , :
( );
;
(Breakpoint);
;
, , ;
.
2 .
Delphi.
28
Debugger
Options ( ) (. 1.7), Tools ().
(Debugger Options
General | Event Log | Language Exceptions j OS Exceptions |
General -
F Integrated debugging
OK
Cancel
Help
. 1.7.
Integrated debugging ( ),
, . , , ,
.
1.4.2.
(Project Browser Browser)
, , , , , ,
.
,
. View | Browser
( | ).
I. Delphi
29
1.4.3.
Delphi
.
(Repository).
, File | New |
Other ( | | ) New Items ( )
(. 1.8).
New () .
, ,
, , , .
'New Items
Data Modules | Business, | . WebSJnap I . SOAP j Corba"
New .1 ActiveX,! Multifer | Project! Forni j Dialogs | Projects^
Dual list box QuickReport QuickReport QuickReport
Labels
List
Master/Detail
Tabbed
pages
\Qopy
. 1.8.
, ,
:
New ;
Projectl ;
Forms ;
Projects ;
Data Modules ;
Business .
30
Delphi.
Projectl ,
, Forml.
.
.
.
, . . 1.8 About box
( ), Forms ().
.
,
. (),
. ,
, .
, , ,
File | New,
Application, Form, Frame, Data
Module Unit.
1.4.4.
Delphi :
, Internet - .
,
Delphi Help ( Delphi) Delphi Tools
( Delphi) Help ().
,
, Help Topics: Delphi Help ( Delphi).
Internet Help (), (), Micrisoft Internet Explorer,
Web-. , Borland Home Page (
Borland) Borland.
- <F1>, ,
( , . .) .
Object Pascal
Object Pascal Delphi - Pascal.
Delphi
VCL.
2.1.
2.1.1.
Object Pascal :
53 (AZ) (az)
(_);
0, 1,..., 9;
23 + - * / . , : ; = > < () {} [ ] # $ @
.
:
:= ,
<> ;
.. ;
<= ;
>= ;
(* *) { };
(. .) [ ].
32
Delphi.
2.1.2.
,
.
, , ,
.
:
;
;
.
() ,
,
. , :
Label, Unit, Goto, Begin, Interface. .
:
;
;
.
. ,
- . sin, pi,Real.
,
, , , . .
.
, , 0
9999.
,
, . , , ,
btnOpen, ,
, , P i c t u r e i D .
.
I. Delphi
33
2.1.3.
, .
.
:
Program < >;
: . ,
, .
:
;
;
;
;
;
.
.
:
Program < >;
Uses < >;
Label < >;
Const < >;
>;
Var >;
>;
< >;
Begin
<>;
End.
. ,
, ,
.
, . .
34
Delphi.
uses
. :
Uses <1>, <2>, ... , <>,-
. .
Uses Crt, Dos, MyLib;
Label,
, .
:
Label <1>, <2>, ... , <>;
. .
Label metkal, metka2, 10, 567;
.
const, ,
. , .
, . :
Const <1> = <>;
<> = <>;
. .
Const stl = 'WORD'; ch = '5'; n34 = 45.8;
.
Delphi , , , Nil, True Maxint.
.
,
. , ,
.
. :
< 1> = >;
< > = <0 >;
I. Delphi
35
. .
Type char2 = ( ' ' .. ' z ' ) ;
NumberArray = a r r a y [ l .. 100] of r e a l ;
Month =1 .. 12;
, . , .
,
. : . . .
Begin,
, .
End, .
:
Begin
<1>;
<0>;
End.
3(5
Delphi.
, ,
.
2.1.4.
, , . (* *) { } , . ,
, . //.
. .
(* *)
//
(*
*)
. - .
2.1.5.
, . , .
, ,
, .
.
, .
,
, .
2.1.6.
,
, , .
, -34 67
I. Delphi
37
, , , abed sdfhi23
(), .
:
;
;
;
.
, , , .
, , , .
, ,
. , ,
,
, .
2.1.7.
,
. Delphi
:
;
.
, ,
.
. , .
,
. ,
.
begin end,
, . -
38
Delphi.
then else. ,
do
, .
2.2.
,
.
:
;
();
();
.
, , ,
. .
2.2.1.
.
integer, -2 147 483 648
2 147 483 647.
+ -,
, .
, . , $ ( ),
$00000000 $FFFFFFFF.
2.2.2.
,
. Object Pascal char,
, ANSI (American National
Standards Institute).
:
chr(x) : char , ;
upCase () : char .
I. Delphi
39
2.2.3.
Object Pascal Boolean.
: True () False (). .
2.2.4.
, . () .
, , ,
, . ,
.
,
. , , . . :
< > = <1> .. <2>;
. .
Type Dayl_31 = 1..31;
Var dayl, day2 : Dayl_31;
dayl day2 Dayi_3i
1 31.
2.2.5.
() .
Real, 1,7308 1516 .
. .
. + -.
40
Delphi.
, . , ( ).
12 . 5, - 1 3 7 . , + 1 0 + 3 .
currency
.
:
Round (X) ;
() .
2.3.
,
. :
;
;
;
;
;
.
, ,
.
2.3.1.
s t r i n g ,
210 31 . ANSI.
,
() , , strName [ i ] .
2.3.2.
, .
, .
( ) , .
() , , ,
a r r l [ 3 , 35] , arrl[3] [35] [7].
(,
. .), . ,
I. Delphi
41
.
.
. .
. , .
:
Array [ ] of < >;
. .
Type tm = Arraytl .. 10, 1 .. 100] of real;
Var arrl, arr2: tm;
arr3:
Array[20 .. 100] of char;
arr4:
Array['a' .. 'z'] of integer;
a r r l arr2 .
real. a r r l 2 tm. 4
81 26 .
2.3.3.
, .
, 256. :
Set of < >;
. . [ ].
Delphi , ,
TBordericons
TFilterOptions:
type TBorderlcon = (biSysteniMenu, biMinimize, biMaximize, biHelp);
TBordericons = set of TBorderlcon;
type TFilterOption = (foCaselnsensitive, foNoPartialCompare);
TFilterOptions = set of TFilterOption;
42
Delphi.
Forms Db,
.
2.4.
, . ,
, . :
;
;
.
. .
, . (), , .
, .
.
, , , -.
,
, , X+Y.
.
:
, .
2.4.1.
, , .
( ), , .
. , .
,
. , .
I. Delphi
43
(+ ,
, * / ), ,
(+ ),
.
.
System, s y s u t i i s Math ,
. :
Abs (X) ;
Sqrt (X) ;
sqr () ;
Ln(x) ;
(X) ;
sin () , .
, ,
.
. .
( + 12.3) / 30 * sin(2 * alpha)
+
()
, , :
Div ;
Mod .
. .
, d (integer)
: := ; := 7; d := -56. :
+7
56 - 8
5 *d
56 / b
56 div b
40 div 13
40 mod 13
17
48
-280
8.0
8
3
1
44_
Delphi.
(~
~^)
Object Pascal .
()
. X
( * L n ( X ) ) .
2.4.2.
True
False. :
T r u e F a l s e ;
boolean;
();
;
.
, , ,
:
= ,
< ,
> ,
<= ,
>= ,
.
. False,
, True, .
, .
, , .
( boolean) (. 2.1) ( )
(boolean). And, Or
, Not . , Object Pascal -
I. Delphi
45
() , () .
2.1.
not
and
or
xor
1
False
True
False
False
True
True
False
False
True
True
False
False
True
True
False
True
False
True
False
True
False
True
False
True
False
True
True
False
False
False
False
True
False
True
True
True
False
True
True
False
.
< 10
+ 17 >=
( > a) and ( < )
, , , ,
.
2.4.3.
.
+, ()
, :
Length (s): integer s;
Copy(S;
Index,
Count:
Integer):
S t r i n g S
count . ,
index;
46
Delphi.
Pos(Substr: String; S: S t r i n g ) : I n t e g e r
() , substr
s, . ,
:
Insert(Source: String; var S: String; Index: Integer)
source s, index;
Delete(var S: String; Index, Count: Integer) S
count, index;
Val(S; var V; var Code: Integer) S
v. . code
, ,
;
s t r ( x [: width [: Decimals ] ] ; var s)
s.
,
Sysutiis.
:
intToStr (Value: i n t e g e r ) : s t r i n g value ;
strToint (const s: string) : integer s ;
FioatTostr(Value: Extended): s t r i n g value ;
strToFioat (const s: s t r i n g ) : Extended s
;
DateToStr (Date: TDateTime) : S t r i n g
Date ;
TimeTostr(Time: TDateTime): s t r i n g Time ;
StrToDate (const S: String): TDateTime S
;
StrToTime (const S: String) : TDateTime S BO
;
Uppercase (const S: String): String s ;
Lowercase (const S: S t r i n g ) : String s ;
I. Delphi
47
Trim(const s: string) : s t r i n g s
;
TrimLeft(const S: S t r i n g ) : String s;
TrimRight(const S: S t r i n g ) : S t r i n g s.
, TDateTime, a
, NOW(), Date Timed,
.
. .
'abcdk' + s
2.5.
, .
:
;
;
;
.
2.5.1.
. , , , .
, , , . , . :
< > := <>;
. , := = . ,
48
Delphi.
. ,
, :
:= + 1;
. .
Var , :
real;
n:
integer;
stroka:
string;
n := 17 * n - 1;
stroka := ' ' + DateToStr(Date);
x := -12.3 * sin(pi / 4);
:= 23.789+3;
2.5.2.
. ,
, - . , , .
,
0 9999,
,
, . :
goto <>;
. .
Label ml;
g o t o ml;
ml: <>;
, .
, , , (, ).
I. Delphi
49
2.5.3.
, .
, .
.
2.5.4.
.
.
2.6.
, . :
;
();
2.6.1.
, , begin end. :
begin <1>;
, , . .
. .
begin
;
Editl.Text := '';
Exit;
end;
50
Delphi.
, , .
.
2.6.2.
.
:
if <> then <01> [ else <02> ];
2.6.3.
, .
, , else, , .
:
case <-> of
<1> : <1>;
<CnncoKN> : <OnepaTopN>
else <>;
end;
I. Delphi
51
- . ,
, , . , . " . . " .
-.
:
;
;
,
. ;
, ,
else ( ).
. .
case DayNumber of
1 .. 5 : strDay := ' ';
6, 7
DayNumber, , strDay.
2.6.4.
().
, .
. .
. :
;
;
.
52
Delphi.
, , , - ( ).
goto
Break, .
continue
,
.
.
:
for <> := <1> to <2> do <>;
,
, , ! 2
,
.
,
do,
. 1 -1 .
(for.. .to)
(for.. .downto) .
, f o r . . . t o
, for.. .downto, , .
. .
var n, k: integer;
s := 0;
for n := 1 to 10 do s := s + m[n];
for := 0 to 2 do
for n := 5 to 10 do begin
I. Delphi
53
arrl[, n] := 0;
arr2[k, n] := 1;
end;
.
, a r r l 2.
,
.
r e p e a t . . . u n t i l , .
:
while <> do <>;
,
False, ,
True.
. .
.
var x: integer;
sum: real;
:
x : = 1; sum := 0;
while x <= 10 do begin
sum := sum + m[x];
x := x + 1;
end;
(
False), , .
2.6.5.
, . , ,
.
- , , . :
54
Delphi.
, do,
,
with.
. .
//
Forml.Canvas.Pen.Color := clRed;
Forml.Canvas.Pen.Width := 5;
Forml.Canvas.Rectangle(10, 10, 100, 100);
//
with Forml.Canvas do begin
Pen.Color := clRed;
Pen.Width := 5;
Rectangle(10, 10, 100, 100);
end;
.
()
( ).
, , .
2.7.
, .
.
.
,
. ,
.
:
;
.
I. Delphi
55
,
. ,
.
( ), .
Delphi , . .
, , .
, . ,
.
.
.
,
. :
;
;
.
.
. ( )
, .
( )
. .
. ,
,
.
Exit, .
,
.
56
Delphi.
2.7.1.
, .
procedure,
. :
Procedure <> [ ( ) ];
.
,
.
. .
Buttoni, DecodeDate ChangeStr.
procedure TForml.ButtonlClick(Sender: TObject);
// ChangeStr
procedure ChangeStr( Source: string; const charl, char2: char);
label 10;
var n: integer;
begin
10:
n := pos(charl, Source);
if n > 0 then begin
Source[n] := char2;
goto 10;
end;
end;
var strl: string;
Year, Month, Day: word;
begin
// DecodeDate
DecodeDate(Now, Year, Month, Day);
strl := Editl.Text;
// ChangeStr
ChangeStr(strl, '1', ' * ' ) ;
Editl.Text := strl;
end;
I. Delphi
57
s t r i
2.7.2.
. Function, , , ,
. :
Function <> [ ( ) ] : <
, .
, .
, .
, . ,
.
Result,
. , Result
. Result
.
,
.
, .
, ,
. ,
.
58
Delphi.
. .
Buttoni, Length ChangeStr2.
procedure TForml.ButtonlClick(Sender: TObject);
// ChangeStr2
function ChangeStr2(Source:
label
char2:
char):
string;
10;
var n:
integer;
begin
Result := Source;
10:
n := pos(charl, Result);
if n > 0 then begin
Result[n] := char2;
goto 10;
end;
end;
var strl: string;
n:
integer;
begin
strl
:= Editl.Text;
// ChangeStr2
strl := ChangeStr2(strl, 1 , ' * ' ) ;
Editl.Text := strl;
// Length
n := Length(strl);
end;
Length
, system.
Changestr2 , changestr
.
.
2.7.3.
.
.
I. Delphi
59
, .
:
;
;
;
.
,
var const , -. , g - :
procedure PI(a: real; g: integer);
- . ,
,
-.
,
const , . ,
procedure P2(const , : integer);
-.
- . -
,
. , -
.
,
var , -.
, - f :
function Fl(var d, f: real; ql7 : integer): real;
- ,
.
-, .
.
- -
, . ,
3 . 641
60
Delphi.
. - - :
function F2 (var el; const t2): integer;
,
.
2.8. -
Object Pascal -
Pascal - . , , . ,
() , , , , .
2.8.1.
Object Pascal . , , .
, (), , . .
, .
.
, , , ; ,
.
:
< > = class (< ->)
private
< >;
protected
>;
public
< >;
published
>;
end;
I. Delphi
61
, .
. .
type
TColorCircle = class(TCircle);
FLeft,
FTop,
FRight,
FBottom: Integer;
Color: TColor;
end;
TColorCircle
TCircle. , integer TColor.
Tobject, , class
. :
type TNewClass = class
(), ,
.
private protected , , .
protected, ,
.
public ,
, .
published ,
(. . ) (Run-Time Type Information,
RTTI).
.
published
. , . published , , , ,
.
var
. ,
62
Delphi.
var
CCirclel: TColorCircle;
CircleA:
TCircle;
,
(, ) , , . . .
. .
var
CCirclel: TColorCircle;
begin
CCirclel.FLeft:=5;
CCirclel.FTop:=l;
end;
,
.
2.8.2.
, . .
. .
type TNewCiass = class(TObject)
private
FCode: integer;
FSign: char:
FNote: string;
end;
TNewCiass Tobject
Fcode, FSign FNote, ,
, , .
, f (
. Field ).
- ,
.
,
.
I. Delphi
63
2.8.3.
. , , ,
. property,
.
read write , , , .
. .
type TNewClass = class(TObject)
private
FCode: integer;
FSign: char:
FNote: string;
published
property Code: integer read FCode write FCode;
property Sign: char read FSign write FSign;
property Note: string read FNote write FNote;
end;
Fcode, FSign Fnote, , code,
sign Note, .
2.8.4.
( ), . .
, . .
, Buttoniciick :
interface
type
TForml = class(TForm)
Buttonl: TButton;
procedure ButtonlClick(Sender: TObject);
end;
64
Delphi.
implementation
procedure TForml.ButtonlClick(Sender: TObject);
begin
Close;
end;
, , ,
. ,
. :
v i r t u a l ; dynamic ; override
; message .
, ,
.
, , , . ,
constructor destructor.
Tobject Create Destroy.
,
. :
ObjectA := TOwnClass.Create;
"" (heap), , n i l
-, ,
.
, .
2.8.5.
Windows
, "" , , , . . Delphi
.
, Windows , ,
message, .
I. Delphi
65
,
, . ,
.
Delphi
Windows, . .
, . ,
. ()
, . .
. .
Application.Onldle:=IdleWork;
onidie, , idiework.
Application ,
.
Delphi , .
TNotifyEvent,
() . :
type TNotifyEvent = procedure (Sender: TObject) of object;
Sender, - .
, , Sender.
2.8.6.
(Visual Component Library, VCL) , . Object Pascal
Delphi. VCL ,
, TObject. , .
VCL
() . , -. , caption
TControi, , ,
TButton TCheckBox Button CneckBox . . 2.1.
66
Delphi.
TObject
TPersistent
TException
TlniFile
TComponent
TCIipboard
TString
TControl
TGraphicControl
I TApplication | |
TScreen
| |
TMenu
TWinControl
. 2 . 1 .
, ,
SOURCE Delphi.
3.1.
Delphi
,
Standard (), Additional () Win32 (32-
Windows) .
, 32- ( Windows 95) .
,
,
, , . , Button BitBtn,
, .
Standard () . 3.1
, Windows:
Frames ;
MainMenu ;
;
Label ;
Edit ;
Memo ;
Button ;
checkbox ;
68
Delphi.
RadioButton ;
ListBox ;
comboBox ;
scroiiBar ;
GroupBox ;
RadioGroup ;
Panel ;
ActionList .
i' Standard | Additional I Win32) Svsteml Data Access] Data Controls) ADO | InterBase! Md
i as
i i Ci 3 V '| '> ft ' H i
. 3 . 1 . Standard
. ,
.
Additional () (. 3.2)
:
BitBtn ;
SpeedButton ;
MaskEdit ;
stringGrid ;
DrawGrid ;
image ;
shape ;
Bevel ;
ScroiiBox ;
checkListBox ;
S p l i t t e r ;
staticText ;
ControiBar ;
ApplicationEvents ;
vaiueListEditor ;
LabeledEdit ;
I. Delphi
69_
coiorBox ;
chart ;
ActionManager ;
ActionMainMenuBar ;
ActionTooiBar ;
CustomizeDig .
ard Additional I Win32 | Svstem] DataAccess] Data Controls j dbExpfess|-DataSrmo| BDE | ADD
. .2. Additional
HeaderControi ;
statusBar ;
TooiBar ;
cooiBar "" ;
Pagescroiier ;
.
6- Delphi.
70
Delphi.
lard | AdcMional Wit)32 j Svstem | Data Access | Data Controls | dbExpress | DataSnap
. 3 . 3 . Win32
, .
3.2. TControl
VCL (Visual Component Library)
TControl,
TComponent. TControl
, . :
.
, .
, , Button Edit.
,
, .
T W i n C o n t r o l T C o n t r o l .
:
;
.
, Edit, DBEdit, Memo DBMemo
( ). . .
, , . , , Button
, ListBox . - , .
. -
I. Delphi
71
. , ,
Label DBText. TGraphicControi,
TControl.
, , TStrings,
.
3.3.
. , ,
. , , .
, .
,
. , , , Edit
C a p t i o n , L a b e l R e a d o n l y .
.
,
Name.
. .
with Edit.Create(Self) do begin
Parent := Forml;
Name := 'edtName';
Text := ' ..';
Left := 100;
Top := 60;
end;
Edit,
edtName.
.
Forml.
72
Delphi.
Align TAiign
, . Form Panel. , , - ,
.
Align :
alNone , , ;
alTop ,
, ;
alBottom alTop,
;
alLeft ,
, ;
aiRight alLeft,
;
1 a i c i i e n t .
Caption TCaption
. , TCaption string. ,
:
<Alt> ,
.
&, :
CheckBoxl.Caption := '& ';
<Alt>+<3>
RadioGroupl.Caption := 'SConditions';
<Alt>+<C>
(~
~}
Windows , , , .
I. Delphi
73
, color. RGB- ( , ), . ,
, $FF, , $, . , .
, $, $FFFFFF,
$OOOOFF, $OOFFOO, $FFOOOO.
. , , . ,
. 3.1, , .
3.1.
clAqua
$FFFF00
clBlack
$000000
clBlue
()
$FF0000
clFuchsia
$FFOOFF
clGray
$808080
clGreen
$008000
clLime
$00FF00
clMaroon
$000080
clNavy
$800000
clOlive
$008080
1 Purple
$800080
clRed
$0000FF
clSilver
$000
clTeal
clWhite
$FFFFFF
$00FFFF
clYellow
$808000
, ciDkGray ciLtGray,
.
74
Delphi.
ciDkGray ciLtGray,
ciGray c i s i l v e r , .
(. 3.2) Windows, Appearance () Display Properties ( ). .
3.2. Windows
clBackground
1ActiveCaption
cllnactiveCaption
clMenu
clWindow
Windows
clWindowFrame
clMenuText
clWindowText
clCaptionText
clInactiveCaptionText
clActiveBorder
clInactiveBorder
clAppWorkSpace
clHighlight
clHightlightText
clBtnFace
clBtnShadow
clGrayText
clBtnText
clBtnHighlight
clScrollBar
cl3DDkShadow
cl3DLight
clInfoText
clInfoBk
I. Delphi
75
, :
crDefauit ( );
crNone ;
Arrow ;
crCross ;
crDrag - ;
crHourGiass .
DragCursor TCursor . cursor.
crDrag.
DragMode TDragMode
, drag-and-drop ( ),
. DragMode
: dmAutomatic dmManuai.
dmManuai, ,
BeginDrag. dmManuai,
.
DragMode ,
, ,
, .
Enabled Boolean ,
, ,
. True ( ),
, . ,
.
(), , ,
Edit. :
Editl.Enabled := false;
Enabled .
, ,
Editl.Text := ' ..';
76
Delphi.
, , Readonly True.
Font TFont , . , TFont ,
. TFont.
Name TFontName , , Arial
Times New Roman. , Name .
size integer . 1/72 .
Height integer .
,
. , .
style TFontstyle :
f s i t a i i c ;
f sBoid ;
fsunderiine ;
fsstrikeOut .
Color TColor .
size Height ,
.
. .
Editl.Font.Color := clGreen;
Editl.Color := clBlue;
Editl
.
Height width integer .
Left integer
, ,
. , ,
.
Left Height width .
I. Delphi
77
HelpContext THeipContext
.
, <F1> , .
Hint s t r i n g , ,
.
( ) , .
, True
showHint Boolean. showHint False,
.
PopupMenu TPopupMenu
,
.
, True AutoPopup Boolean.
False.
Text TCaption , .
. ,
Edit Memo Text
.
TabOrder TTaborder <>, () .
:
TabOrder 0, 1 . . TabOrder .
.
TabOrder;
Delphi ,
. , TabOrder
0, .
TabOrder Tabstop
Boolean, . Tabstop True, , False .
Edit Tab Order ( )
(. 3.4), Delphi
Delphi.
78
OK
Cancel
Help
. .4.
Readonly Boolean ,
. Readonly True,
.
False ( ), . ,
Readonly, , :
Editl.Readonly := true;
Edit1.Text := ' ';
,
. - ,
. (TField) Readonly, .
True,
, .
, Color, Ctl3D, Font
showHint, , , .
I. Delphi
-
Boolean:
Parentcoior ;
Parentcti3D ;
ParentFont ;
ParentshowHint .
True,
.
:
. , 12, , True ParentFont.
- , False. ,
, ,
True.
visible Boolean .
True, , False . ,
, .
. .
Editl.Visible := true;
Edit2.Visible := false;
Editl , Edit2.
3.4.
( ) .
:
;
80
Delphi.
;
;
;
;
drag-and-drop.
Object Pascal, Delphi, .
()
TNotifyEvent, :
type TNotifyEvent = procedure (Sender: TObject) of object;
, , Sender,
. ,
, , , .
.
onclick
TNotifyEvent, .
.
Onclick .
. Editl.
procedure TForml.EditlClick(Sender: TObject);
begin
E d i t l . C o l o r := Random($FFFFFF);
end;
Editl
.
onclick
, ,
, Button <>
<Enter>, <>.
:
OnMouseDown TMouseEvent, ,
OnMouseUp TMouseEvent, .
,
, OnDbiciick TNotifyEvent. -
I. Delphi
81
. ,
, . Y
, .
onKeyPress onKeyDown,
, OnKeyUp, -
82
Delphi.
Char);
Editi
!.
, ASCII-,
OnKeyDown OnKeyUp TKeyEvent,
. TKeyEvent
type TKeyEvent = procedure (Sender: TObject; var Key: Word; Shift:
TShiftState) of object;
<Shift>, <Ctrl>, <Alt> .
shift,
. OnKeyPress, Key
word, char, Key
chr .
I. Delphi
83
, , - , , <Alt>+<S>.
. - .
procedure TForml.Edit2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Shift = [ssCtrl]) and (chr(Key) = '1') then
MessageDlg(' <Ctrl> + <1> ', mtConfirmation, [mbOK], 0) ;
end;
84
Delphi.
, onHint TNotifyEvent,
, .
3.5.
, ,
, , , , .
.
SetFocus .
, .
.
canFocus: Boolean, True,
, False .
,
, Enabled False.
. Editi .
If Editl.CanFocus then Editl.SetFocus;
.
clear ,
.
. ListBoxi Memoi.
ListBoxl.Clear;
Memol.Clear;
Refresh ,
.
. Refresh ,
, , ListBox.
() ,
. ,
, ,
. . Delphi
Tstrings. (, )
Label.
.
. Delphi , , Edit, MaskEdit, Memo RichEdit.
4.1. TStrings
TStrings
. (
). TStrings
. TStrings , , TStringList.
, ,
, , . , ListBox DBListBox
RadioGroup DBRadioGroup items,
Memo Lines.
ListBox Memo
, DBListBox
DBMemo, , .
86
Delphi.
TStrings
items . TStrings
.
, items.
. items [0], items [1], items [2] .
. ,
,
.
count integer .
,
count-i.
. ListBoxi .
var n: integer;
for n := 0 to ListBoxi. Items. Count - 1 do
ListBoxi.Items[n] := ' ' + IntToStr(n);
,
, . Addstrings Assign. ,
. , ,
E q u a l s .
I. Delphi
87_
, ., ListBoxl ListBox2,
.
Delete clear. Delete (index: integer) , index.
, Delete .
. .
procedure TForml.Button2Click(Sender:
TObject);
begin
ComboBoxl.Items.Delete(4) ;
end;
Button2 ComboBoxl
.
clear , .
. .
procedure TForml.btnClearPersonalListClearClick(Sender: TObject);
88
Delphi.
begin
lbPersonal.Items, deadend;
btnciearPersonaiList
lbPersonal.
indexOf.
indexOf (const S: s t r i n g ) : integer ,
s . ; , - 1 .
TStrings saveToFiie LoadFromFile,
. . ANSI.
SaveToFiie (const FileName: string)
FileName.
, .
, L o a d F r o m F i l e .
. .
ListBox3.SaveToFiie(':\COMPANY\names.txt');
ListBox3 names.txt
C:\COMPANY.
LoadFromFile
(const FileName:
s t r i n g ) -
,
. ,
.
. .
procedure TForml.FormCreate(Sender: TObject);
begin
ComboBox2.Items.LoadFromFile('C:\TEXT\personal.txt');
end;
personal.txt .
ComboBox2.
String List editor ( ) . 4.1.
TStrings.
,
.
I. Delphi
89
fodeEdtc
ir|
Uicel
jelp
4.2.
,
caption. , , Label, .
, .
Label
Autosize Boolean. True ( ), Label , Caption.
Label
Alignment TAiignment, :
taLeftJustify ;
tacenter ;
taRightJustify .
A u t o s i z e True, A l i g n m e n t
.
, ,
Wordwrap B o o l e a n .
90^
Delphi.
True ,
Label
. wordwrap
False, .
Wordwrap , A u t o S i z e
True.
,
Transparent Boolean.
color. Transparent False
. Label ,
, , .
, Label . , ,
staticText.
Label staticText . staticText . Label , staticText
,
BorderStyle TStaticBorderStyle.
4.3.
, () ,
. Delphi , Edit.
I. Delphi
91
Edit , ,
, <Backspace> <Delete>,
. ,
<Enter> <Esc>.
, , , , OnKeyPress.
. , .
procedure TForml.EditlKeyPress(Sender :TObject; var Key :Char);
begin
if (Key < '0') or (Key > '9') then Key := #0;
end;
Editl .
, , <Enter>
.
, <Enter>.
<Enter>
,
, ,
SetFocus ActiveControl.
.
<Enter>.
procedure TForml.EditlKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then begin
Key := #0;
Forml.ActiveControl := Edit2;
end;
end;
procedure TForml,Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then begin
Key := #0;
Edit3.SetFocus;
end;
end;
4 3. 641
92_
Delphi.
( ) () , <Enter>.
:
procedure TForml.AllEditsKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then begin
Forml.SelectNext(Sender as TWinControl, true, true);
Key := #0;
end;
end;
,
OnKeyPress.
type
TForml = class(TForm)
Editl: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure AllEditsKeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
end;
procedure TForml.FormCreate(Sender: TObject);
begin
Editl.OnKeyPress:= AllEditsKeyPress;
Edit2.OnKeyPress:= AllEditsKeyPress;
Edit3.OnKeyPress:= AllEditsKeyPress;
end;
I. Delphi
93
,
( , , Edit Memo),
.
<Enter> seiectNext,
. seiectNext
(CurControl: TWinControl; GoForward, CheckTabStop: Boolean)
, CurControl
.
GoForward . True, ,
. CheckTabStop , Tabstop , . True
, Tabstop True.
MaskEdit ,
Edit .
() , (, . .). ,
( , . .).
, , .
4.4.
Delphi Memo.
, .
, .
Text string, Memo
. ,
<Enter>, #13#10, ,
Text. , , - Memo.
Lines
Tstrings. TString
, . -
94
Delphi.
Memo Lines.
. .
Memol.Lines[3] := ' a s d ' ;
Memo2.Lines.Clear;
.Lines.Add(' ');
Memol asd.
, TString . >2 .
.
Memo .
LoadFromFile
(const FileName:
String) LoadFromFile
(const
FileName: String) TStrings. FileName
.
. Memol.
Memol.Lines.LoadFromFile(':\TEXT\examplel.txt');
. 2 .
Memo2.Lines.SaveToFile(':\TEXT\exampie2.txt');
ScrollBars TScrollStyle,
:
ssNone ( );
ssHorizontai ;
s s v e r t i c a l ;
ssBoth .
Memo . Alignment TAlignment,
:
taLeftJustify ( );
tacenter ;
taRightJustify .
, Memo <Enter>.
, wantReturns Boolean -
I. Delphi
True ( ).
<Enter>.
wantTabs Boolean, <>.
True, <> . wantTabs False, <>
.
, WantReturns WantTabs
False, Memo <Enter> <>.
<Enter> <>
<Ctrl>.
RichEdit Memo
, ,
, . ,
, RTF (Rich Text
Format),
Windows.
4.5.
, ,
, .
onchange
TNotifyEvent, ,
, , . ,
Modiefid Boolean True.
, , , :
if Memol.Modiefid then begin
//
//
end;
, , MaxLength
96
Delphi.
integer.
, , MaxLength. (MaxLength = ).
AutoSelect, S e l S t a r t , SelLength SeiText
() .
, , , , , , , .
AutoSelect Boolean , ,
( True) .
SeiText string .
.
s e i s t a r t SelLength integer ( )
.
(
^)
S e l S t a r t SelLength ,
S e i s t a r t , ,
SelLength.
, , ,
, HideSelection
Boolean False. , .
HideSelection True ( ),
.
. .
Memol.SelStart := 19;
Memol.SelLength := 6;
Memol.SeiText := 'abcdefgh';
if pos('qwerty', Editl.Text) <> 0 then begin
Editl.HideSelection := false;
Editl.SelStart := pos('qwerty', Editl.Text)-1;
Editl.SelLength := length('qwerty');
end;
I. Delphi
Memol 6 , 19-,
abcdefgh. Editi qwerty. .
,
, SelectAll, CopyToClipBoard CutToClipBoard.
SelectAll .
CopyToClipBoard CutToClipBoard . ,
Memol.CutToClipBoard;
.
PasteFromciipBoard,
. , . ,
, , .
, , OnExit, , .
. , .
procedure TForml.EditlExit(Sender: TObject);
begin
if (Editl.Text = 423') or (Editl.Text = '456') then begin
MessageDlg{' '+ Editl.Text + ' !' +
#13#10' .', mtError, [mbOK], 0) ;
Editl.SetFocus;
Editl.SelectAll;
end;
end;
Editl ,
123 456 (
, ,
, ). OnExit .
, ,
Editl, .
,
98
Delphi.
, , .
Readonly Enabled.
,
.
Readonly, , :
Memol.Readonly := true;
Memol.Alignment := taCenter;
Memol.Clear;
Memol.Lines.Add(' ');
Memol.Lines.Add( ' ');
Memo .
,
.
Enabled.
,
, . , ( ).
Readonly.
4.6.
, .
. ,
, ,
().
4.6.1.
, . Delphi
L i s t B o x .
, , . , ,
, columns integer.
I. Delphi
99
0. ,
,
(. 4.2, )
(. 4.2, ).
I ListBox
. .
J
"
. 4 . 2 .
Columns , 1,
,
(),
.
,
columns. . 4.3 ,
9 . columns 2, 2 ,
Columns 3, 3 .
1 5| ListBox
Column*- :
. 4 . 3 .
, , .
columns , .
LB setHorizontaiExtent. -
100
Delphi.
.
, ListBox,
.
. ,
,
, .
. ListBoxi .
procedure TForml.FormCreate(Sender: TObject);
begin
ListBoxi.Columns := 0;
SendMessage(ListBoxi.Handle, LB_SetHorizontalExtent, 1000, 0);
end;
,
.
Topindex integer.
style TListBoxstyle, :
lbstandard ( );
lbOwnerDrawFixed , ItemHeight;
lbOwnerDrawVariabie - , .
lbstandard,
.
Delphi.
.
Borderstyle TBorderStyle,
:
bsNone ;
bssingie ( ).
4.6.2.
.
. Delphi
ComboBox.
I. Delphi
101
, ,
.
. . 4.4 .
ComboBox
1 EH I
'
. 4 . 4 . ComboBox
,
.
style TComboBoxStyle
. style
:
csDropDown (
). ,
, () ;
cssimpie . , ( Height)
ComboBox;
csDropDownList , ;
csOwnerDrawFixed , itemHeight;
csOwnerDrawVariable , .
csOwnerDrawFixed csOwnerDrawVariable,
.
DropDownCount integer ,
. , Count
102
Delphi.
items,
. ,
DropDownCount,
. DropDownCount 8.
TNotifyEvent: onDropDown ; oncioseUp
; OnSeiect ; OnChange
.
4.6.3.
, .
items,
() .
. Sorted Boolean.
False ( ) . Sorted
True, .
, , Windows 1251 ANSI. Windows .
,
, , ,
, , , : , , , . , ,
, .
Sorted , .
, i n s e r t
Add
, . , sorted
False, True:
ListBoxl.Sorted := false;
ListBoxl.Sorted := true;
.
I. Delphi
itemindex integer. ,
, , , 7- 6.
. , ListBoxi.
Label5.Caption := ' ' + IntToStr(ListBoxi.Itemindex) + ' ';
,
itemindex. ,
ListBox2.Itemindex := 3;
4- ListBox2, .
.
MultiSelect Boolean, , True. False.
M u l t i S e l e c t True, I t e m i n d e x
, .
. , I t e m i n d e x , .
,
, ExtendedSelect Boolean
. ExtendedSelect
False,
. ,
. ExtendedSelect
True ( ), , <Shift> <Ctrl>.
, M u l t i S e l e c t ExtendedSelect.
seicount
integer. Selected [Index: Integer] Boolean,
. index ,
Selected True, ,
, selected False. seicount
selected , .
. .
104
Delphi,
var i :integer;
for i := 0 to ListBox2.Items.Count 1 do
ListBoxi .
Onclick,
.
. .
procedure TForml.ListBoxlClick(Sender: TObject) ;
begin
Label3.Caption := ListBoxi.Items[ListBox4.Itemlndex];
end;
Labei3 , ListBoxi.
5.1.
,
. / .
Delphi , :
Button;
BitBtn ;
speedButton .
, ,
.
.
5.1.1.
, Delphi
Button, .
Button , , .
onclick, . , . , Onclick, .
Delphi.
106
:
;
, Caption;
<Enter> <>;
<Esc>.
<Enter> <> , , ,
(. 5.1).
. 5 . 1 . Cancel
, ,
Edit Memo, ,
Default Boolean True.
, ,
. ( , , Panel) False, .
Default True ,
,
.
Onclick <Esc>, , , , Cancel .
<Esc>, cancel
Boolean True. Cancel
True
. Cancel
False, <Esc>.
, , Memo,
, <Enter>
<Esc>, -.
I. Delphi
107
ModaiResuit TModaiResuit. ,
ModaiResuit ,
. ModaiResuit ,
:
mrNone 0J
mrOk idOK (1);
mrCancel idCancel (2);
mrAbort idAbort (3);
mrRetry idRetry (4);
mrlgnore idlgnore (5);
mrYes idYes (6);
mrNo idNo (7) ;
mrAll mrNo + l;
mrNoToAll mrAll + l;
mrYesToAll mrNoToAll + 1.
.
ModaiResuit ,
mrNone ( ),
,
close Onclick .
. Form2.
procedure TForm2 .FormCreate(Sender: TObject);
begin
Button2.ModaiResuit := mrOK;
Button3.ModaiResuit := 123;
end;
procedure TForm2.ButtonlClick(Sender: TObject);
begin
Form2.Close;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
//
end;
108
Delphi.
5.1.2.
Delphi BitBtn, TBitBtn TButton
Button. ,
(). BitBtn .
Glyph TBitmap .
Glyph n i l ,
. . ,
:
1- , ( );
2- ,
;
3- , ( ).
BMP.
, , Image
Editor, Delphi. . 5.2
.
, , 16 16 .
. ( ciBtnFace), ,
, .
. ,
, , .
I. Delphi
109
"LI
M " F 171
:: .-.-0 Yi-004
. 5.2.
Delphi ,
Program
Files\Common Files\Borland Shared\Images\Button.
Delphi BitBtn
(. 5.3),
Kind
TBitBtnKind.
- . :
bkCustom , ;
; Default
True, ModalResuit
;
bkcancel Cancel;
Cancel True, ModalResuit
mrcancel;
bkYes Yes; Default
True, ModalResuit
mrYes;
Delphi.
110
bkAbort Abort;
bkRetry
Retry;
bkignore
Ignore;
bkAii
Yes to All.
1
1
O K
Abort
Cancel
*,
* irjnDie 11
y^
QjJu
? Help
J.
^ All
. 5 . . B i t B t n
biGiyphLeft ( );
biGiyphRight ;
biGiyphTop ;
biGiyphBottom .
VblGlyphLelt:
blGljiphBotom
_:
bG
i yiphRg
i ht </
V
bG
i yiphTop
.
^._
. 5 . 4 .
5.2.
() - . () () . .
I. Delphi
Delphi checkBox,
RadioButton RadioGroup. CheckBox RadioButton,
Button, TButtonControi.
: checkBox , RadioButton .
5.2.1.
CheckBox.
.
checked
Boolean. False, .
. , , .
checked. <>, checkBox
, .
. .
If CheckBoxl.Checked then
MessageDlg(' !', mtError, [rabOK], 0);
!
CheckBoxl, .
, checked .
. ().
CheckBox2.Checked := true;
CheckBox3.Checked := false;
checkBox2 ,
checkBox3 .
()
Enabled False:
CheckBoxl.Enabled := false;
, .
.
( )
, .
112
Delphi.
AiiowGrayed
Boolean. True,
: , . , .
,
.
Checked True .
(. 5.5)
s t a t e TCheckBoxstate.
:
cbchecked ;
cbUnchecked ;
cbGrayed .
t
[ }
. 5.5. CheckBox
Onclick, , . onclick , .
. .
procedure TForml.CheckBox3Click(Sender: TObject);
begin
case .State of
cbUnchecked: .Caption : = ' ';
cbchecked: CheckBox3.Caption := ' ';
cbGrayed: .Caption := ' ';
end;
end;
I. Delphi
113
5.2.2.
RadioButton, . .
,
. , . Delphi . , ,
(. 5.6).
, Form, Panel GroupBox.
13 \
1 I f '
RadioButton2
: - " '
~- RadioBuon5
( RadioButlonS '
RadioButlon?
Paneli
RadioButton4
RadioButlon?
;
RadioBultorfi
RadioButlon9
.'
RadioButtoniO
' -r*Radio3utton11
(?.RadioButton12
RadioButlonl3
'
. 5.6.
,
. , . 6.6
:
procedure TForml.FormCreate(Sender: TObject);
begin
//
RadioButton2.Checked := true;
RadioButton3.Checked := true;
RadioButton6.Checked := true;
RadioButtonl2.Checked := true;
end;
ipynne , ,
,
Delphi.
114
.
.
R a d i o B u t t o n O n c l i c k
. O n c l i c k .
, , Delphi
RadioGroup (. 5.7),
RadioButton.
.
I , RadioGioup
j
Rado
i Groupi
" Hem1
11-4
Item 2
(? Item 5
Iteti3
!lsm6
. 5 . 7 . R a d i o G r o u p
RadioGroup
, , checkBox Edit.
items TStrings, . , .
: items [0], items [1] . . () , Add Delete.
itemindex integer, () , .
, . itemindex - 1 , .
columns integer , ( 1).
, items
I. Delphi
115
, , , Edit . Label,
RadioGroup.
. .
procedure TForml.FormCreate(Sender: TObject);
begin
RadioGroupl.Items.Clear;
RadioGroupl.Items.Add('Item 1');
RadioGroupl.Items.Add('Item 2');
RadioGroupl.Items.Add('Item 3');
RadioGroupl.Items.Add('Item 4');
RadioGroupl.Items.Add('Item 5');
RadioGroupl.Items.Add('Item 6');
RadioGroupl.Columns := 2;
RadioGroupl.Itemlndex := 4;
end;
RadioGroupl 6 ,
. item 5 .
5.3.
, . , , .
. ,
,
.
.
Parent.
RadioGroup, . Delphi
, , :
GroupBox;
Panel;
scroiiBox;
() Frame.
116
Delphi.
, , . .
5.3.1.
. Delphi GroupBox,
( Caption)
. , . 5.6
GroupBoxl
RadioButton.
5.3.2.
,
.
, . Delphi Panel.
: .
, .
Beweiwidth
TBeweiwidth. TBeveiwidth
(TBeveiwidth = 1 .. Maxint). 1.
Beveiinner BeveiOuter TPaneiBevel .
:
bvNone ;
bvLowered ;
bvRaised ;
bvspace .
Beveiinner bvNone,
BeveiOuter bvRaised.
, Borderwidth TBorderWidth.
.
Alignment TAiignment,
:
taLeftJustify ;
I. Delphi
117
tacenter ( );
taRightJustify .
, Caption
.
5.3.3.
. .
Delphi ScrollBox.
ScrollBox ,
, .
- , ScrollBox, , : (. 5.8, ), .
(. 5.8, ), .
:: ScrollBox
" QieckBoxl
CheikBox2
Buttoni
I I ScrollBox
CheckBoxi
ChBckBon2
Butoni
J_LJ
. 5 . 8 . S c r o l l B o x
ScrollBox , , , . ,
. () ScrollBox >!'*#
. 5 . 9 .
118
Delphi.
,
(. 5.9,
).
,
scroliBox Align a i c i i e n t .
, , . , ,
ScroliBox, .
(. 5.9, ).
Autoscroii Boolean ,
. True, .
Autoscroii False,
,
HorzScrollBar VertScrollBar TControlScrollBar.
ScrollInView. ScrollInView (AControl: TControl) , ,
AControl, .
. Windows . "" ""
.
Form TForm,
. , , () . ,
Delphi, .
,
Delphi Formi.
, , .
, .
() ,
.
Delphi
( Forml). (DPR)
, :
Application.Initialize;
Application.CreateForm(TForml, Forml);
Application.CreateForm(TForm2, Form2);
Application.Run;
, CreateForm . , Form2 :
120
Delphi.
Application.Initialize;
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForml, Forml);
Application.Run;
, Project | Options ( |
). Main
Form Form, Delphi
.
.
.
.
6.1.
, ,
, ,
. , , Caption Color, onKeyPress. , , , .
, , Bordericons,
, , AutoScroii
ActiveControl.
Delphi
(Forml, Form2 . .), ,
Application.CreateForm(TForml, Forml);
, ,
, ( Auto-create forms Form).
( Available forms), , .
Create. Create
,
, (DFM) (PAS).
. .
I. Delphi
121
Form2
.
TNotifyEvent, :
OnCreate;
OnActivate;
OnShow;
OnPaint.
OnResize;
OnCreate , ,
.
OnCreate ,
, ,
. ,
, , , .
. OnCreate Form2.
procedure TForm2.FormCreate(Sender :TObject);
begin
Form2.Caption := ' ';
ComboBox2.Items.LoadFromFile('list.txt');
Button3.Enabled := false;
end;
, comboBox2 list.txt,
Button3 .
Delphi , visible
True.
False,
. , visible.
122
Delphi.
(
, , ,
.
show Hide. Show , v i s i b l e True,
. Hide
, visible False.
, show
.
. .
procedure TForml.btnShowFormsClick(Sender :TObject);
begin
Form2.Visible := t r u e ;
Form3.Show;
end;
procedure TForml.btnHideFormsClick(Sender :TObject);
begin
Form2.Visible := f a l s e ;
Form3.Hide;
end;
btnShowForms btnHideForms,
Forml, (
) Form2 Form3.
, v i s i b l e True, onShow. , v i s i b l e False, OnHide.
, ,
,
onActivate.
OnDeActivate.
onPaint , , ,
.
close,
. close , -
I. Delphi
/23
, , ,
Show ShowModal.
.
. .
procedure TForm2.btnCloseClick(Sender: TObject);
begin
Form2.Close;
end;
btnciose Form2.
( caption), , .
Free,
,
().
,
.
. .
procedure TForm3.btnDestroyClick(Sender: TObject);
begin
Form3. Freerend;
btnDestroy Form3. , , .
, :
OnCloseQuery;
OnClose;
OnDeActivate;
OnHideJ
OnDestroy.
124
Delphi.
. , , , . oncioseQuery ,
.
. .
procedure TForm2.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := MessageDlg(' ?', mtConfirmation,
[mbYes, mbNo], 0) = mrYes;
end;
Form2 , "
?" Yes No. Yes , .
Onciose TCioseEvent . .
Action TCioseAction, :
caNone ;
caHide ;
caFree , ;
caMinimize .
, onClose.
. .
procedure TForm2.FormClose(Sender: TObject; var Action: TCioseAction);
begin
if Memol.Modified then Action := caNone else Action := caHide;
end;
I. Delphi
125
,
. , .
.
, .
. .
procedure TForm2. btnResizeFormClick(Sender: TObject);
Delphi.
126
begin
Form2.Width := Form2.Width + 100;
end;
btnResizeForm Form2
100 , Borderstyle
, bsDialog, bsSingle bsNone.
(
,
.
, , showModal. ,
, .
4 .
Bordericons TBordericons,
:
bisystemMenu ;
biMinimize ();
biMaximize ();
biHelp , - .
Windows
, , .
,
, (. 6.1).
I ,:
BEHDt
AU+F4
. 6 . 1 .
Bordericons
. , , . , .
. , -
I. Delphi
127
. (, ), FormStyle B o r d e r l c o n s .
.
. , .
, . . ,
width Height ,
ClientWidth ClientHeight Integer
.
.
.
procedure TForml.FormCreate(Sender: TObject);
begin
Forml.Caption := ' ' +
IntToStr(Forml.ClientWidth) +' x '+ IntToStr{Forml.ClientHeight);
end;
Menu TMainMenu.
MainMenu
(Menu:=KainMenui) Menu ,
.
, icon Ticon.
,
. icon ( ). , , icon Application.
Windows .
. .
procedure TForml.FormCreate(Sender: TObj ect);
128
Delphi.
begin
Forml.Icon.LoadFromFile(':\Picturel.ico1);
end;
Forml
c:\Picturel.ico.
Position
TPosition. :
poDesigned ,
( ). Left,
, width Height.
, , ,
;
poScreenCenter , ( Height width) ;
poDefauit Windows
, . ;
poDefauitPosOnly Windows ,
;
poDefauitsizeOnly Windows
, .
Active Boolean .
,
, . Active
True, ( ),
False .
. ,
windowstate show (showModai).
windowstate Twindowstate :
wsNormai ( );
wsMinimized ;
wsMaximized .
. .
procedure TForml.btnMiniFormClick(Sender: TObject) ;
I. Delphi
129
begin
Form2.WindowState := wsMinimized;
end;
procedure TForml.btnNormalFormClick(Sender: TObject);
begin
Form2.WindowState := wsNormal;
end;
btnMiniForm btnNormalForm Forml Form2.
, , CreateForm Create. , ,
, .
, , ( WindowState) ,
, .
, , .
( TWinControi) (). Activecontroi TWinControi , .
, ( ), , :
Forml.ActiveControl := Edit2;
setFocus,
, :
Edit2.SetFocus;
, , . AutoScroil Boolean ,
. AutoScroil True (
), ,
. , ,
. ,
AutoScroil False,
, HorzScrollBar
VertScrollBar TControlScrollBar .
ScrollInView. ScrollInView (AControl: TControl) -
Delphi.
130
, AControi .
KeyPreview Boolean , ,
. False ( ), ( ). KeyPreview True
, ,
.
<>
.
. .
// KeyPreview True
procedure TForml.FormKeyPress(Sender: TObject; var Key: Char);
begin
MessageDlg(' ' + Key, mtlnformation, [rnbOK], 0);
end;
Formi - , .
. .
, Windows, (. 6.2), Labeil,
Timerl MainMenul.
! 1
Labell
. 6.2.
, ,
onTimer .
Label 1.
I. Delphi
131
: (mnuCaption),
(mnuinitiaisize) (mnuciose).
Name .
. ,
(. 6.3, ).
, , , (. 6.3, ). .
Labeil.
22:00:10
21:59:34
. 6.3. -
uciock Formi.
OnCreate. .
unit uClock;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, ExtCtrls, StdCtrls, Menus;
type
TForml = class(TForm)
Labeil: TLabel;
Timerl: TTimer;
MainMenul: TMainMenu;
mnuMenu: TMenuItem;
mnuCaption: TMenuItem;
mnuinitiaisize: TMenuItem;
mnuClose: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure TimerITimer(Sender: TObject);
132
Delphi.
I. Delphi
else Labe11.Font.Height := Round((Forml.ClientWidth - 10) *
Label1.Height / Labell.Width);
Label1.Left :=' (Forml.ClientWidth - Labell.Width) div 2;
Labell.Top := (Forml.ClientHeight - Labell.Height) div 2;
end;
//
procedure TForml.TimerlTimer(Sender: TObject);
begin
Labell.Caption := TimeToStr(Time);
end;
//
procedure TForml.mnuCaptionClick(Sender: TObject);
begin
if mnCaption.Checked then begin
Forml.BorderStyle := bsNone;
Forml.Menu := nil;
end
else begin
Forml.BorderStyle := bsSizeable;
Forml.Menu := MainMenul;
end;
mnuCaption.Checked := not mnuCaption.Checked;
end;
//
procedure TForml.mnuInitialSizeClick(Sender: TObject);
begin
Forml.ClientWidth := 100; Forml.ClientHeight := 45;
FormResize(Sender);
end;
//
procedure TForml.mnuCloseClick(Sender: TObject);
begin
Close;
end;
// ""
133
134
Delphi.
II ,
procedure TForml.FormDblClick(Sender: TObject);
begin
mnuCaption.Click;
end;
end.
,
, . Labeii. , Height
. ,
,
Constraints
. ,
, .
,
.
Clock.ico.
.
, Formstyie fsStayOnTop.
6.2.
- ,
uses implementation ( interface)
.
. .
Forml Form2, u n i t l Unit2 .
U n i t l Forml.
unit Unitl;
interface
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TForml = class(TForm)
I. Delphi
135
Buttonl: TButton;
procedure ButtonlClick(Sender: TObject);
end;
var Forml: TForml;
implementation
//
uses Unit2;
{$R *.DFM}
procedure TForml.ButtonlClick(Sender: TObject);
begin
//
Form2.Show;
end;
end.
Buttonl
, . , implementation
uses unit2.
, Delphi
. File | Use Unit ( | )
Use Unit ( ) (. 6.4).
.
. 6.4.
Delphi.
136
, Information () (. 6.5).
, ,
uses . Yes.
I Information
e
ale
rF
d
n
ia2
' nt2
i'wh
ch
i si notn
i you!
o
m
rE
'ie
ro
e
fe
rny
co
eu
so
fm
rd
'unt?
U
S
SF's
ilotrm
.D
w
sh
ic
o
l'orm
dd
liiU
F
ancel|
L::3::JI * j C
. 6.5.
,
.
.
. .
uses Unit2;
procedure TForml.Button2Click(Sender: TObject);
begin
Labell.Caption := Form2.Editl.Text;
end;
Button2 Formi Labell
Editi, Form2.
,
.
.
6.3.
, . , ,
Windows .
I. Delphi
137
, Windows.
, ,
.
, ,
.
Windows ,
. , , Delphi
.
.
About ( ).
,
, ,
, .
showModai.
. .
procedure TForml.mnuAboutClick(Sender: TObject);
begin
fmAbout.ShowModai;
end;
mnuAbout fmAbout . (, ),
caption. , .
, ,
:
fmAbout.Show;
ShowModai
ModaiResuit TModaiResuit,
.
. , show .
. . .
138
Delphi.
.
. .
// Forml
procedure TForml.btnDialogClick(Sender: TObject);
var rez :TModalResult;
begin
// ()
rez := fmDialog.ShowModal;
// ()
if rez = mrOK then
MessageDlg(' .1, mtlnformation, [mbYes], 0);
if rez = mrCancel then
MessageDlg(' .', mtlnformation, [mbYes], 0);
end;
// fmDialog
// mrOK
procedure TfmDialog.btnCloseClick(Sender: TObject);
begin
ModaiResuit := mrOK;
end;
// mrCancel
procedure TfmDialog. btnCancelClick(Sender: TObject);
begin
ModaiResuit := mrCancel;
end;
I. Delphi
739
, ,
ModaiResuit . , mrNone,
.
,
ModaiResuit , .
. .
procedure TfmDialog.FormCreate(Sender: TObject);
begin
fmDialog.BorderStyle := bsDialog;
btnOK.Caption := 'OK';
btnOK.Default := true;
btnOK.ModaiResuit := mrOK;
btnCancel.Caption := 'Ioiaia';
btnCancel.Cancel := true;
btnCancel.ModaiResuit := mrCancel;
end;
btnOK
btnCancel fmDiaiog.
( ) .
, .
onCreate .
c l o s e
mrCancel ModaiResuit. Hide ModaiResuit.
, ,
Delphi . ,
. ,
Dialogs () .
140
Delphi.
6.4. ,
ShowMessage, MessageDlg MessageDlgPos
() ; inputBox inputQuery () . ShowMessage
MessageDlg.
ShowMessage (const Msg: String)
. , Msg .
. .
(. 6.6) dlgwin.exe.
procedure TForml.btnDialoglClick(Sender: TObject);
begin
ShowMessage(' ');
end;
. 6.6.
MessageDlg
(const Msg:
String;
AType:
TMsgDlgType;
AButtons: TMsgDlgButtons; HelpCtx: L o n g i n t ) : Word
. Msg .
. ,
:
mtwarning
Warning;
mtError Error;
mtinformation "i" Information;
mtconf irmation "?" Confirmation;
I. Delphi
141
mtcustom ,
.
AButtons
:
mbYes Yes;
mbNo No;
;
mbcancei Cancel;
mbHelp Help;
mbAbort Abort;
mbRetry Retry;
mbignore Ignore;
mbAii All.
AButtons mbYesNoCancel
mbOKCancel, :
, Help, MessageDig (
ModaiResuit),
.
Heipctx () ,
<F1>.
.
. MessageDig.
procedure TForml.btnTestDateClick(Sender: TObject);
var rez : TModalResu.lt;
begin
if length(edtDate.Text) < 8 then begin
rez := MessageDig(' !' +
#10#13' ?',
mtError, [mbOK, mbNo], 0);
if rez = mrOK then edtDate.Text := DateToStr(Date);
if rez = mrNo then if edtDate.CanFocus then edtDate.SetFocus;
end;
end;
142
Delphi.
btnTestDate
. edtDate,
. ,
. ,
.
6.5.
Delphi , Dialogs (. 6.7) .
Windows- , , ,
. , Microsoft
Word .
Windows, ,
, Windows.
Internet] FaslMet) Decision Cube ].QReDort Dialogs [Win 3.1
. 6.7. Dialogs
Dialogs , :
OpenDialog ;
saveDialog ;
OpenPictureDialog ;
SavePictureDialog ;
Fontoiaiog ;
coiorDiaiog ;
PrintDialog ;
PrinterSetupDialog ;
FindDialog ;
RepiaceDiaiog .
-
I. Delphi
143
. - .
.
Execute
, . ( ) Execute
True, False.
, . ,
(openDialogl.FileName),
( l o r Dialogl. Color).
, .
/ .
, .
openDialog , (. 6.8) . (
Open) .
Jj 14._
15._
-1) 16._
li 17._
li 1._
li 19._
_1| 20_
li 21._
1}22_
_D 23_
1} 24_
1125._
-J 26_
1
Filename;
LJ 28_ npw
29_
Zi 30_
UU 31_,
CJaaa
'_Uaaa3
] 5
LJ After Khomonenko
Dcdr
Qwork
fJNotes,doc
11
_
Open
-{ Delphi 6.doc
zl-
Cancel
1
_J
144
Delphi.
saveDialog ,
.
OpenDialog SaveDialog
:
FileName s t r i n g , . ;
T i t l e string . T i t l e , Open
OpenDialog Save SaveDialog;
i n i t i a i o i r s t r i n g ,
. , ;
DefauitExt string , , ;
F i l t e r s t r i n g , Files of type.
, ( . 6.8
DOC). F i l t e r
,
;
Fiiterindex integer , . Fiiterindex 1,
;
options TOpenOptions ,
. () .
options , :
ofCreatePrompt
;
ofNoLongNames (
8 3 );
, I. ,
I. , .
I. Delphi
145
.
, ;.
. .
OpenDialogl.Filter :==' !*.txt;*.docI |*.*';
. DOC .
, , , :
OpenDialogl.Filte r:= ' *.txt;*.doc|*.txt;*.doc'
+ '| *.*!*.*';
.
F i l t e r (Filter Editor).
(. 6.9),
Filter Name ( ) Filter ().
, , .
Filer Editor
Filler Name
(".")
JFilter
'. doc
Help
. 6.9.
Execute. , , . Open
146
Delphi.
6.6.
. ,
. :
New:
Form;
Forms:
About Box;
Dual List Box ;
Quick Report List ;
Quick Report Master/Detail ;
Dialogs:
Dialog with Help Help ( , );
Password Dialog ;
Standard Dialog ( ,
).
I. Delphi
147
C&ncel
ModalResult:
OKBtn mrOK;
CancelBtn mrCancel.
, , ,
.
Password Dialog showModai :
PasswordDig.ShowModai;
. , ,
.
,
(wizards) -,
. ,
, , .
, .
Windows ,
, Microsoft Office .
Windows , . ,
().
.
( ) . ,
.
TMenuitem.
,
. ()
. TMenuitem
. :
Bitmap TBitmap , .
n i l , ;
Break , .
Break :
mbNone ( );
mbBreak , , ;
mbBreakBar , ,
, ;
caption string , . "-",
I. Delphi
149
. , , caption
- "-";
checked Boolean , .
True, . checked
False, ;
AutoCheck Boolean checked
( Delphi 6);
count integer
. . -
, Count ;
Enabled Boolean , , . .
. Enabled
False,
. Enabled True,
;
items TMenuitems
. , (
), items. : items [0], items [l]
. .;
Radioitem Boolean ,
. False ( ), ,
;
shortcut TSortCut . caption, shortcut
. , shortcut, . ,
. ,
Shortcut
(Key:
Word;
Shift:
150
Delphi.
v i s i b l e Boolean , .
v i s i b l e False,
. visible True,
.
, , onclick,
.
Onclick
click. .
. .
procedure TForml.ButtonlClick(Sender: TObject);
begin
mnuLockltem.Click;
end;
Buttoni ,
mnuLockltem.
. .
7.1.
(. 7.1) . Delphi MainMenu.
. 7 . 1 .
,
.
, (. 7.2).
. ,
, .
MainMenu
.
I. Delphi
151
, .
onclick
.
\
l.iaixi
. 7 . 2 .
7.2.
()
. , , ,
. . 7.3 .
-
- - '
1
. 7 . 3 .
Delphi PopupMenu.
:
AutoPopup Boolean ,
, . AutoPopup
True ( ), . AutoPopup False,
. , Popup. Popup
(, Y: integer), Y
,
, ,
PopupMenul.Popup(200, 200);
Alignment TPopupAiignment . Alignment
:
paLeft ( );
Delphi.
152
pacenter ;
paRight .
,
PopupMenu .
. .
Forml.PopupMenu := PopupMenu1;
Forml PopupMenui.
7.3.
Delphi (Menu Designer). Menu Designer ( ) MainMerm PopupMenu, .
. , MainMenu PopupMenu Standard ( ) .
.
, .
. 7.4.
!- Forml MainMenul
-'
'.- .
33 Insert
Ins
>ee
l (e
Del
'"""~:"" Create Submenu
Dfl+Right
. SejectMenu..
Save As Template..
Insert From Template..
Delete Templates..
Insert FromBesource..
. 7.4.
(. 7.4), -
I. Delphi
153
.
, (Insert) (Delete) , (Create Submenu), (Select Menu).
drag-and-drop.
. ,
caption.
7.4.
. ,
. , :
;
;
;
;
;
;
.
.
Add i n s e r t , Delete.
Add (item: TMenuitem)
item , .
, .
. .
procedure Forml.mnuItemAddClick(Sender :TSender);
var Newltem :TMenuitem;
begin
Newltem := TMenuitem.Create(Self);
Newltem.Caption := ' 1;
mnuFile.Add(Newltem) ;
end;
. .
C r e a t e .
154
Delphi.
II
8.
9.
10.
11.
8.1.
, , .
8.1.1.
,
:
;
();
();
( ).
,
. , .
,
, .
.
,
. Paradox, dBase, FoxPro, Access .
, "-". -
158
Delphi.
-.
. .
, ,
.
,
.
, , .
Delphi , . Delphi - ,
.
Delphi , , , ,
, ( )
, , dBase, Paradox
InterBase. ,
. , , ,
Delphi ,
.
II.
159
8.1.2.
:
;
.
,
- .
, . Delphi BDE (Borland Database
Engine Borland). BDE
, . BDE , . BDE
, Delphi-, . , Delphi
BDE.
,
. (. 8.1). , , . ,
. . , , , , .
.
BDE
. 8 . 1 .
BDE , dBase,
Paradox, FoxPro, .
- , ,
, .
160
Delphi.
-, .
, - ,
.
"-" ,
. .
:
;
;
.
, , - .
dBase Paradox. ,
.
8.2.
. ,
.
8.2.1.
, , () .
(, Microsoft Excel),
, ,
Windows. , , , . .
.
, , , . . ,
, . ,
:
dBase DBF, Paradox
DB.
,
, , .
II.
161
.
, (. 8.2).
.
. 8 . 2 .
, , ,
. . , , , .
, . , dBase ( )
.
() , , . ,
,
, ,
.
,
. :
;
;
;
;
162
Delphi.
;
.
, , .
, ,
, dBase . (
) , ,
(, Database
Desktop). (,
) ,
.
:
( );
();
;
.
, .
.
, , .
.
,
. (), ,
, Database Desktop Data Pump.
, ,
, Windows.
. , ( Windows).
II.
163
8.2.2.
,
.
, () . ,
, .
. :
;
;
;
D ;
.
() .
. , Paradox
( ) . Access
MDB. . , ( ).
, .
,
,
, , . ( ),
, . ,
,
.
.
.
, .
.
( ) .
, . .
, .
, , .
164
Delphi.
,
. , .
, , ,
, ( ).
, , .
, .
,
. Paradox , (4 ). dBase InterBase ,
, , .
,
,
. , , , , Code Number.
, , , , . , ,
. , () .
. , , . .
:
() ;
;
;
.
. ,
, .
, , ,
- .
II.
165
.
. Delphi Table
. Query
SQL ,
.
.
, . . . . , , Table. , Table
.
. Paradox () ,
. dBase ,
.
. ,
Paradox ,
, .
, :
;
;
;
;
;
.
( ).
8.2.3.
:
;
.
166
Delphi.
.
.
, .
,
, , . SQL-, SQL-.
,
.
, . , , Delphi,
Query, Query.
8.2.4.
, ,
.
. ()
.
,
, , .
. ,
, ,
. ,
, ( ),
.
( ). . , .
.
. , dBase
( ) . ,
, , .
167
II.
Paradox , .
,
. . 8.3 Paradox.
_Code
1 ( )
D_Number
D_Code
. 8.3. Paradox
, M_Code .
D_Number ,
D_code .
D_code M_code. DCode . , . ,
(Master), D (Detail). , .
, , , , .
SQL ()
. .
,
(, Master),
(, Detail). () "-", "" "-". :
168
Delphi.
"--";
"--";
"--";
"--".
"--", ,
, .
- ,
. .
, ,
, :
, ,
, , , ;
,
.
, . ,
.
, .
, .
, .
.
.
()
.
.
( ).
.
,
. -
II.
169
, , , ,
, . , , Database
Desktop,
.
, ,
,
(), . :
;
(
);
() ;
() .
, .
, , ,
. ,
.
8.2.5.
.
.
.
.
.
, ,
, . .
.
, (
) .
, .
,
. :
;
.
170
Delphi.
.
,
.
Database / SQL.
,
.
. , , , - , ,
, .
, , , .
.
. ,
.
8.2.6. -
- , , ,
. , -
.
- :
;
;
;
;
.
- , . (,
) .
, .
-
- .
,
II.
171
. - .
-
"" .
, , .
8.2.7.
Delphi , , , dBase Paradox. .
dBase
, ,
. dBase: .
dBase
.
, :
DBF ;
DBT , BLOB- (Binary
Large OBject). , Memo- OLE-. Memo ;
MDX ;
NDX , dBase.
.
dBase
. 10 . .
dBase , ,
.
Paradox
. :
;
;
;
Delphi.
172
.
, . ,
.
Paradox .
. 8.1 Paradox 7.
,
Database Desktop, , .
8.1. Paradox 7
Alpha
.
255
Number
. - 1 0 3 0 7
10 308 . 15
Money
. Number
,
.
Windows
Short
Longlnteger
. - 32 768 32 767
BCD
Date
31.12.9999
Time
Timestamp
Memo
01.01.9999
..
. . 240 ,
MB
Formatted
Memo
. Memo
,
Graphic
. BMP,
PCX, TIF, GIF EPS. BMP.
MB
173
h1
8.1 ()
OLE
,
OLE.
MB
Logical
.
True () False ().
Autoincrement
.
, ,
.
.
Binary
. . . 240 ,
MB
Bytes
.
255
(~
Database Desktop
Graphic, B i n a r y , Memo OLE .
Paradox ( ) .
25 . , , #, $
. ., ! |,
Delphi .
.
Paradox ,
10 .
Paradox
,
174
Delphi.
. -
, . Paradox
:
DB ;
MB BLOB-;
();
XG* YG* ;
VAL ;
TV FAM Database Desktop.
, ; .
8.3.
Delphi , , ,
Delphi, , :
;
.
, .
,
.
8.3.1.
Delphi
, .
Borland Database Engine (BDE) , , Delphi-. BDE .
BDE Administrator BDE.
Database Desktop , SQL QBE.
II.
175_
SQL Explorer , .
SQL Builder SQL-.
Data Pump .
8.3.2.
, Delphi
, , TFieid.
Delphi, ,
.
, .
.
.
, .
, .
, ,
Data Access, Data Controls, BDE QReport .
,
Delphi.
, Delphi 6.
BDE , ,
Table Query, Data Access.
. 8 . 4 . Data Access
176
Delphi.
A H ' L I
. 8.5. Data Controls
BDE (. 8.6) ,
BDE:
Table , ;
Query , SQL-;
storedProc ;
DataBase ;
Session ;
BatchMove ;
updateSQL , SQL-;
II.
177_
NestedTabie ;
BDECiientDataSet .
iress j DateSnao BDE . j ADO ] InterBa
. 8.6. BDE
QReport (. 8.7) ( ), :
QuickRep ;
QRSubDetaii , "-";
QRStringsBand ;
QRBand ;
QRChiidBand ;
QRGroup ;
QRLabel ;
QRDBText ;
QRExpr ;
QRSysData ;
QRMemo ;
QRExprMemo ;
QRRichText ;
QRDBRichText ;
QRShape ;
QRimage ;
QRDBimage ;
QRCompositeReport ;
QRPreview ;
QRTextFiiter ;
QRCSvFiiter CSV-;
QRHTMLFiiter HTNL-;
QRChart .
178
Delphi.
| Decision Cube QReport | Dialoas j Win 3.1 | Samples | ActiveX | COM+ | WebSnao | Servers | indvQ
. 8.7. QReport
, ,
, , DB QR. DB ,
.
. QR ,
. QuickRep
, , QRBand,
.
8.4.
Delphi
.
,
: Database Desktop, . :
;
.
.
, . , Delphi
,
.
Program Files\Shared Files\Borland Shared\Data. .
8.5.
Database Desktop, :
;
;
.
II.
179
, Database Desktop (,
SQL-, ).
File | New | Table
( | | ) .
:
() ;
.
Create Table ( )
(. 8.8) . Paradox 7, .
, , dBase IV,
.
I Create Table
Iable type: -
51
Cancel' |
Hep
l
. 8.8.
(. 8.9), :
;
;
;
;
() ;
;
;
.
, . .
.
. , ,
, ,
Paradox.
,
Save as ( )
. ,
, .
180
Delphi.
I Create Paradox 7 Table: ( llnlitled )
-field tostet:
jKeyj
Field
Name
Post
Salary
5|BirthOay
20 i
' 15;
Table eioperties:
[ j Secondary Indexes
J>J
indName
Help
. 8.9.
8.5.1.
Field roster ( ), . :
Field Name;
;
Size.
,
. Paradox .
, ,
, I ,
, <> ().
, .
, , ().
,
. , , (+) (i), . -
II.
181_
,
.
,
.
<Insert>.
, .
<Ctrl>+<Delete>.
.
(Key) *,
- . . , . .
. (. . 8.9).
, Paradox (Primary Index), dBase , .
Table properties ( ),
:
Secondary Indexes ;
Validity Checks ( );
Referential Integrity ;
Password Security ;
Table Language ( );
Table Lookup ;
Dependent Tables .
- , .
. , dBase
Indexes () Table Language ( ).
8.5.2.
:
;
.
;
182
Delphi.
, .
, ,
Secondary Indexes ( )
, Define ()
Modify (), Erase ().
, . 8.9 indName.
, Paradox .
Define (), . Define Secondary Index ( ), (. 8.10).
indexed fields:
alary
BrithDay
ill
I n d e x
P "
i n -'
Case sensitive
" Descending
M a i n l a i n e d
OK
Cancel
Help
. 8.10.
Fields () ,
, , ,
. Indexed Fields ( ) , .
() . ,
, . ,
.
II.
183
. .
, Change order ( ). ()
() .
, , :
Unique
;
Maintained
;
Case sensitive ;
Descending .
dBase ,
Unique ()
( ),
.
Save Index As ( ),
(. 8.11).
, - ,
ind. ,
Paradox
. , .
(Save Index As
Jndeji rams.
, jindNamel
|". OK | ' Cancel ]
HI
Help |
. 8 . 1 1 .
184
Delphi.
, , .
. Modify
() (. . 8.10).
(. 8.11), ,
.
Erase (). .
Modify () Erase () ,
.
8.5.3.
:
;
;
;
;
.
( )
, :
Database Desktop, , Delphi.
.
,
, Validity Checks ( ) Table properties ( ) (. . 8.9).
8.5.4.
:
, ;
( ).
II.
185
, ,
Referential Integrity ( )
Table properties ( ) (. . 8.9).
8.5.5.
() . , .
, : Database Desktop, Delphi.
8.5.6.
Table Language (
) Table properties ( ) (. . 8.9).
8.5.7.
, Table | Restructure ( | )
Database Desktop. , , .
, Delphi. Delphi
, Table
.
Table, , A c t i v e
False.
Database
Desktop, Windows, , .
Save as... (
) .
.
. -
Delphi.
186
, .
,
Table | Into Structure ( | ).
, ,
, .
, .
8.5.8.
Alias Manager ( ) (. 8.12),
Tools | Alias Manager ( | ) Database Desktop.
[Alias Manager
|7 Public aOas
Database alias: I
Diivertype; (STANDARD JJ
Path: |DAB00K_D\EX4MPL '
fiemove
'firowse...
OK
Cancel |
Help
. 8 . 1 2 .
( New) ( Remove) . ( )
( ) Database alias (
). , :
( Driver type) ( Path). , Browse
().
idapi.cfg .
II.
187
8.6.
, , ,
, .
- .
, .
. 8.13,
DBNavigatorl.
T a b l e l ,
DataSourcel,
I W
LAST_NAMES
Davis
Jones
1 Parker
Sawyer
Jennifer
Aithui
Debra
;Dave
DBGridl
jADDRESS_1'|:
CT
IY
1023495.100 Danbeiiji St. : Welesley
2094056 10HunnewelSt
Los Altos
1209395 74 South St Atherton
3094095 101 Oaka
l nd St LosAltos
1 "*
. 8.13.
Tablel .
DataBaseName, , TableName,
.
Active True.
True A c t i v e ,
DataBaseName TableName.
TableName. ( DataBaseName) ,
.
,
Delphi , clients.dbf.
, dbdemos.
7 3. 64!
188
Delphi.
DBGridl
DBNavigatorl
DataSource
DataBaseName
TableName
DataSourcel
DataSource
1 Tabiel
Client.dbf
Active
. 8.14.
.
. - . . 8.2 ,
, .
,
, , , .
,
, Database Form Wizard (
). Business .
, ,
Table Query.
II.
189
8.2.
Tablel
DataBaseName
dbdemos
TableName
clients.dbf
Active
true
DataSourcel
DataSet
Tablel
DBGridl
DataSource
DataSourcel
DBNavigatorl
DataSource
DataSourcel
9.1.
.
.
9.1.1.
.
, ,
. Delphi , . , , ,
. ,
. .
Delphi,
.
Delphi ,
T a b l e Query, TDBDataSet
TDataSet ( TBDEDataSet).
,
II.
1_
.
.
, ,
DatabaseName string. , ( ), , . (alias),
.
;
. ,
,
. Database
Desktop BDE Administrator.
, A c t i v e
False. .
.
, ,
RecordCount Longint. . , , SQL- ( Query).
. .
var i: integer;
Tablel.First;
for i := 1 to Tablel.RecordCount do begin
// ,
//
Tablel.Next;
end;
192
Delphi.
, i 1
RecordCount. F i r s t .
Next.
dBase Paradox , .
RecNo Longint,
.
, , :
Editl.Text := IntToStr(Tablel.RecNo);
Paradox RecNo , .
. .
Tablel.RecNo := StrToInt(Editl.Text);
, Editl. .
:
;
.
.
. .
, ,
. . , DBEdit DBText
. DBGrid .
, T a b l e Query.
.
, ,
II.
193
.
SQL-,
SQL.
.
.
9.1.2.
,
Active Boolean. Active True, .
Table , , TableName. Query SQL-,
SQL . Active False
( ), , .
.
DataSource
, , DBGrid DBEdit,
.
(
, . DBGrid.
- ,
Active True
, Active False.
TableName SQL.
A c t i v e False
DataBaseName, TableName SQL.
. .
Active,
Queryl.
procedure TForml.ButtonlClick(Sender: TObject);
194
Delphi.
begin
Queryl.Active := false;
Queryl.SQL.Clear;
Queryl.SQL.Add("select * from Examplel.db');
Queryl.Active := true;
end;
Open Close.
Open ,
Active True. close ,
Active False.
:
type TDataSetNotifyEvent = procedure(DataSet: TDataSet) of object;
DataSet ,
.
BeforeClose AfterClose
TDataSetNotifyEvent.
,
, . . , .
Post, .
post BeforeClose,
.
. .
procedure TForml.TablelBeforeClose(DataSet: TDataSet);
begin
if (Tablel.State = dsEdit) or (Tablel.State = dslnsert) then Tablel.Post;
end;
, Tablel
,
.
BeforeClose , .
II.
195
9.1.3.
.
s t a t e TDataSetstate,
.
.
( ) (
, ,
DBNavigator DBGrid).
.
dsinactive ; . , Active False.
dsBrowse
.
:
dsinactive Active
True;
dsEdit P o s t Cancel;
d s l n s e r t P o s t C a n c e l .
dsEdit .
dsBrowse Edit.
dsinsert . dsBrowse Insert, InsertRecord,
Append AppendRecord.
dsCalcFields .
OnCalcFields.
dsSetKey , .
dsBrowse
SetKey, SetRangeXXX, FindKey, GotoKey, FindNearest
GotoNearest. , Query SQL.
d s F i i t e r .
dsBrowse ,
onFiiterRecord. . OnFiiterRecord dsBrowse.
Delphi.
196
. 9.1, ,
.
Post, Cancel
StRangeXXX
EditRandeXXX +
. 9 . 1 .
, ,
dsEdit , dsinsert .
.
s t a t e TDataSetstate
DataSource.
DataSource OnStateChange TNotifyEvent.
. .
procedure TForml.DataSourcelStateChange(Sender: TObject);
begin
case DataSourcel.State of
dslnactive: Labell.Caption := ' ';
dsBrowse: Labell.Caption :=
' ';
dsEdit:
Labell.Caption :=
' ';
dsinsert: Labell.Caption :=
' '
II.
197
else Label1.Caption :=
1
';
end;
end;
,
Datasourcei, Labeii.
s t a t e . , , onstateChange DataSourcel.
9.1.4.
, Delphi Field TFieid , , TIntegerField, TFloatField
TStringFieid. , , ,
.
FieidByName.
FindField(const FieldName: String): TFieid , FieldName. FieldName , .
, FieldName, , , ( Name) F i e l d , .
Query FieldName SQL-.
198
Delphi.
9.1.5. Table
Table ,
. , Table
, dBase Paradox. Query.
Table
TabieName TFiieName, (
). TabieName .
. , ,
DatabaseName.
A c t i v e False.
, A c t i v e False. .
. .
procedure TForml.ButtonlClick(Sender: TObject) ;
begin
if OpenDialogl.Execute then begin
Tablel.Active := false;
Tablel.TabieName := OpenDialogl.FileName;
Tablel.Active := true;
end;
end;
Buttoni
. TabieName. Tablel
II,
199
.
.
TTtabieType . :
ttDefauit
;
ttParadox Paradox ;
ttDBase dBASE;
ttFoxPro FoxPro;
ttASCii ,
(ASCII-).
ttDefauit ( ),
:
DB Paradox;
DBF dBASE;
TXT (ASCII-).
Table . ,
, .
, Readonly Boolean.
False,
.
Table ,
:
;
;
.
indexName
indexFieidNames string.
, .
indexName indexFieidNames
, .
, .
indexName , , indexFieidNames ,
. , , indexName -
200
Delphi.
, IndexFieidNames , .
. .
Tablel. IndexNarne : = ' indName' ;
Table2.IndexFieidNames := 'Name';
Tablel 2 ,
Name indName. .
Paradox ( )
indexFieidNames,
,
IndexName.
:
Tablel.IndexFieidNames := 'Name;Post;BirthDay';
Paradox, Tablel, ,
Name, Post BirthDay.
.
IndexName IndexFieidNames .
.
, , . , IndexName IndexFieidNames, , .
, Table,
IndexName IndexFieidNames , .
IndexFieldCount IndexFields.
9.1.6. Query
Query , SQL- . Table, Query .
, ,
SQL TStrings.
II.
201
SQL . SQL
SQL-.
(. 9.2),
SQL.
(string List Editor
1<
1-|. = * FROM ^ersonnel2
TZ'-P, BY P Name
Cede editor... I
Cancel
Help
. 9.2. SQL
. , SQL-.
. 9.3 . ,
Queryl DataSourcel, .
SQL- Memol.
Buttoni
, DBGridi.
202
Delphi.
\ SQL-
SQL-
P_Coda
|P_Nome
IP.Birthday IP^Poaitipn
1 ..
19.10,1962
1 ..
27.01.1980
[P^Salaiy JPJsltj ^
6 700.00.
:2 400.00.
2 .P.
12.051977
| 4 500.00.
03111973
4 .
SQL-
SELECT * FROM Personnel?
ORDER BYP Name
[[]
. 9 . 3 . - SQL-
SQL-
(. 9.4),
. Queryl .
. 9 . 4 .
II.
203
TForml = class(TForm)
Memol: TMemo;
DataSourcel: TDataSource;
Query!: TQuery;
DBGridl: TDBGrid;
Buttonl: TButton;
Labell: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure ButtonlClick(Sender: TObject);
end;
var Forml: TForml;
implementation
{$R *.DFM}
procedure TForml.FormCreate(Sender: TObject);
begin
DataSourcel.DataSet := Queryl;
DBGridl.DataSource := DataSourcel;
end;
procedure TForml.ButtonlClick(Sender: TObject);
begin
Queryl.Close;
Queryl.SQL.Assign(Memol.Lines);
Queryl.Open;
end;
end.
Assign ,
.
( Tstrings), SQL
Queryl Lines Memol,
. ( ) ,
.
204
Delphi.
Query SQL- , .
Query
Open Active True.
Query , , .
RequestLive Boolean.
False, Query
. , RequestLive
True. Query
, Table.
(
RequestLive SQL-.
, R e q u e s t L i v e True .
RequestLive, CanModify Boolean. True, , False - .
SQL- , RequestLive True,
, , , .
Table Query. SQL SELECT * FROM NameTabieBD, RequestLive True, Query
Table ( NameTabieBD , TabieName). , , Query ,
, , ,
FindFirst, FindLast, FindNext FindPrior.
9.1.7.
TFieid .
II.
205
Field TField .
TFieid .
, , .
TField ,
, ,
, . TField
TField, , , TStringFieid ( )
TintegerFieid ( ). . 8.1 Field.
9.1. Field
TBLOLBField
BLOB-
TMemoField
Memo- ( )
TGraphicField
TDateTimeField
TNumericField
TBCDField
BCD-
TFloatField
TCurrencyField
TintegerFieid
TAutoincField
TStringFieid
:
( );
( ).
,
TField.
,
. ,
Table ,
, Query SQL-.
206
Delphi.
, , , .
.
() , :
,
, ;
;
;
;
.
, , ,
, , , .
,
, .
, .
9.1.8.
TFieid,
. () . , ,
. , , .
.
(
Query SQL,
, , .
II.
207
P_Cpde
P_Name
P_Brithday
P_Position
P Salary
P Note
. 9.5.
, , . :
;
;
.
,
( TField) . , TField .
Add Fields ( ).
Delete
<Delete>.
, ,
. , .
, .
208
Delphi.
.
. ,
<Ctrl>+<Page Up> <Ctrl>+<Page Down>.
(
,
TableName , . , , , ,
. , ,
.
9.1.9.
, , (), Name string. Field ,
. Field
, ,
.
. , Name
Table 1 , TablelName. ,
.
Field, FieldName s t r i n g , .
Name FieldName, .
. .
Tablel.FieldByName('Number').DisplayLabel := '';
TablelNumber.DisplayLabel := '';
Number :
Field .
value Asxxx.
value variant
TField.
. value,
II.
209
.
. Asxxx.
procedure TForml.Button2Click(Sender: TObject);
var s: string;
x: real;
begin
//
s := Tablel.FieldByName('Salary').AsString;
:= Tablel.FieldByName('Salary').AsFloat;
Labell.Caption := s;
Label2.Caption := FloatToStr(x);
//
s := TablelSalary.AsString;
:= TablelSalary.AsFloat;
Label3.Caption := s;
Label4.Caption := FloatToStr(x);
end;
Salary .
, .
~
, , , , .
,
, Readonly Visible Boolean.
canModify Boolean. ,
Readonly CanModify : ( ) .
(
CanModify True, ,
.
( v i s i b l e
False), ( Readonly
False), .
210
Delphi.
9.1.10.
,
. Delphi
DataSource.
, ,
Dataset TDataSet . DataSource.
.
, , s t a t e TDatasetstate.
DataSource OnStateChange TNotifyEvent.
, AutoEdit
Boolean , . , DBGrid DBEdit - ,
. AutoEdit True, . ,
AutoEdit False.
(
A u t o E d i t
.
.
A u t o E d i t
DBNavigator.
OnDataChange TDataChangeEvent, :
type TDataChangeEvent = procedure (Sender: TObject; Field: TField)
of object;
II,
211
Field ; , , Nil.
, OnDataChange
. , , , ,
, . OnDataChange , , , .
.
:
procedure TForml.DataSourcelDataChange(Sender: TObject; Field: TField);
begin
Label1.Caption := ' ' + IntToStr(Tablel.RecNo);
end;
9.2.
Data Controls ( )
. ,
. , .
, . , , DBEdit
DBImage.
. DBGrid
DBCtriGrid, .
Standard () Additional ()
212
Delphi.
, , ,
Datasource DataFieid.
Datasource,
, . ,
DBEdit , Edit, . , DBEdit
.
, , , .
, , ,
.
.
Edit
. () , , , post .
, , ( QReport ( ) ), .
. 9.2
, Standard ()
Additional
()
,
( Data Controls ( ))
( Qreport ( )).
: DBGrid
DBNavigator, , .
9.2. ,
Standard Additional
Data Controls
QReport
Label
DBText
QRLabel
Edit
DBEdit
II.
213
9.2. ()
Standard Additional
Data Controls
QReport
Memo
DBMemo
RichEdit
DBRichEdit
QRRichEdit,
ListBox
DBListBox
ComboBox
DBComboBox
CheckBox
DBCheckBox
RadioGroup
DBRadioGroup
Image
DBImage
QRImage, QRDBImage
Shape
QRShape
StringGrid
DBGrid
Chart
DBChart
QRChart
QRDBRichEdit
9.2.1.
, Delphi DBGrid.
,
, .
,
. .
- . <Insert>,
.
. , ,
<Enter> , <Esc>.
<Ctrl>+<Delete>.
9.2.2.
, DBGrid
StringGrid, . ,
StringGrid
. DBGrid ,
, .
214
Delphi.
columns
TDBGridColumns, ()
column TCoiumn, .
s e l e c t e d i n d e x i n t e g e r Columns, S e l e c t e d F i e l d TField,
.
FieidCount i n t e g e r , F i e l d s
[index: i n t e g e r ] T F i e l d
. 0 FieidCount-1.
c o l o r FixedCoior TCoior , . Color
ciwindow ( Windows), FixedCoior clBtnFace ( ).
T i t i e F o n t TFont , .
Options
TGridOptions. :
dgEditing ;
dgAiwaysShowEditor ;
d g T i t i e s ;
d g i n d i c a t o r ;
dgCoiumnResize ;
dgCoiLins
;
dgRowLines ;
dgTabs <>
<Shift>+<Tab>;
dgRowSeiect ;
d g E d i t i n g
dgAiwaysShowEditor;
dgAiwaysshowSeiection ,
;
dgConfirmDeiete ;
II.
215
dgCanceionExit () ;
dgMuitiSeiect
.
Options
dgTitles,
dglndicator,
dgColumnResize,
dgTabs, dgConfirmDelete, dgCanceionExit].
dgColLines,
[dgEditing,
dgRowLines,
onceiiciick,
onTitleCiick. TDBGridciickEvent, :
type TDBGridciickEvent = procedure (Column: TColumn) of object;
column , .
onCoiEnter onCoiExit TNotifyEvent,
, .
DBGrid ,
. , , , , , .
OnDrawColumnCell TDrawColumnCellEvent, . OnDrawColumnCell
:
type TDrawColumnCellEvent = procedure (Sender: TObject;
const Rect: TRect; DataCoi: Integer;
Column: TColumn; State: TGridDrawState) of object;
Rect , DataCoi , column . s t a t e
:
gdSeiected ;
gdFocused ;
gdFixed .
OnDrawColumnCell
DefauitDrawing Boolean. True (
), OnDrawColumnCell .
. DefauitDrawing -
216
Delphi.
False, onDrawCoiumnCeii, .
. .
// DefaultDrawing True
procedure TForml.DBGridlDrawColumnCell(Sender: TObject; const
Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var r :TRect;
s :string;
begin
s := Tablel.FieldByName(Column.FieldName).AsString;
r := Rect;
if (Column.FieldName = 'Debt') then begin
DBGridl.Canvas.Brush.Color := clRed;
DBGridl.Canvas.Font.Color := clYellow;
DBGridl.Canvas.Font.Style := [fsltalic];
DBGridl.Canvas.FillRect(Rect) ;
if Tablel.FieldByName(Column.FieldName).AsCurrency > 1000
then begin
ImageListl.Draw(DBGridl.Canvas, Rect.Left + 2, Rect.Top + 2 , 2);
r.Left := r.Left + ImageListl.Width + 4;
end;
DBGridl.Canvas.TextOut(r.Left, r.Top + 2, s);
end
else begin
DBGridl.Canvas.Brush.Color := clWhite;
DBGridl.Canvas.FillRect(Rect);
DBGridl.Canvas.Font.Color := clBlack;
DBGridl.Canvas.Font.Style := [];
DBGridl.Canvas.TextOut(r.Left, r.Top + 2, s) ;
end;
end;
, Debt ()
, ,
. ,
1000 ( ), Debt
,
ImageListl ( ). .
II.
217
canvas DBGridi,
Rect. OnDrawColumnCeii DBGrid, ( DBGridi)
(Sender as TDBGrid) TDBGrid (sender). ,
(Sender as TDBGrid).Canvas.Font.Color := clRed;
, Sender.
9.2.3.
Column TCoiumn.
,
DBGrid, ,
. . .
,
.
,
.
.
,
.
(
TFieid), TCoiumn.
: TFieid
TCoiumn. ,
, .
,
,
. ,
, ,
. ,
TCoiumn , .
(. 9.6)
DBGrid Columns Editor (
) columns .
Delphi.
218
I f f Editing DDGiidl Columns
ffi ?
1-G_Name
2-6 Price
3 - G~Unit
4 G_Note
5 TCou
l mn
6 TCou
l mn
. 9 . 6 .
,
, DBGridi.Columns. , Toolbar ( ) .
, (
).
, T F i e l d , .
, ,
. :
;
;
.
, ( TColumn) .
, TColumn
.
, ,
.
Columns TDBGridColumns.
(,
) .
II.
219
.
Alignment TAiignment :
taLeftJustify ;
taCenter ;
taRightJustify .
Count integer .
Field TFieid ,
.
FieidName string ,
. .
pickList TStrings . PickList
.
,
, .
.
T i t l e TCoiumnTitie .
, , caption,
Alignment, Color Font, , ,
, .
, , ,
.
. .
, . , , :
//
procedure TForml.FormCreate(Sender:
TObject);
begin
//
DBGridl.Columns[0].Visible := false;
//
8 3 641
Delphi.
220
DBGridl.Columns[1].Title.Caption := ' ';
DBGridl.Columns[1].Title.Alignment := taCenter;
DBGridl.Columns[1].Alignment := taCenter;
//
DBGridl.Columns[2].Visible := false;
//
DBGridl.Columns[3].Title.Caption := '';
DBGridl.Columns[3].Title.Alignment := taCenter;
DBGridl.Columns[3].Alignment := taRightJustify;
//
DBGridl.Columns[4].Title.Caption := '';
DBGridl.Columns[4].Title.Alignment := taCenter;
DBGridl.Columns[4].Title.Alignment := taLeftJustify;
DBGridl.Columns[4].PickList.Clear;
DBGridl.Columns[4].PickList.Add(' 1);
DBGridl.Columns[4].PickList.Add('') ;
DBGridl.Columns[4].PickList.Add(' ');
end;
, , . , ,
, . , . . 9.7.
DBGrid
,
,
.
W UBGrid
. 9.7.
II.
221
. .
Queryi, SQL- Memoi.
Buttoni
SQL. DBGridi. Button2
() , 2 (. 9.8).
\ DBGrid
SQL
P_Code
[P.Name
1
2
3
4
5
|P_Posi>ioiV
. ..
..
..
..
..
fP.Salary J * j
5 600.00
5 300.00
4 800.00
4 .
3 700.00
. 9.8.
.
// SQL-
procedure TForml.ButtoniClick(Sender: TObject);
begin
Queryi.Close;
Queryi.SQL.Assign(Memol.Lines);
Queryi.Open;
end;
//
procedure TForml.Button2Click(Sender: TObject);
var c, n
s, rs
:integer;
:string;
begin
Memo2.Clear;
Queryi.First;
222
Delphi.
/I
for n := I to Queryl.RecordCount do begin
rs : = " ; s : = " ;
//
if n = 1 then begin
for := 0 to DBGridl.Columns.Count 1 do begin
s := DBGridl.Columns[c].FieldName + ' ';
rs := rs + s;
end;
Memo2.Lines.Add(rs) ;
Rs : = " ; s : =
end;
//
for : = 0 to DBGridl. Columns. Count 1 do begin
s := DBGridl.Columns[c].Field.AsString + ' ';
rs := rs + s;
end;
Memo2.Lines.Add(rs) ;
Queryl.Next;
end;
end;
FieldName, Count Field .
9.2.4.
,
.
.
Delphi DBNavigator (. 9.9).
X "
. 9.9.
,
. visibieButtons
TButtonSet, (
):
II.
223
nbFirst (First);
nbPrior (prior);
nbNext (Next);
nbLast (Last);
nbinsert (insert);
nbDelete (Delete);
nbEdit (Edit);
nbPost (post);
nbcancel (cancel);
nbRefresh (Refresh).
.
BtnClick (Index: TNavigateBtn) , index. TNavigateBtn TButtonSet,
. , :
DBNavigator.BtnClick(nbNext);
nbNext,
.
Delete Record ( ) , .
ConfirmDelete Boolean, True, . .
.
False, .
Flat Boolean . False, .
Fiat True
, .
Hints TString.
, ,
String list editor.
Hint string. ,
True showHint, False.
Button BitBtn, .
224
Delphi.
.
.
procedure TForml.ButtonlClick(Sender: TObject);
begin
Tablel.Next;
end;
procedure TForml.Button2Click(Sender: TObject);
begin
Tablel.Prior;
end;
10
.
Table Query.
. , . . , , . Table Query
.
:
;
;
;
;
.
,
, SQL-.
10.1.
. , ,
Paradox , dBase
.
.
226
Delphi.
. , ,
.
Query . Table,
Query SQL.
. . , ,
. ,
.
ixDescending , ,
. ixDescending ,
.
, ( ),
, IndexName IndexFieldNames. ,
. IndexName , . indexFieidNames , .
, () Paradox ,
IndexFieidNames.
. .
procedure TForml.Button4Click(Sender: TObject);
begin
case RadioGroupl.Itemlndex of
0: Tablel.IndexName := 'indName';
1: Tablel.IndexName := 'indBirthDay';
end;
end;
Tablel,
: indName,
Name, indBirthDay, BirthDay.
. .
II.
227
code .
procedure TForml.Button5Click(Sender: TObject);
begin
case RadioGroupl.Itemlndex of
0: Tablel.IndexFieldNames := 'Name';
'Name;BirthDay';
1: Tablel.IndexFieldNames
1
Code';
2: Tablel.IndexFieldNames
end;
end;
: Name ( indName),
Name BirthDay ( indNameBirthDay), Code ( ).
. .
Tablel. : , .
btnsort . . 10.1.
I
|P_Po8iiicin
,P_Nan
.
_]
|p_Snlaiy |P_Nols
6 700
1 500.00
4 .
loo.oop
-.
- . ':
,<* .
: : :
. 10.1.
, Table DataSource ,
, . DataSource DBGrid,
.
btnsort, .
228
Delphi.
10.2.
(). , , .
. , .
:
F i r s t ;
Next (
);
Last ;
II.
229
Prior (
);
MoveBy (Distance: Integer) : Integer , Distance.
, , . . Distance ,
. , .
, . ,
,
. Recordcount.
, , -
, RecNo.
Beforescroii
Afterscroli
TDataSetNotifyEvent.
. .
procedure TForml.Button3Click(Sender: TObject);
var sum: real;
n: integer;
begin
sum := 0;
//
Tablel.First;
for n := 1 to Tablel.Recordcount do begin
inc(sum, Tablel.FieldByName('Salary').AsFloat);
//
Tablel.Next;
end;
Label2.Caption := FloatToStr(sum);
end;
230
Delphi.
Tabiei,
s ,
Salary. Next,
. F i r s t
.
.
,
integer, longint,
RecordCount.
,
. , Last
Prior.
RecNo, ,
( dBase Paradox).
Paradox RecNo
:
RecNo , . :
procedure TForml.ButtonlClick(Sender: TObject);
begin
Tablel.RecNo := StrToInt(Editl.Text);
end;
Buttoni
Tablel , Editl.
BOF EOF Boolean, . . BOF ,
. True
, , First.
EOF , . True .
II.
231
. .
procedure TForml.Button2Click(Sender: TObject);
var sum: real;
begin
sum := 0;
Tablel.First;
while not Tablel.EOF do begin
sum := sum + Tablel.FieldByName('Salary').AsFloat;
Tablel.Next;
end;
Label2.Caption := FloatToStr(sum);
end;
, Tablel ,
salary. ,
,
.
,
, .
,
, . DisableControls EnableControls.
, DBGrid DBNavigator.
, .
, First record, Prior record, Next record
Last record DBNavigatorl First,
Prior, Next Last, , ,
, ( DataSource)
DBNavigatorl.
,
, Button, . . ,
Prior.
232
Delphi.
, ( )
, , ,
.
10.3.
,
. ,
Table ,
Query , SQL-, SQL.
(
SQL-, . SQL- ,
, .
Delphi :
;
.
, , , . ,
, .
F i l t e r string.
, :
;
;
;
;
;
.
II.
233
, ,
.
, , , ,
. ,
. - ,
.
Pascal <, >, =, <=, >= <>.
+, -, * / (, ,
, ).
AND, OR NOT ( , , ).
.
:
Salary <= 2000
Post = '' OR Post = ''
,
(salary) 2000.
, (Post)
.
, OnFilterRecord.
F i l t e r
Boolean. False, . F i l t e r e d True , , , F i l t e r .
( ), .
.
, . (
F i l t e r e d False),
.
234
Delphi.
Filteroptions
TFiiterOptidns. :
foCaseinsensitive , . . Post = '' , . foCaseinsensitive , , ;
foNoPartiaicompare , .
. ( ) , ,
* foNoPartiaicompare. ,
foNoPartiaicompare Post = ' * '
, Post ,
., - .
F i l t e r o p t i o n s [ ] .
. , .
. 10.2.
.
Code2
3
4
6
7
JFirm
""
"
""
""
Idly,
'"'"
Id
13
-
-
JLLJ
( ,=
'
-1
. Cily=Fajj4t
. 10.2.
II.
235
Formi
Delphi.
236
]*'
|P..Birthday]P_Pos[tioii
|P_Salaty' | P _ N t u ]
12 051977
1500 00.
3;
03111973 '
4 300.00.
4 ..
.27.01.1980
2 400.00.
5:..
31.12.1982
2 500.00.
-"
'"
< <
01 1965
' *
position ''
/. . .
. 10.3.
. .
.
Formi .
procedure TForml.FormCreate(Sender: TObject);
begin
Tablel.Filter := '';
Tablel.FilterOptions := [foCaselnsensitive];
Tablel.Filtered := true;
end;
procedure TForml.btnFilterClick(Sender: TObject);
begin
//
if rbFilterSalary.Checked then Tablel.Filter :=
'P_Salary > ' + edtSalaryMin.Text +
' AND P_Salary < ' + edtSalaryMax.Text;
//
if rbFilterBirthday.Checked then Tablel.Filter :=
'P_BirthDay > '+ DateToStr(dtpBirthdayMin.Date) +
1
//
if rbFilterExpression.Checked then Tablel.Filter := edtFilter.Text;
//
II.
237
TDateTimePicker
(dtpBirthdayMin
dtpBirthdayMax),
.
edtsaiaryMin
edtSalaryMax.
, .
.
,
OR NOT. , , ,
,
edtFilter.
, ,
, .
10.4.
, .
, .
,
,
.
10.4.1.
Locate Lookup,
.
Locate (const KeyFields: String; const KeyValues: Variant;
Options: TLocateOptions) : Boolean
. , . , True,
False. , ,
KeyFields, . KeyValues
238
Delphi.
variant . , , ,
.
, Locate .
options ,
.
TLocateOptions :
locaseinsensitive ;
loPartiaiKey .
, TLocateOptions T F i l t e r O p t i o n s ,
,
loPartiaiKey foNoPartialCompare ."
, .
(
~~}
Options l o P a r t i a i K e y l o c a s e i n s e n s i t i v e .
. .
Tablel.Locate('Number', 123, []);
Number ,
123. . Locate .
Locate KeyValues variant, .
VarArrayOf.
,
KeyFields. :
Tablel.Locate('Name;Post;', VarArrayOf(['', '']),
[locaseinsensitive, loPartiaiKey]);
Name Post, , ,
. . .
,
.
,
.
II.
239
Lookup,
Locate. Lookup (const KeyFields:
String; const KeyValues: Variant; const ResultFields: String):
variant , , , Locate, , .
, Lookup
.
KeyFields KeyValues , Locate, .
ResultFields
, .
, . ResultFields . ,
Code, Name, Salary Note, TO R e s u l t F i e l d s
Salary Name.
10.4.2.
Table , .
, . ,
FindKey, SetKey, EditKey GotoKey,
10.5.
, .
. .
Readonly Boolean,
True . Readonly
False, .
240
Delphi.
Readonly .
, , E d i t
Memo, (), .
, ,
canModify Boolean, . True,
, False, ,
.
, .
, , Edit
Append .
, , DBEdit DBGrid, .
, AutoEdit DateSource True ( ).
False, .
(
A u t o E d i t , DateSource,
, , , B u t t o n checkBox.
DateSource OnUpdateData.
,
,
. Refresh, . ,
,
.
II,
241
, . , ,
, , . Table
.
, ,
.
. , .
Tablel.Edit;
Tablel.FieldByName('Name')-AsString := Editl.Text;
Tablel.Post;
Tablel.Refresh;
Form2.Table2.Refresh;
Tablel, Formi, , 2,
Form2. . Forml
Form2.
10.5.1.
. , , , . ,
, :
;
;
,
.
Edit,
:
,
;
,
;
, .
242
Delphi.
Edit
(, canModify).
:
if Tablel.CanModify then Tablel.Edit;
, . , ,
.
, DBGrid DBEdit
- , , DBNavigator
Edit Record. ,
Edit . , , .
, , ,
Button , .
. .
procedure TForml.btnEditClick(Sender: TObject);
begin
if not Tablel.CanModify then begin
Beep;
MessageDlg(' !', mtlnformation, [mbOK], 0);
exit;
end;
Tablel.Edit;
end;
btnEdit, Edit.
,
Tablel, ,
.
, .
. .
II.
243
244
Delphi.
if MessageDlg(' ?',
mtConfirmation, [mbYes, nibNo], 0) <> mrYes then Abort;
end;
, .
,
. :
Tablel.FieldByName('City').AsString := Edit1.Text;
Tablel.FieldByName('Code').Aslnteger := StrToInt(Edit2.Text);
Tablel.FieldByName('Price').AsFloat := StrToFloat(Edit3.Text);
Tablel
. Edit2 Edit3 , , .
, ,
Modified Boolean. True,
.
, .
Post ,
. , Post
.
BeforePost
TDataSetNotifyEvent,
AfterPost TDataSetNotifyEvent. BeforePost,
,
, "" .
. , .
procedure TForml.btnPriceChangeClick(Sender: TObject);
var bml:
coeff, x:
TBookmark;
real;
begin
// ,
if not Tablel.CanModif then begin
MessageDlg(' !', mtError, [mbOK], 0);
exit ;
end;
II.
245
//
try
coeff := StrToFloat(Editl.Text);
except
MessageDlg(' !' + #13#10 +
' .', mtError, [mbOK], 0);
if Editl.CanFocus then Editl.SetFocus;
exit;
end;
//
bml := Tablel.GetBookmark;
//
Tablel.DisableControls;
//
Tablel.First;
while not Tablel.EOF do begin
//
:= Tablel.FieldByName('Price').AsFloat;
//
x := x * Coeff;
//
Tablel.Edit;
Tablel.FieldByName('Price').AsFloat := x;
Tablel.Post;
//
Tablel.Next;
end;
//
//
if Tablel.BookmarkValid(bml) then Tablel.GotoBookmark(bml);
if Tablel.BookmarkValid(bml) then Tablel.FreeBookmark(bml);
Tablel.EnableControls;
end;
Tablel
Price. ,
Editl.
246
Delphi.
,
. , DBGrid
<Esc>, DBNavigator Cancel Edit.
RoiiBack TDateBase.
Post SetFields
(const Values: array of const), .
10.5.2.
, .
:
II.
247
;
;
, .
I n s e r t , I n s e r t R e c o r d , Append
AppendRecord.
insert
. , . insert .
() , . setFieids,
Post cancel.
, .
(
,
.
, "-",
, .
. .
procedure TForml.ButtonlClick(Sender: TObject);
begin
Tablel.Insert;
Tablel.FieldByName('Name').AsString := Editl.Text;
Tablel.FieldByName('Group').AsString := Edit2.Text;
Tablel.Post;
end;
(Name)
(Group), . , ,
.
248
Delphi.
SetFields. ,
.
. SetFields.
procedure TForml.btnlnsertClick(Sender: TObject);
begin
if not Tablel.CanModify then begin
II.
249
B e f o r e l n s e r t A f t e r l n s e r t TDataSetNotifyEvent,
OnNewRecord TDataSetNotifyEvent.
B e f o r e l n s e r t OnNewRecord , -
() . :
procedure TForml.TablelNewRecord(DataSet: TDataSet);
begin
Table1.FieldByName('Unit').AsString := '';
Tablel.FieldByName('NDS').AsString := '20';
end;
,
, BeforePost
AfterPost
BeforeCancel AfterCancel.
10.5.3.
Delete,
.
, ,
,
.
Delete ,
.
, Delete
Cancel, .
, D e l e t e
.
BeforeDelete AfterDelete
TDataSetNotifyEvent. BeforeDelete,
,
.
Delete , , onDeieteError, .
, , Delete -
250
Delphi.
, . ( ) .
:
procedure TForml.btnDeleteAHClick(Sender: TObject);
var n: longint;
begin
Tablel.Last;
for n := Tablel.RecordCount downto 1 do Tablel.Delete;
end;
.
.
Table EmptyTabie,
.
(), . . Delete
, .
, ,
.
10.6.
, . . , ,
. "--",
. "-".
- ,
. .
, :
MasterSource ;
indexName ;
II.
251
indexFieidNames
;
MasterFieids .
.
()
.
.
( ).
.
, , Database Desktop . ,
-
.
10.6.1.
, .
Paradox: store cards , ( ) . . 10.1 10.2. ( ).
, .
10.1. store
S Code
S Name
9 6-t I
20
Delphi.
252
10. 1 ()
SJJnit
S_Price
S_Quantit
S Note
.
30
10.2. Cards
Number
Code
Move
Date
"-",
store , Cards (. 10.4).
s_code . ,
.
( ) c_code,
.
fmstore
(. 10.5) fminput .
,
.
II.
253
, .
,
DBGrid. .
S_Code
S_Name
SJJnit
S_Price
S_Quantity
S_Note
Store.db
( )
S _ N umber
S_Code
S_Move
S_Date
Cards.db
. 1 0 . 4 . S t o r e C a r d s
S_Code
S_Name
S_Unil
1
2
|S_Piice
S_Quartity jS_Note
27
320
250
0
7
13.
19.
6
JJ
CJJumber ,jC_Code
1
2
3
4
9
_
|C_Move
C_Date
2
100 12 04.01
70 14 04 01
2
200 20 04.01
2
130 22.04.01
2
40 30.04.01
2
-!
f
. 1 0 . 5 .
Delphi.
254
DBGrid ,
AutoEdit False. Button,
fminput. btnNew btnDeiete
.
btnNew
fminput (. 10.6), DBEdit,
, ,
store. dsstore, fmstore. ,
uinput ustore .
, .
j *J"
. 1 0 . 6 .
, - DBEdit ( ) .
, ,
, . , . ,
, .
btnDeiete,
.
,
.
btnMove -. , ,
.
.
II.
255
,
,
inputQuery, .
,
, fminput.
() , .
. , .
s Q u a n t i t y .
cbMoveAii
. ,
.
, . btnDeiete
, .
, :
;
;
DBGrid,
.
.
.
//
unit uStore;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, Db, DBTables, ExtCtrls, DBCtrls, Grids,
DBGrids, StdCtrls, DBCGrids;
type
TfmStore = class(TForm)
dsStore: TDataSource;
TableStore: TTable;
DBGridStore: TDBGrid;
dsCard: TDataSource;
256
Delphi.
TableCard: TTable;
DBGridCard: TDBGrid;
Label1: TLabel;
Label2: TLabel;
btnMove: TBut ton;
btnNew: TButton;
btnDelete: TButton;
cbMoveAll: TCheckBox;
procedure
procedure
procedure
procedure
procedure
end;
FormCreate(Sender: TObject);
btnNewClick(Sender: TObject);
btnDeleteClick(Sender: TObject);
btnMoveClick(Sender: TObject);
cbMoveAllClick(Sender: TObject);
II.
257
var n: longint;
begin
if TableStore.RecordCount = 0 then exit;
if MessageDlg(' ?', mtConfirmation, [mbOK, mbNo], 0) = mrOK
then begin
// ( )
TableCard.Last;
for n := 1 to TableCard.RecordCount do TableCard.Delete;
//
TableStore.Delete;
end;
end;
procedure TfmStore.btnMoveClick(Sender: TObject);
var sMove: string;
nMove: double;
begin
if InputQuery (' 1 +
TableStore. FieldByName ( ' S__Name ') . AsString,
' ', sMove) then begin
//
try
nMove := StrToFloat(sMove);
except
Beep;
MessageDlg (' : ' + sMove,
mtError, [mbOK], 0);
exit;
end;
//
TableCard.Append;
// C_Code S_Code
TableCard.FieldByName('C_Move').AsFloat := nMove;
TableCard.FieldByName('C_Date').AsDateTime := Now;
TableCard.Post;
//
TableStore.Edit;
TableStore.FieldByName('S_Quantify').AsFloat:=
TableStore.FieldByName('S_Quantify').AsFloat + nMove;
TableStore.Post;
258
Delphi.
end;
end;
procedure TfmStore.cbMoveAllClick(Sender: TObject);
begin
if not cbMoveAll.Checked then begin
TableCard.IndexFieldNames := 'C_Code';
TableCard.MasterFields := 'S__Code';
btnDelete.Enabled := true;
end
else begin
TableCard.IndexName := '';
TableCard.IndexFieldNames := '';
TableCard.MasterFields := '';
btnDelete.Enabled := false;
end;
end;
end.
//
unit ulnput;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Mask, DBCtrls;
type
Tfmlnput = class(TForm)
dbeName: TDBEdit;
dbeUnit: TDBEdit;
dbePrice: TDBEdit;
dbeNote: TDBEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
btnOK: TButton;
btnCancel: TButton;
procedure FormCreate(Sender: TObject);
end;
II.
259
MasterSource TableCard,
d s s t o r e .
260
Delphi.
Field Link Designei
Available Indexes
. 10.7.
, , , .
10.6.2.
. ,
.
- , , ,
, . , , .
.
. ,
.
. ,
, ( " ").
, .
Delphi StartTransaction, Commit Rollback
DataBase. StartTransaction , -
II.
261
, .
. ,
Commit, , .
Rollback,
.
,
btnMove , .
TabieCard Tabiestore.
, ,
DataBasei.
//
Databasel.StartTransaction;
try
TabieCard.Append;
TabieCard.FieldByName('C_Move').AsFloat := nMove;
TabieCard.FieldByName('C_Date').AsDateTime := Now;
TabieCard.Post;
TableStore.Edit;
TableStore.FieldByName('S_Quantity').AsFloat :=
TableStore.FieldByName('S_Quantity').AsFloat + nMove;
TableStore.Post;
//
//
Databasel.Commit;
except
//
//
Databasel.Rollback;
end;
, .
, .
SQL .
11
, , . Delphi QuickReport,
.
11.1.
, , QReport ( ) . .
Standard (), Additional () Data Controls ( ). ,
QRImage Image DBImage.
11.1.1.
II.
263
, , .
() , .
QuickRep Table Query,
, DataSet.
Query , .
.
,
DataSource . QuickRep
,
. , , , / , .
. .
Uses Unitl;
QuickRepl.DataSet := Forml.Tablel;
QuickRepl, , Tablel, Forml. fmReport
(uses Unitl) Forml.
,
.
.
.
. 11.1.
Bands
TQuickRepBands. /
Bands, , HasTitie. :
HasPageHeader ;
HasTitie
HasColumnHeader ;
HasDetaii ;
HasSummary ;
HasPageFooter .
264
Delphi.
1
2
DataSet
. 1 1 . 1 .
QRBand,
BandType .
Page TQRPage,
,
, , .
,
(, )
Report Setting ( ) .
Report Setting ( )
.
,
Frame TQRFrame:
color ( );
width ( 1);
style ( );
DrawTop, DrawBottom, DrawLeft, DrawRight ,
, , ( , ).
PrinterSetting TQuickRepPrinterSettings :
FirstPage LastPage
;
C o p e i s ;
II.
265
Duplex ;
OutputBin .
PrintDialog PrinterSetupDialog PrinterSetup.
,
Options TQuickReportOptions:
FirstPageHeader
;
LastPageFooter
;
compression , , .
Options
[FirstPageHeader,
LastPageFooter].
PrintifEmpty Boolean , .
True, , .
, , . PrintifEmpty
False, , , . , , , .
. showProgress Boolean.
True, .
<Esc>.
Print,
. .
Print , , ,
, .
- QuickRep ,
DBGrid ,
, (. 11.2). () /
, .
Delphi.
266
,
, , .
91
1
| |P_Name- .
H Q
.
U
|p_Position
6 700 00.
03 04 1962
5 200 00.
12 10 1962
5 20000.
0711.1981
2005.1978
2 40000
1*
^1
.
1
. 1 1 . 2 .
. .
Uses uReport;
procedure TForml.btnPrintClick(Sender: TObject);
var bm: TBookmark;
begin
//
bm := Tablel.GetBookmark;
//
fmReport.QuickRepl.Print;
//
Tablel.GotoBookmark(bm);
Tablel.FreeBookmark(bm);
end;
bm
. uReport fmReport
uses Formi,
.
BeforePrint AfterPrint
TQRBeforePrintEvent.
, ,
, .
II.
267
, .
B e f o r e P r i n t , , , , -.
Preview,
(. 11.3). :
;
;
;
;
;
.
Preview Print, ,
, . .
, Preview () .
, , .
< g&.
..
6 700 00.
5 200 00.
5 200
3 600
29 101951
03 04 1962
12 101962
07 11198)
. 1 1 . 3 .
268
Delphi.
, , , .
, QRPreview.
11.1.2.
( QRBand)
() , .
BandType TQRBandType,
:
rbTitie ( );
rbPageHeader , , , ( ) FirstPageFooter Options ; , ;
rbDetail ; ;
rbPageFooter , , , ( )
LastPageFooter Options ;
,
;
rbSummary ;
, .
.
. ,
.
Height .
:
QRBand
BandType;
True Bands
QuickRep, , BandType .
II.
269
,
"" . ,
(rbTitie), , . ,
, rbDetaii,
.
,
Frame, QuickRep.
BeforePrint
TQRBeforePrintEvent AfterPrint TQRAfterPrintEvent.
BeforePrint ,
.
type procedure BeforePrint (Sender: TObject; var PrintBand: Boolean) of
object;
PrintBand , .
, False. BeforePrint , ,
.
Preview B e f o r e P r i n t A f t e r P r i n t .
. , .
procedure TfmReport.DetailBandlBeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean) ;
begin
PrintBand := Form2.Tablel.FieldByName('Salary').AsFloat > 3000;
end;
, salary
3000.
11.1.3. ,
, -
270
Delphi.
II.
271
.
.
.
, ,
A l i g n m e n t . , , QRLabel
QRDBText. . , , ,
(tacenter),
(taRightJustify).
AutoSize.
, AutoSize True.
.
, ,
, .
AutoSize False.
Font . Font QuickRep ParentFont ,
. QuickRep. ParentFont True, .
- , ParentFont False.
Frame, , , .
onPrint
TQRLabelonPrintEvent, .
type TQRLabelonPrintEvent = procedure (Sender: TObject;
Var Value: String) of Object;
value ,
. .
272
Delphi.
onPrint
, .
. .
procedure TfmReport.QRDBText3Print(Sender: TObject; var Value: String);
begin
Value := Value + '%';
end;
QRDBText3 .
.
OnPrint , , . , QRDBText (
Alignment taRightJustify)
.
:
Value := Value + '
';
, .
OnPrint
.
(
O n P r i n t Preview, .
11.2.
,
, , .
, DBGrid. ,
, ,
.
, ,
(. 11.4). .
:
II.
273
QuickRep;
QuickRep ;
, QRLabei,
QRDBText QRExpr;
- , , , , .
11|"
30.04.200f
jP[ I
'.
r
P_Name.
[
^Positiqn
'!
[P_Salary
^Birthday,
| -]
{
. ]
. 11.4.
, ,
QuickRep .
,
:
(rbPageHeader);
(rbTitie);
(rbColumnHeader);
( r b D e t a i l ) ;
(rbSummary);
(rbPageFooter).
.
,
QuickReport List ( ), Forms ().
274
Delphi.
11.2.1.
, .
QRLabei, ( , ).
, , ,
, . . 11.4
.
QRiabel,
.
20 . QRimage.
Font
QuickRep 12 .
11.2.2.
,
, . .
QRiabel, , .
QRDBText QRExpr.
QRDBText,
. DataSet,
DataFiieid.
,
. ,
, .
( ), PrintifEmpty
QuickRep True ( ).
QRExpr , . Expression string,
Expression Wizard ( ), .
, QRiabel,
QRDBText QRExpr, .
II.
275
11.2.3.
. ,
, - ,
, .
: QRiabei
QRExpr .
, ,
.
QRExpr :
SUM ;
MIN ;
;
AVERAGE ;
COUNT .
, COUNT, ,
.
QRSysData
qrsDetailCount
Data.
. 11.4 ( -) , .
11.2.4.
,
, , .
QRSysData, Data.
QRSysData, :
;
;
, Text
.
,
, QRLabel .
Bands 263
BDE 159, 174
Beforelnsert 249
BitBtn 108
BtnClick 223
Button 105
CanModify 209
Close 122, 194
Code 164
Color 72
Commit 261
ConfirmDelete 223
Create 120
Cursor 74
DBNavigatorl 188
Delete 249
Destroy 123
DFM 10, 120
DLL 15
DOF 10
DPR 10
DragCursor 75
DragMode 75
Enabled 75
EXE 15
Execute 143, 145
Field 205
Filter 233
FilterOptions 234
FindField 197
Flat 223
Font 76
Form 119
FormStyle 125
Frame 264
Free 123
GroupBox 116
Database Desktop 178
DatabaseName 191
DataSourcel 188
DB 178
DBGrid 213
DBGridl 188
DBNavigator 222
H
Height 76
HelpContext 77
Hide 122
Hint 77
IDE 5
IndexFieldNames 199, 251
IndexName 199, 228, 250
Insert 154, 247
InsertRecord 248
ixDescending 226
Left 76
Load From File 88
Locate 237
M
MainMenu 150
MaskEdit 93
MasterFields 251
MasterSource 250
Memo 98
MessageDlg 140, 141
N
Name 21
Number 164
Object Pascal 31
OnActivate 122
OnCellClick 215
OnCloseQuery 123
OnCreate 121
OnDeActivate 122
OnDrawColumnCell 215
OnKeyPress 82
OnNewRecord 249
OnPaint 122
OnResize 125
OnShow 122
OnTitleClick 215
Open 194
OpenDialog 143
Options 214, 265
Page 264
PAS 10, 120
277
PopupMenu 77, 151
Position 128
Post 244
Preview 267
PrinterSetting 264
PrintlfEmpty 265
QR 178
QRBand 264
QRDBText 274
QRExpr 274
QRlabel 274
QRShape 270
Query 200
QuickReport 262
SaveDialog 144
SaveToFile 88
ScrollBox 118
ScrollInView 129
SetFocus 84
Show 122
ShowMessage 140
ShowProgress 265
Size 76
Standard 67
StartTransaction 260
String 93
Table 191
Table 1 188
TableName 198, 208
TableType 199
278
TabOrder 77
TCloseQuery Event 123
TColorCircle 61
Text 77, 93
TForm 119
TFormStyle 125
TMenuItem 148
Top 76
TPosition 128
TStrings 85
TWinControl 70
31
"-"
Value 208
VCL 65 70
Visible 209. .
VisibleButtons 222
W
Width 76
Win32 69
160
157
159
160
157
65, 70
- 170
, 84
27
145
42
42
44
45
167
148, 150
163, 200
116
64
205
71
153
:
2, 190, 204
197, 208
274
181
161
246
241
213
211
249
SQL 201
32
:
199, 210
168
185
:
199
183
180, 208
198
164
182
174
5
19
2 210
275
168
60
163, 181, 200
163, 200
105
108
105
275
100
36
:
211
190
270
64
152
115
151
190
40
148
63
169
93
41
158
279
117
28
205
61
34
35
:
170
184
90
:
8
7
8
8
70
37, 47
50
49
53
48
47
49
49
49
51
96
180
134
143
167
262
264
267
7
116
:
183
15
185
163
163
280
110
113
11:
54
58
167
237
239
237
161 205
197
268
129
62
185
178
158
272
98
56
186
148
180
17
206
195,210
192
63, 71
250
166
213
157
64, 79
:
187
179
64
225
10
193
144
98
165
30
Delphi 5, 31, 67, 85, 105, 119,
148, 157, 190, 225, 262
184
142
206
40
160
199
:
268
180, 209
171, 199
36
39
39
38
39
38
40
38
169. 260
154
228
50
:
14
11
15
144
232
232
281
2 119
123
125
136
122
. .
123
122
128
:
dBase 171
Paradox 171
57
24
29
146
185
1600
- w w w . c o m p u t e r b o o k . r u
ComputeiBQOK.ru - Miciosofl Internet Exploiei
. ' - f i * f
-
Snepef-
"Q - . - 0
)
@ @ Mail.ru
| - - > >
-
V
2 0
.,
-
Compnieibookro
'
M i c r o s o f t Office XP
: 1636
: 11
: 1
"-"
Web-. XML
"-"
Copyright computeifaook..2001