(. 44) Internet.
. 44. Internet
Delphi - , . Data Access. .
DataControls , Windows, .
QReport , .
Windows-
Delphi 3 , , Windows- (. 45).
. 45. Dialogs
:
TOpenDialog .
TSaveDialog .
TFontDialog .
TColorDialog .
TPrintDialog .
TPrinterSetupDialog .
TFindDialog .
TReplaceDialog .
TOpenPictureDialog .
TSavePictureDialog .
:
, - . . Execute. Execute . . , , , . Execute . Execute, , .
,
Procedure TForm1.Button1Click(Sender: Tbject);
Begin
If ColorDialog1.Execute then
Form1.Color:= ColorDialog1.Color;
End;
(. 46), , , Color .
TOpenDialog (. 47) TSaveDialog .
FileName . . Filter , . . , | , . .TXT,
|
|
Filter:= *.TXT;
Filter:= |.TXT|DOC-|.DOC|Wri-|*.WRI;
InitialDir.
. OpenDialog, Button Memo. .
.
Prcedure TForm1.Button1Click(Sender:TObject);
Var S: String; F: TextFile;
Begin
OpenDialog1.Filter:= |*.TXT| |*.PAS;
If OpenDialog1.Execute and FileExists(OpenDialog1.FileName) Then
Begin
AssignFile(F, OpenDialog1.FileName);
Reset(F);
Memo1.Lines.Clear;
While not EOF(f) Do
Begin
ReadLn(F, S);
Memo1.Lines.Add(S)
End;
CloseFile(F)
End;
End;
FontDialog (. 48) Device, . : fdScreen , fdPrinter , fdBoth .
, .
Procedure TForm1.Button1Click(Sender: TObject);
Var FontName: TFont;
Begin
FontDialog1.Device:= fdPrinter;
FontDialog1.Execute;
FontName:= FontDialog1.Font;
End;
ActiveX
ActiveX Delphi. Delphi OLE.
. , . TStrings TStringList. VCL TCombobox, TList, TDBComboBox . (Temo, TStringGrid) . , TList. , , Tollection TllectionItem.
TStrings , , . TPersistent.
, :
Strings [Index: Integer]: String;
:
|
|
SomeStrings.Strings[i]:= Edit1.Text; SomeStrings [i]:= Edit1.Text
.
Objects [Index: Integer]: TObject
, . , , , .. :
TSityProps = Class (TObject)
Square: LongInt;
Population: LongInt;
Status: String;
End;
AddObject, :
SomeStrings.AddObject (SomeItem, TSityProps.Create);
. .
TStrings , TStringList, .
TSringList . , .
Strings, Text CommaText. . .
Add Insert. , .
. AddStrings Assign. .
AddObject. , , Object.
, :
IndexOf ;
IndexOfName ;
IndexOfObject .
Sorted Sort.
. LoadFromFile LoadFromStream. SaveToFile SaveToStream.
. , . . . , : , , -, . , , .
. 49. ,
:
TainMenu, , , N1, N2, N3. Edit1... Edit4 . Edit5 . Bitbtn1 BitBtn2 . OpenDialog1 SaveDialog1.
:
Type TTovar = Class // .
Name, Cost, Country, Volume: String[20];
Constructor Create (a: String);
End; // .
var
Form1: TForm1; Num, Numk: Integer;
List1: TStringList; Tovar: TTovar;
:
|
|
Constructor TTovar.Create;
Begin
Inherited Create;
Name:= a;
End;
:
Procedure Mem;
Begin
List1.add(IntToStr(Num));
Tovar:= TTovar.Create( ); //
List1.Objects[Num]:= Tovar;
End;
:
procedure TForm1.FormCreate(Sender: TObject);
begin
List1:=TStringList.Create; //
Num:= 0; Mem; Edit5.Text:= 0; // 0-
end;
procedure TForm1. BitBtn1Click (Sender: TObject);
Begin
Edit5.Text:= IntTostr(Num);
With List1.Objects[Num] as TTovar do
Begin //
Name:= edit1.text;
Cost:= edit2.text;
Country:= edit3.Text;
Volume:= edit4.text;
End;
If (Sender AS TBitBtn).Name = BitBtn1Then
Begin //
If Num = 0 Then exit;
Num:= Num - 1;
End;
If (Sender AS TBitBtn).Name = BitBtn2 Then
Begin //
Num:= Num + 1;
If Num > List1.Count Then Mem;
End;
//
With List1.Objects [Num] as TTovar do
Begin
edit1.text:= Name;
edit2.text:= Cost;
edit3.Text:= Country;
edit4.text:= Volume;
End;
End;
// .
procedure TForm1.N1Click(Sender: TObject);
Var F: TextFile;
begin
Try
With OpenDialog1 Do
Begin
If Not Execute Then Exit;
List1.LoadFromFile (FileName); //
// Tovar.
AssignFile(F,Copy(FileName,1,Length(FileName)-4)+.o);
Reset(F);
Num:= 0
While Not Eof(F) Do // Tovar
With List1 Do
Begin
If List1.Objects[Num] = Nil Then
Begin
Tovar:= TTovar.Create( );
List1.Objects[Num]:= Tovar;
End;
Readln(F,(Objects[Num] AS TTovar).Name);
Readln(F,(Objects[Num] AS TTovar).Cost);
Readln(F,(Objects[Num] AS TTovar).Country);
Readln(F,(Objects[Num] AS TTovar).Volume);
Inc(Num);
End;
CloseFile(F);
End;
Except
ShowMessage( );
End;
Num:= 0; //
With List1.Objects [Num] as TTovar do
Begin
edit1.text:= Name;
edit2.text:= Cost;
edit3.Text:= Country;
edit4.text:= Volume;
End;
Edit5.Text:= IntToStr(Num);
end;
// .
procedure TForm1.N2Click(Sender: TObject);
Var F: TextFile; i: Integer;
begin
Try
With SaveDialog1, List1 Do
Begin
If Not Execute Then Exit;
SaveToFile (FileName); //
AssignFile(F,Copy(FileName,1,Length(FileName)-4)+.o);
Rewrite(F);
For i:= 0 To Count - 1 Do //
Begin
If Objects[i] <> Nil Then
Writeln(F,(Objects[i] AS TTovar).Name);
Writeln(F,(Objects[i] AS TTovar).Cost);
Writeln(F,(Objects[i] AS TTovar).Country);
Writeln(F,(Objects[i] AS TTovar).Volume);
End;
CloseFile(F);
End;
Except
ShowMessage( );
End;
End;
Tovar . Name.
BitBtn1Click , Edit , . BitBtn1Click , BitBtn1 BitBtn2. Sender.
SaveToFile LoadFromFile. .ooo.
|
|
TList . ,
Items [Index: Integer]: Pointer;
Itemindex .
TList .
Add (Item: Point): Integer;
, Add, .
.
Insert (Index: Integer; Item: Pointer);
, Index1 Index2:
Exchange (Index1, Index2);
. ,
Delete (Index: Integer);
,
Remove (Item: Pointer): Integer;
TList Delphi.
, . Tollection. , TollectionItem. . , ToolBar . ToolBands, , Tollection. ToolBar, TollectionItem.
VCL Delphi - GUI (Graphic User Interface), .
Tanvas
Tanvas . , (, , ) .
, , - . , , .
Canvas VCL .
, :
Font: TFont;
Pen: TPen;
Brush: TBrush.
, : Pixels [X, Y: Integer]: Tolor.
. . Y .
PenPos: TPoint .
. :
Arc (X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer) (X1, Y1) (X2, Y2).
Ellipse(X1, Y1, X2, Y2: Integer) (X1, Y1) (X2, Y2).
LineTo (X, Y: Integer) (X, Y).
FrameRect (const Rect: TRect) Rect 1 .
MoveTo (X, Y: Integer) (X, Y) .
Polygon (Points: array of TPoint) , Points.
Rectangle (X1, Y1, X2, Y2: Integer) (X1, Y1) (X2, Y2).
FloodFill (X, Y,: Integer; Color: TColor; FillStyle: TFillStyle) .
TextOut (X, Y: Integer; const Text: String) Text , , , (X, Y).
Draw (X, Y: Integer; Graphic: TGraphic) Graphic.
StretchDraw (const Rect: TRect: Graphic: TGraphic) Graphic Rect. , Graphic .
|
|
CopyRect (Dest: TRect; Canvas: TCanvas; Source: TRect); Source Canvas Dest .
, . 51.
. 51. Canvas
:
procedure TForm1.Button1Click(Sender: TObject);
const pi = 3.14159;
Var x, y: Real; px, py, offset, halfheight: LongInt;
begin
//
halfheight:= Form1.Height div 2;
offset:=0;
For offset:= -10 To 10 Do
Begin
px:= 0;
While px < Form1.Width Do
Begin
// 2 ,
//
x:= px * (2 * pi/Form1.Width);
y:= Sin(x);
py:= Trunc(0.7 * y * halfheight) + halfheight + (offset * 10);
If (px = 0) Then Canvas.LineTo (px, py);
Canvas.LineTo (px, py);
py:= Trunc(0.7 * y * halfheight) + halfheight + ((offset-1) * 10);
Canvas.LineTo (px, py);
px:= px +15;
End;
End;
end;
TFont
- .
Color: TColor .
Size: Integer (1/72 ).
Style: TFontStyles . fsBold , fsItalic , fsUnderline , fsStrikeOut .
. - , FontDialog.
TFont:
Var F: TFont;
Begin
F:= TFont.Create;
With F Do
Begin
Name:= Arial; Height:= 40;
Color:= clBlue; Size:= 40;
Style:= [fsBold];
End;
Canvas.Font:= F;
Canvas.TextOut(10, 10, );
F.Free;
End;
TPen
. . TPen :
Color: TColor ;
Style: TPenStyle (psSolid , psDash ..);
Width: Integer ;
Mode: TPenMode ( TPenMode . Delphi).
TBrush
.
:
Bitmap: TBitmap , ;
Color: Tolor ;
Style: TrushStyle (bsSolid , bsBDiagonal , bsCross , bsVertical . ).
TaintBox:
procedure TForm1.Button1Click(Sender: TObject);
Var w, h: Integer;
begin
With PaintBox1 Do
Begin
W:=Width Div 6; h:= Height Div 6;
Canvas.Brush.Style:= bsCross;
Canvas.Pen.Color:=clBlue;
Canvas.Ellipse(w, h, 5 * w, 5 * h);
End;
end;