edu.semgu.kzedu.semgu.kz/ebook/umkd/32f81a2e-08d7-11e7-bfa7-a6…  · web view- өзінде...

342
ҚАЗАҚСТАН РЕСПУБЛИКАСЫ БІЛІМ ЖӘНЕ ҒЫЛЫМ МИНИСТРЛІГІ СЕМЕЙ қаласы ШӘКӘРІМ атындағы МЕМЛЕКЕТТІК УНИВЕРСИТЕТІ СМЖ 3 деңгейдегі құжаты ПОӘК ПОӘК 042- 39.1.35/01-2014 ПОӘК «Delphi-де программалау» пәні бойынша оқу- әдістемелік материалдар 03.09.2014ж №1 басылым ПӘННІҢ ОҚУ-ӘДІСТЕМЕЛІК КЕШЕНІ «Delphi-де программалау» 5В060200 - «Информатика» мамандығына арналған ОҚУ-ӘДІСТЕМЕЛІК МАТЕРИАЛДАР

Upload: buinhan

Post on 30-Jan-2018

266 views

Category:

Documents


9 download

TRANSCRIPT

042-39.1.31/01-2014

03.09.2014 . 1

148148

3

042-39.1.35/01-2014

Delphi- -

03.09.2014

1

-

Delphi-

5060200 -

-

2014

1.

: .. , 2. 2.1

1, 10 2014 .

_________________ .. ..

2.2. - - .

1, 11 2014 .

__________ ..

3.

- , .

1, 11 2014 .

___________ ..

4.

1.

2.

3.

4.

5.

() - , , .

, - .

.

- , .

- .

- .

- , .

- , .

- Delphi - .

- , .

(, ) . .

- .

- .

. .

Uses - ; - - . .

. . , .

Implementation - . . a , . - , , .

. Uses . Initalisation . .

, .

- .

2

1.DELPHI-

1.1 Delphi

Delphi IDE (Integrated Development Environment) . - . IDE , , . , , IDE .

Delphi- . :

(Delphi7-Project1.dpr)

i (ObjectTreeView)

(ObjectInspector)

c (Form1.dfm)

(Unit1.pas)

(ExploringUnit.pas)

. ( - Form1).

. . - . , . :

Standard

Additional-

Win32- Windows- 32 System -

Data Access-

Data ontrols- ...

.

:

.

, .

: Label1.Caption:=Delphi;

. .

:Label1.Font.Color:=clRed;Label1 .

:

1. .

2. .

.

:

Properties () Events ().

(, ) - , .

. . : Standard (Button) (Label) , Form1, Button1, Label1 . ( 1). Caption ( 1).

)

)

1.Label, Button Delphi

.

Name (Tcomponent Name ) . . : Form1, Form2, Button1, Edit2, Label1 ...

Caption (Tcaption ) . (String) . : Button1. Caption:= ; Form1.Caption:=';

Text (Tcaption ) . . :Edit1.text:=; Memo1.Text:='';

Enabled (Boolean ) . true () , , false ( ) , . : Edit1.Enabled:=false; Button1.Enabled:=false; Edit1- Button1 .

Color (Tcolor ) . : clRed (), clAqua (- ), clBlue (), clGreen (), clYellow (), clWhite (), clFuchcia () ..

: Edit1.Color:=clLime;

Edit1.Font.Color:=clMaroon; , () .

Visible (Boolean ) . true , , .

: Edit1.Visible:=false; Button1.Visible:=true;

Font (TFont ) .TFont .

Name (TFontName ) . : Label1.Font.Name:=Arial; Edit1.Font.Name:=KZ Decor;

Size (Integer ) .

Height (Integer) . : Label1.Font.Size:=18;

Color (Tolor ) . : Label1.Font.Color:=clRed;

Style (TFontStyle ) .

fsItalic - ()

fsBold ()

fsUnderline - ()

fsStrikeOut - ()

:Label1.Font.Style:=[fsBold];Edit1.Font.Style:=[fsBold, fsItalic];

:

1. Delphi ?

2. ?

3. Delphi ?

4. , .

5. ?

6. ?

7. ?

8. LabelEdit , , ?

9. ?

2.

Delphi . :

(.dpr)

(.dfm)

(.pas)

(.pas)

(.dof)

(.res)

Project1.dpr . Form1 . . 1 :

Program Project1;

usesForms,

Unit1in'Unit1.pas'{Form1};

{$R*.res}

begin

Application.Initialize;

Application.CreateForm(TForm1,Form1);

Application.Run;

end.

: View UnitsProject1( CTRL+F12).

(.dfm) (.pas) .

. , . View as Text . , View as Form .

: (Button) (Edit) :

objectForm1:TForm1

Left=192

Top=114

Width=696

Height=480

Caption='Form1'

Color=clBtnFace

Font.Charset=DEFAULT_CHARSET

Font.Color=clWindowText

Font.Height=-11

Font.Name='MSSansSerif'

Font.Style=[]

OldCreateOrder=False

PixelsPerInch=96

TextHeight=13

objectButton1:TButton

Left=40

Top=80

Width=89

Height=33

Caption='Button1'

TabOrder=0

end

objectEdit1:TEdit

Left=40

Top=24

Width=81

Height=21

TabOrder=1

Text='Edit1'

end

end

. :

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm1=class(TForm)

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1:TForm1;

implementation

{ $R*.dfm }

end.

: View Units Unit1 ( CTRL+F12).

() .

- . Events . On . .

3.Events

Delphi- :

OnClick-

OnDblClick- OnCreat-

OnKeyPress ..

:

Procedure (Sender : TObject);

Begin

end;

4.

: Delphi :

procedureTForm1.Button1Click(Sender:TObject);

begin

Edit1.Text:='Delphi '

end;

5.

:

1. Delphi - ? ?

2. ? ?

3. ? ?

4. ?

5. ? ? Delphi- ?

6. Delphi- ?

7. Sender:TObject ?

3. Delphi .

unit , . Unit1, Unit2 .. . : interface implementation . Interface uses .

:

Uses,,;

:

interface

uses

Windows,Messages,SysUtils,Variants,Classes,Graphic,Controls,Forms,

Dialogs,StdCtrls;

SysUtils.

IntToStr (Value:Integer): String;-Value.

StrToInt (const S: String) : Integer;- S.

FloatToStr (Value:Extended) : String Value.

StrToFloat (const S: String) : Extended; S

DateToStr(Date:TDateTime) : String;- Date.

TimeToStr(Time:TDateTime) : String;-Time.

StrToDate (const S: String ) : TdateTime;- S.

StrToTime (const S: String ) : TdateTime;- S.

:Edit ( 6).

6.

BitBtn1:

procedure TForm1.BitBtn1Click(Sender:TObject);

begin

Edit3.Text:=IntToStr(StrToInt(Edit1.Text)+StrToInt(Edit2.Text));

end;

Edit, Edit1, Edit2, . Edit3 , , .

7.

Delphi-.Random(). . Randomize.

[a,b] : Random(b-a)+a;

: [10,50] : random(40)+10;

:..

8.

Edit1 Edit2 1- 100- BitBtn1 :

procedureTForm1.BitBtn1Click(Sender:TObject);

begin

randomize; Edit1.Text:=IntToStr(random(100)); Edit2.Text:=IntToStr(random(100)); end;

BitBtn21-.

:

1. ?

2. ?

3. SysUtils?

4. Label.

5. ?

6. Edit?

DELPHI- ( 2)

4. Standard..

Standard Windows .

9. Standard

STANDARD:

Frame ,

MainMenu

PopurMenu

Label - . .

Edit 1

Memo

Button

CheckBox -

RadioButton -

ListBox

ComboBox

ScrollBar

GroupBox

RadioGroup

Panel

ActionList

, Edit. - Text.

Label. - Caption.

.

:, (10- )

10.

:

procedureTForm1.Button1Click(Sender:TObject);begin edit2.Text:=FloatToStr(StrToFloat(edit1.Text)/1024); edit3.Text:=FloatToStr(StrToFloat(edit2.Text)/1024); edit4.Text:=FloatToStr(StrToFloat(edit3.Text)/1024); end;

:. .

11.

(12-13 ):

var s:string; Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin

s:= FloatToStr(StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/(4*pi));

ShowMessage('='+ s); end;

end.

C 12.

13.

Delphi , .

1.

.

InputBox() . .

: :=InputBox(,,);

:

String

: .

. procedureTForm1.Button1Click(Sender:TObject);

vars:string;

begin

s:=InputBox('-','','0');

label1.caption:=floatTostr(strTofloat(s)/1024);

end;

, , label1.

14.

:y=(3x+5)/3 . InputBox() , ShowMessage() .

Procedure TForm1.FormCreate(Sender:TObject);

Var x, y:real; S:string;

begin

s:=InputBox(-,=,0);

x:=StrToFloat(s);

y:=(3*x+5)/3; ShowMessage(FloatToStr(y));

end.

. - 4,8 ,- 6,46666- .

15.InputBox()

16.ShowMessage()

2.

ShowMessage() MessageDlg() .

ShowMessage .

: ShowMessage();

:ShowMessage();

Project . Project\Options\Application|Title.

MessageDlg().. :

:= MessageDlg(,,, );

:

. , , . .

MessageDlg() .

(MtWarning()MtError()MtInformation ()MtConfirmation()MtCustom) 1. MessageDlg()

:.

procedureTForm1.Button3Click(Sender:TObject);

Varr:integer;

begin

r:=MessageDlg('

',mtWarning,[mbOk,mbCancel],0);

end;

17.MessageDlg ()

:

mbOk,mbCancel,mbYes,mbNo,mbAbort,mbRetry,mbIgnore,mbAll,mbHelp.

:

1. ?

2. ?

3. ?

4. ShowMessage?

5. ShowMessage?

6. ?

7. InputBox(), MessageDlg() ?

8. Edit?

9. LabelEdit?

5. .

Object Pascal . :

IfThenElse

: If (x>=0) and (xm then k:=k-m else m:=m-k;

edit3.Text:=inttostr(k);

edit4.Text:=inttostr(trunc(n/k));

end; end.

. , n h = 1 y = x ^ n . 2 Listbox . (34 - )

28.

var n,a,b,x,y:integer;

Form1: TForm1;

implementation

{ $R *.dfm }

procedure TForm1.BitBtn1Click(Sender:TObject);

begin

n:=strtoint(edit1.text);

a:=strtoint(edit2.text);

b:=strtoint(edit3.text);

for x:=a to b do begin

y:=trunc(exp(n*ln(x)));

listbox1.Items.add(inttostr(x));

listbox2.Items.add(inttostr(y));

end;

end;

end.

:

1. Object Pascal?

2. ?

3. ListBoxComboBox?

4. ?

5. Items?

6. ItemIndex?

7. Object Pascal ?

8. ?

9. ?

10. Break Continue ?

11. Trunc ?

12. listbox1 ?

III.DELPHI- ADDITIONAL

7. Additional.BitBtnSpeedButton

Additional .

29.Additional

BitBtn .

SpeedButton .

MaskEdit . .

StringGrid . .

DrawGrid - ( )

Image . , .

Bevel . .

ScrollBox . , .

CheckListBox ( heckBox ).

Srlitter . .

StaticText , Label - Windows . .

Application-Events , Windows- .

Chart . .

Standard Button , . Additional Bitbtn . - . Caption .

Bitbtn Kind . -bkCustom. : bkOK,bkCancel,bkHelp,bkYes,bkNo,bkClose,bkAbort,bkRetry,bkIgnore,bkAll. (30-).

Glyph . Glyph . Load , *.bmp . Delphi- .

\programfiles\commonfiles\borlandshared\Images\Buttons .

- - OnClick. .

30. Bitbtn Kind

. , Edit , (31)

31.

:

procedure TForm1.BitBtn1Click(Sender:TObject);

begin

Edit1.Text:=TimeToStr(Time);

end;

procedure TForm1.BitBtn2Click(Sender:TObject);

begin

Edit2.Text:=DateToStr(Date);

end;

procedure TForm1.BitBtn3Click(Sender:TObject);

begin

Edit3.CutToClipboard;

end;

procedure TForm1.BitBtn4Click(Sender:TObject);

begin

Edit3.CopyToClipboard;

end;

procedure TForm1.BitBtn5Click(Sender:TObject);

begin

Edit3.PasteFromClipboard;

end;

SpeedButton

Delphi - 3 :

Button ;

BitBtn - ;

SpeedButton .

SpeedButton BitBtn . TGraphicControl .

. SpeedButton . 3- . Boolean Down . true , , .

: Speedbutton1.down:=true;

SpeedButton . , . Integer GroupIndex . 0 . GroupIndex . , , .

: MS Word ( , , )

GroupIndex . : GroupIndex=5

4 . .

1 . GroupIndex .

: MS Word ( , )

GroupIndex=1, GroupIndex=2, GroupIndex=3.

.

SpeedButton Boolean AllowAllUp . AllowAllUp=true , . SpeedButton BitBtn 3 , 4 . , NumGlyph 4-.

SpeedButtonBooleanflattrue, , .

Caption, Glyph.

: (, ) 3SpeedButton, RichEdit1 (32- ).

32.

SpeedButton1, SpeedButton2, SpeedButton3 , :

SpeedButton1.GroupIndex:=1;

SpeedButton2.GroupIndex:=2;

SpeedButton3.GroupIndex:=3;

SpeedButton1.AllowAllUp:=true;

SpeedButton2. AllowAllUp:=true;

SpeedButton3. AllowAllUp:=true;

3 :

procedureTForm1.SpeedButton1Click(Sender:TObject);

begin

ifSpeedButton1.Down=trueThen

RichEdit1.SelAttributes.Style:=[fsBold]

ElseRichEdit1.SelAttributes.Style:=[];

end;

procedureTForm1.SpeedButton2Click(Sender:TObject);

begin

ifSpeedButton2.Down=truethen

RichEdit1.SelAttributes.Style:=[fsItalic]

ElseRichEdit1.SelAttributes.Style:=[];

end;

procedureTForm1.SpeedButton3Click(Sender:TObject);

begin

ifSpeedButton3.Down=truethen

RichEdit1.SelAttributes.Style:=[fsUnderLine]

ElseRichEdit1.SelAttributes.Style:=[];

end;

Delphi-

Delphi , . (: Adobe PhotoShop) :

1)

2)

3)

, jpg : 1.jpg- , 11.jpg , 111.jpg ( Height =65, Width =129) .

33.1.jpg

34. 11.jpg

35. 111.jpg

, Delphi (Height =65, Width =129) Image , Picture 1.jpg . Image (Image1MouseMove), (Image1MouseDown) (FormMouseMove) :.

Procedure

Form1.Image1MouseMove(Sender:TObject;Shift:TShiftState;X,Y:Integer);

begin

Image1.Picture.LoadFromFile('c:\11.jpg')

end;

procedureTForm1.Image1MouseDown(Sender:TObject;Button:TMouseButton;Shift:TShiftState;X,Y:Integer);

begin

Image1.Picture.LoadFromFile('c:\111.jpg');

end;

procedureTForm1.FormMouseMove(Sender:TObject;Shift:TShiftState;X,

Y:Integer);

begin

Image1.Picture.LoadFromFile('c:\1.jpg');

end;

:

1. Additional?

2. BitBtnButton?

3. 3. BitBtn?

4. Kind?

5. Kind?

6. Edit, ?

7. ?

8. SpeedButton?

9. Delphi ?

8. ShapeImage

Shape. . - Shape.:

StCircle-

StEllipse-

StRectangle-

StRoundRectangle

StSquare-

StRoundSquare

:Shape1.Shape:=StEllipse;Shape2.Shape:=StRectangle;

Pen().. :

Color- .

Width .

Style ..

psSolid

psDash

psDot

psDashDot

psDashDotDot

psClear .

: Shape1.Pen.Color:=clRed; Shape1.Pen.Width:=3;

Shape1.Pen.Style:=psDash;

Shape1.Shape:=stCircle;

3-,, .

Shape- Brush (). . Brush.

Color .

Style .:

bsSolid

bsHorizontal

bsVertical

bsFDiagonal,bsBDiagonal

bsCross-

bsDiagCross-

bsClear-.

(36- )

36.Shape

Image.:

AutoSizeImage.

Stretch, .

Center , Image.true,false.

Picture.LoadFromFileSaveToFile. :

procedure LoadFromFile(const FileName: string);

procedure SaveToFile(const FileName: string);

(:Image1.Picture.LoadFromFile(d:\4204\Zainyllin_Adilbek.bmp);)

37. Image

procedureTForm1.BitBtn1Click(Sender:TObject);

begin

Image1.Picture.LoadFromFile('c:\4204.bmp');

end;

:

1. ShapeShape?

2. Shape?

3. Pen, ?

4. Brush, ?

5. Image?

6. Image?

7. Image?

9. StringGrid

. Delphi-StringGrid. . longint ColCountRowCount, . 5 66 . . ,.integer FixedRowsFixedCol. 1 . . FixedColor. Color. OptionsgoEditingtrue. StringCells[ACol,ARow:integer]. Aol,ARow. .

!StringGrid 0-.

: Label1.Caption:=StringGrid1.Cells[5,9];

StringGrid1.Cells[1,2]:=Hello;

Label1StringGrid1 10- 3- 2- Hello .

: . :

FixedCols

0

FixedRows

1

Options\goEditing

true

38.StringGrid

:

ProcedureTForm1.BitBtn1Click(Sender:TObject);

begin

StringGrid1.Cells[0,0]:='-';

StringGrid1.Cells[1,0]:=''StringGrid1.Cells[2,0]:=''; StringGrid1.Cells[3,0]:=''; StringGrid1.Cells[4,0]:='';

end;

. (39-)

39.

:, . . (40- ).

40.

:.

vari, max, min, k, n:integer;

//

Form1: TForm1;

implementation

{ $R *.dfm }

procedure TForm1.BitBtn1Click(Sender:TObject);

begin

StringGrid1.Cells[0,0]:=''; StringGrid1.Cells[1,0]:=''; StringGrid1.Cells[2,0]:=''; StringGrid1.Cells[3,0]:='; StringGrid1.Cells[0,1]:=''; StringGrid1.Cells[0,2]:=''; StringGrid1.Cells[0,3]:=''; StringGrid1.Cells[0,4]:='';

end;

//

procedureTForm1.BitBtn2Click(Sender:TObject);

begin

For i:=1 to 4 do

StringGrid1.Cells[3,i]:=inttostr(strtoint(StringGrid1.Cells[1,i]) *strtoint(StringGrid1.Cells[2,i]));

max:=strtoint(StringGrid1.Cells[1,1]);

min:=strtoint(StringGrid1.Cells[1,1]);

k:=1;n:=1;

For i:=1 to 4 do

begin

If maxstrtoint(StringGrid1.Cells[1,i]) then begin

min:=strtoint(StringGrid1.Cells[1,i]);n:=i;end;

end;

Edit1.Text:=StringGrid1.Cells[0,k]; Edit2.Text:=StringGrid1.Cells[0,n];

end;

procedure TForm1.BitBtn3Click(Sender:TObject);

begin

ShowMessage('!')

end;end.

(41-)

41.

:

1. StringGridColCountRowCount?

2. ?

3. StringGridFixedRowsFixedCol ?

4. ?

5. ?

6. ?

10. Win32RichEdit,PageControlreeView

Win32 32 Windows 95/98/NT/2000 95/98/NT/2000 .

42.Win32

.

PageControl- .

RichEdit- .

TrackBar .

Animate- .

TreeView- ...

PageControl . (New Page) . Delphi TabSheet1,TabSheet2 . Caption .

:PageControl . ( 43 .)

43. PageControl

RichEdit .Memo RichEdit (RTF-RichTextFormat) . SelAttributes , . TTextAttributes Color (), Name ( ), Size (), Style () .. . , .. Paragraph . - Alignment. . : taLeftJustify (), taCenter ( ) taRightJustify ().

: RichEdit , , , , , , , (44)

44. RichEdit

:

Procedure TForm1.N2Click(Sender:TObject);

begin

RichEdit1.CutToClipboard;

end;

procedure TForm1.N3Click(Sender:TObject);

begin

RichEdit1.CopyToClipboard;

end;

procedure TForm1.N4Click(Sender:TObject);

begin

RichEdit1.PasteFromClipboard;

end;

procedure TForm1.BitBtn4Click(Sender:TObject);

begin

RichEdit1.SelAttributes.Style:=[fsBold]

end;

procedure TForm1.BitBtn5Click(Sender:TObject);

begin

RichEdit1.SelAttributes.Style:=[fsItalic]

end;

procedure TForm1.BitBtn6Click(Sender:TObject);

begin

RichEdit1.SelAttributes.Style:=[fsUnderLine]

end;

procedure TForm1.BitBtn1Click(Sender:TObject);

begin

RichEdit1.Paragraph.Alignment:=taLeftJustify;

end;

procedure TForm1.BitBtn2Click(Sender:TObject);

begin

RichEdit1.Paragraph.Alignment:=taCenter;

end;

procedure TForm1.BitBtn3Click(Sender:TObject);

begin

RichEdit1.Paragraph.Alignment:=taRightJustify;

end;

TreeView .. - Items.. TTreeNodes. TreeView 2 Items. 45.

45. TreeView

:

NewItem () - .

NewSubItem () - .

Delete () - .

Text -.

1: 46- 2 TreeView . 3 .

46. TreeView

Label1Text. 2: Label1. caption:= TreeView1.Items.Item[1].text; Label1 MS Word . -Label1-: Label1.caption:=TreeView1.Selected.text;

bsoluteIndex. 0- . : 1-. - MS Word , rtf. , RichEditrtf(47 -).

47. TreeView

Procedure TForm1.TreeView1Change(Sender:TObject;Node:TTreeNode);

begin

case treeView1.Selected.AbsoluteIndex of

1: RichEdit1.lines.LoadFromFile('c:\Word.rtf');

2: RichEdit1.lines.LoadFromFile('c:\Excel.rtf');

3: RichEdit1.lines.LoadFromFile('c:\Access.rtf');

end;

end;

:

1. Win32?

2. RichEditMemo?

3. SelAttributes?

4. RichEditParagraph?

5. PageControl?

6. PageControl?

7. reeView?

8. reeView?

9. reeView?

11. Delphi Animate MediaPlayer

Windows., . -., , , . .

Delphi 2 :

Animate .

MediaPlayer ., , , . (MediaPlayer .)

AnimateWin32Animate AVI (Audio-Video Interleaved- ) .

48.Animate

Animate. .

:

Name

FileName

StartFrame

StopFrame.

Activate.

Active true , .

Color

Transparent.

Repetitions.

Play,

Stop.

Animate AVI .

AVI :

64 .

:Windows Clock.avi .Win32Animate, FileName c:\Windows\clock.avi Activetrue.

49. Clock.avi

:Animate*.avi.

50.

ProcedureTForm1.BitBtn1Click(Sender:TObject);

begin

animate1.FileName:='c:\777.avi';

animate1.Active:=true

end;

procedureTForm1.BitBtn2Click(Sender:TObject);

begin

animate1.Stop

end;

AnimateWindows () . CommonAVI :

aviNone

aviCopyFile

aviCopyFiles

aviDeleteFile

aviEmptyRecycle

aviFindComputer

aviFindFile

aviFindFolder

aviRecycleFile

:Windows.

Animate, RadioGroup , Caption , Items 9 .

:

Const :.

ConstAviType:array[0..8]ofcommonAvi=(aviNone,aviCopyFile,aviCopyFiles,

aviDeleteFile,aviEmptyRecycle,

aviFindComputer,aviFindFile,aviFindFolder,

aviRecycleFile);

Const CommonAVI Label RadioGroup onClick.

ProcedureTForm1.RadioGroup1Click(Sender:TObject);

Begin

Animate1.CommonAVI:=aviType[RadioGroup1.Itemindex];

Label1.Caption:=RadioGroup1.Items[RadioGroup1.ItemIndex];

end;

:

ProcedureTForm1.Button1Click(Sender:TObject);

begin

Animate1.Play(1,animate1.FrameCount,0);

end;

procedureTForm1.Button2Click(Sender:TObject);

begin

Animate1.Stop

end;

51. Windows

RadioGroup . . Caption . Items . Columns . ItemIndex . . Windows- , RadioGroup1Click .

MediaPlayer

System MediaPlayer . , .

52. MediaPlayer

MediaPlayer . .

2. MediaPlayer

/

BtPlay

BtPause

BtStop

BtNext

BtPrev

BtStep

BtBack

BtRecord

BtEject

CD .

MediaPlayer:

Name . .

DeviceType.MediaPlayer.

FileName.

AutoOpen, .

Display . (Panel)

VisibleButtons. . .

MediaPlayer.

:MediaPlayer,Panel .MediaPlayer,:

AutoOpen=true;Display=Panel1;

FileName= \\

53. Panel MediaPlayer

54.MediaPlayer

55. MediaPlayer

(54-)MediaPlayer.

MediaPlayer *.wav .

:

1. ?

2. ?

3. Animate?

4. Animate?

5. MediaPlayerAnimat?

6. MediaPlayer?

7. MediaPlayer?

8. ?

9. MediaPlayer?

12

SYSTEM. Timer

System Windows DDE(DinamicDataExchange) OLE(ObjectLinkingandEmbedding) , .. .

55. System

Timer . .

PaintBox - . .

MediaPlayer (CD Rom,MIDI...).

OleContainer OLE- ().

MediaPlayer .Timer. . : , , , ... . :

Interval-.. . OnTimer.

:TimerInterval5000 , OnTimerClose , 5 .

Enabled . true , Timer .

Interval=0 Enabled=false , .Timer .

.5 10 .

: 2 , Interval 5000- , 10000- , Timer1,Timer2 OnTimer .

ProcedureTForm1.Timer1Timer(Sender:TObject);

begin

Edit1.Text:=DateToStr(now);

end;

procedureTForm1.Timer2Timer(Sender:TObject);

begin

Edit2.Text:=TimeToStr(now);

end;

56. Timer

. Edit , 10 .

:Interval 10000 , .

57.

OnClick Timer OnTimer.

ProcedureTForm1.BitBtn1Click(Sender:TObject);

begin

Timer1.Enabled:=true;

Edit1.Enabled:=true; Label3.Caption:='';

end;

procedureTForm1.Timer1Timer(Sender:TObject);

var k:integer;

begin

k:=length(edit1.Text); Timer1.Enabled:=false;

Edit1.Enabled:=false;

Label3.Caption:='10-'+inttostr(k)+' '

end;

.

58.

:

1. Timer?

2. TimerInterval?

3. TimerEnabled, ?

4. ?

5. ?

13. PaintBoxOLEContainer

PaintBox - . Canvas , Pen, Brush, Font , OnPaint . :PaintBox1OnPaint PaintBox1 .

ProcedureTForm1.PaintBox1Paint(Sender:TObject);

Varx,y:integer;

begin

WithPaintBox1.Canvasdo

Begin

Brush.Color:=clRed;

Ellipse(0,0,Width,Height);

Font.Name:='Arial';

Font.Size:=Heightdiv5;

Font.Style:=[fsBold,fsItalic];

Font.Color:=clWhite;

x:=(Width - TextWidth(''))div2;

y:=(Height - TextHeight(''))div2;

TextOut(x,y,'')

end;

end;

59.PaintBox1

OLEContainer OLE . (OLE- Object Linking and Embedding )

(, , , ..) Delphi . OLE ( 2 ) . OLE , .

OLE Paint, NotePad, MS Word, MS Excel .. .

:OleContainer1.CreatObjectFromFile(constFileName:String,Iconic:Boolean);

:

1-

2 - true,false. false, , true, .

: OleContainer1.CreatObjectFromFile(c:\4407.doc,false);

true , W.

3 -:

3. OleContainer

AllowInPlace

OLE- . true Icon= false , , Icon .

CanPaste

Boolean . OLE , true .

Iconic

Boolean . OLE- , true false , .

Close

Copy

LoadFromFile(const FileName:String)

FileName

SaveToFile(const FileName:String)

FileName

Run

,

OnActivate

OnDeactivate

: Delphi MS Word . System OleContainer 2 .

:

ProcedureTForm1.Button1Click(Sender:TObject);

Begin

OleContainer1.CreatObjectFromFile(c:\111.doc,false);

end;

OleContainer1 MS Word . . MS Word . ESC . , .

:

Procedure TForm1.Button1Click(Sender:TObject);

begin

OleContainer1.DestroyObject;

end;

:

1. Timer?

2. Timer-Interval?

3. Timer-Enabled, ?

4. ?

5. ?

6. PaintBox?

7. OleContainer1, , ?

VI.DELPHI

14. Delphi-

. . .

DataAccess . .

- Data Access TTable .

Properties Table1 DatabaseName ( ) .

Table1 . TableName .

, Active true .

Data Access DataSource ( ) . .

4. DataSource

AutoEdit

Boolean

. True, .

DataSet

TDataSet

Enabled

Boolean

Name

. DataSource1, DataSource2.

Tag

LongInt

.

: DataSource1.DataSet:=Table1;

Dataontrols ( ) . . DataControls DBGrid . , .

60.DBGrid

DBNavigator , , . .

61.DBNavigator

VisibleButtons .

62. Delphi DBGrid,DataSource,DBNavigator

BDE Borland BorlandDataBaseEngine . Paradox Dbase . . Paradox .

D(ActiveDataObject) Microsoft .

Delphi- MSAccess

MS Access 1 Baza1.mdb Delphi . .

I. Delphi ADO ADOonnection . ConnectionString 2 . 2 :

UseDataLinkFile ( ) UseConnectionString ( )

63. ConnectionString

, Build . Provider () ADO MS Office Microsoft Jet4.0 OLE DB Provider . MS Access .

64.

Connection() ( Baza1.mdb) , . , . ADOonnection LoginPrompt false . Connected true . .

II. MS Access Baza1.mdb 1 Delphi ADO ADOTable , :

ADOTable1. Name:=ADOTable1;

ADOTable1. Connection:=ADOConnection1;

ADOTable1. TableName:=1;

, TableName. ADOTable1. Active:=true;

III. DataAccessDataSource. DataSetADOTable1 .

IV. DataControls DBGrid . - . , .

. DBGrid1 DataSource DataSource1 .

65. MSAccess Delphi

1 DBGrid1 . , .

:

1. Delphi - ?

2. DataAccessDataControls?

3. Table?

4. DataSource?

5. DBGrid?

6. DBNavigator ,.

7. BDEBDE?

8. DD?

9. Delphi -MSAccess ?

VII.DELPHI

15.

Delphi

Delphi- Canvas (, - ) . . . . Height Width . .

( ) . . MoveTo(x,y:integer) . (,) , . (,) LineTo(x,y:integer) .

Delphi :

Arc(x1,y1,x2,y2,x3,y3,x4,y4:integer)-

Chord(x1,y1,x2,y2,x3,y3,x4,y4:integer)-

Ellipse(x1,y1,x2,y2:integer)-

Rectangle(x1,y1,x2,y2:integer)-

Pie(x1,y1,x2,y2,x3,y3,x4,y4:integer)- ...

Arc,Chord,Ellipse x1 y1 , , , x2 y2- . x3 y3, x4 y4 .

Delphi : Tcanvas- , Tfont- ,Tpen- ,Tbrush- .

I.Pen . :

Color- , Width- , Style- .

.

psSolid-

psDash-

psDot-

psDashDot -

psDashDotDot-

psClear- .

:

Canvas.pen.Width:=1;

Canvas.Pen.Color:=clRed;

Canvas.Pen.Style:=psDash;

Canvas.Ellipse(30,30,120,120);

1,, . .

.

66.Delphi

Canvas , With () . :

WithCanvasdobegin

Pen.Color:=clRed;

Pen.Width:=1;

Pen.Style:=psDash;

Ellipse(30,30,120,120);

end;

II.Brush ()- , . Brush .

Color .

Style- .

:

bsSolid-

bsHorizontal-

bsVertical-

bsFDiagonal,bsBDiagonal-

bsCross-

bsDiagCross-

bsClear- .

: . (79 -)

ProcedureTform1.Button1Click(Sender:Tobject);

begin

WithCanvasdobegin

Pen.Color:=clRed;//1-

Pen.Style:=psSolid;

Brush.Color:=clgreen;

Brush.Style:=bsHorizontal;

Ellipse(5,5,60,60);

Brush.Color:=clRed;//2-

Brush.Style:=bsBDiagonal;

Rectangle(70,5,140,70);

Brush.Color:=clblack; //3- Brush.Style:=bsSolid;

Ellipse(5,75,75,120);

Brush.Color:=claqua;//4-

Brush.Style:=bsVertical;

Chord(80,80,140,140,80,110,140,110);

end;end;

.

67.

III. ( )TextOut. :

TextOut(x,y:integer;constText:string);

() Canvas Font. :

Name . : Arial, Kz Decor, Times New Roman ...

Size . ()

Style. (: fsBold ,fsItalic-, fsUnderline )

Color.

: (68- ).

68.

procedureTForm1.Button1Click(Sender:TObject);

begin

withcanvasdobegin

Font.Name:='KZ Decor';

Font.Size:=18;

Font.Style:=[fsBold,FsItalic];

Font.Color:=clRed;

TextOut(10,10,'BORLAND DELPHI 7')

end;end;

. .

Delphi . Delphi- TCanvas . TCanvas .

propertyPen:TPen; ,

propertyBrush:TBrush; .

propertyClipRect:TRect; .

procedureFillRect(constRect:TRect); Brush ,Rect .

procedureMoveTo(x,y:integer); (,) .

procedureLineTo(x,y:integer); , (x, y) . Canvas .

: Delphi- y=sinx .

unit Unit1;

interface ...

implementation

{ $R *.dfm }

TypeTFunc=function(x:real):real;

procedure Graph(f:TFunc;a:real;b:real;:TCanvas);

var x, y, h: real; max, min: real; sx, sy: real; xmid, ymid: integer;

begin //

sx := (c.ClipRect.Right)/(b-a); h := 1/sx;

xmid := c.ClipRect.Right div 2; ymid := c.ClipRect.Bottom div 2; x := a;

max := f( x); min := max; //

while x=t do

begin

elem:=1/(2*n-1);

if n mod 2=0

then pi:=pi-elem

else pi:=pi+elem;

n:=n+1;

end;

pi:=pi*4;

label1.caption:=Pi=+FloatToStr(pi)+#13++IntToStr(n)+ ;

end;

end.

5.3 REPEAT

REPEAT WHILE .

:

Repeat

//

until

, .

:

1. repeat, until ;

2. . , ;

3. , .

, ( 5.4).

(> )

5.4 Repeat

- . .

( 5.5). 1 . 21 , 17 .

2-, 3- . , . n n .

5.5

5.4 Repeat

Unit simple_;

Interface

Uses

Windows, Messages, SysUtilis, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls;

type

TForm1=class(Tform)

Button1:TButton;

Label1:Tlabel;

Edit1:TEdit;

Label2:TLabel;

Procedure ButtonClick(Sender:TObject);

Private

{Private declarations}

public

{Public declarations}

End;

Var

Form1:TForm1;

Implementation

{$R *.DFM}

Procedure TForm1.ButtonClick(Sender:TObject);

Var

n:integer;

d:integer;

r:integer;

begin

n:=StrToInt(Edit1.text);

d:=2;

repeat

r:=n mod d;

if r0 then d:=d+1;

until r=0;

label2.caption:=Edit1.text;

if d=n then label2.caption:=label2.caption+- else label2.caption:=label2.caption+- ;

end;

end.

5.4 GOTO

f case . . . goto .

Goto :

Goto

, goto , .

Goto , label .

goto . .

5.5Goto

Procedure TForm1.ButtonClick(Sender:TObject);

Label

Bye;

Var

n:integer;

d:integer;

r:integer;

begin

n:=StrToInt(Edit1.text);

if n1000 then

begin

k:=Trunc(w/1000);

g:=Round(w-k*1000);

end

else begin

k:=0;

g:=round(w);

end;

write(f:4:2,Rus('- '));

if k>=1 then write (k,Rus('.'));

writeln(g,Rus('.'));

write(Rus(' '));

readln

end.

{$APPTYPE CONSOLE} . . .

Project Compile .

Run Run . DOS- ( 6.2). Delphi .

File-Save , .

6.2 DOS-,

:

1 Write writeln ?

2 Read readln ?

3 ?

7

,

: Delphi .

. AnsiChar WideChar . AnsiChar ANSI , () . WideChar Unicode , . AnsiChar Char .

, :

;

;

;

.

.

: Char;

:

;

Char .

Chr Ord . Chr . , :=Chr(32) () .

Ord . , k:=Ord(*) k 42 , * . OnActivate , (Label1) . OnActivate . TForm1.FormActivate ( 7.1).

7.1

7.1 .

unit Tab1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;

type

TForm1 = class(TForm)

Label1: TLabel;

procedure FormActivate(Sender:TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormActivate(Sender:TObject);

var

st:string; //

dec:byte; //

i,j:integer; //

begin

st:='';

dec:=192;

for i:=0 to 15 do //

begin

dec:=i+192;

for j:=1 to 4 do //

begin

st:=st+chr(dec)+'-'+IntToStr(dec)+' ';

dec:=dec+16;

end;

st:=st+#13; //

end;

Label1.Caption:=st;

end;

end.

7.1

: ShortString, LongString, WideString. , .

ShortString , 255- . LongString, WideString , .

7.2

Delphi . .

Length . Length . : .

n:=length();

m:=length( );

n m 7 12.

Delete

Delete . :

Delete (, , n);

:

- ;

;

n - .

:

s:= ;

delete(s, 7, 6);

s .

Pos

Pos . :

Pos(1,);

:

1 - ;

- ;

:

p:=pos(; );

p 7 , pos .

Copy

Copy . :

Copy(, , n);

:

- ;

;

n - .

s:= ;

Copy(s,2,5);

s .

, ( 7.2).

7.2

7.2

unit Unit122;

interface

uses

Windows, Messages, SysUtils, Variants,

Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm1 = class(TForm)

Label1: TLabel;

Label2: TLabel;

procedure FormActivate(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormActivate(Sender: TObject);

var s1:string[100];

s:string[100];

begin

s1:='';

s:=copy(s1,1,9);

Label2.Caption:=s;

end;

end.

:

1 1- -, 2- . .

2 1- -, copy .

3 1- , 2- . Pos ?

, , ( 7.3).

7.3

7.3

procedure TForm1.FormActivate(Sender: TObject);

var s1:string[100];

begin

s1:='';

delete(s1, 4, 10);

Label2.Caption:=s1;

end;

:

1 1- , 2- . .

2 1- . .

3 1- , copy .

4 s , delete(s, 8, 4) ?

, , ( 7.4).

7.4

7.4

procedure TForm1.FormActivate(Sender: TObject);

var s1:integer;

begin

s1:=pos('','');

Label2.Caption:= IntToStr(s1);

end;

:

1 1- -, 2- . .

2 1- , .

3 1- , copy .

4 s , delete(s, 8, 2) ?

, , ( 7.5).

7.5

7.5

procedure TForm1.FormActivate(Sender: TObject);

var s1:integer;

s:string[100];

begin

s1:=length('');

Label2.Caption:= IntToStr(s1);

end;

:

1 1- , 2- . .

2 1- , .

3 1- , 2- . pos ?

4 s , delete(s, 6, 3) ?

8

: Delphi , .

. . , : .

, . :

: array[_.._] of

:

;

array-Delphi , .

_.._ , .

:

temper:array[1..31] ofreal;

koef:array[0..2] of integer;

name:array[1..30] of string[25];

. : .

const

NT=18; //

SN=25; //

var

team: array[1..NT] of string[SN];

, () .

: team[1]:=;

:

;

;

;

;

.

8.1

. , for for .

. . Label1.AutoSize False ( 8.1).

8.1

8.1

unit Mas_komanda;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm1 = class(TForm)

Label1: TLabel;

Button1: TButton;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

const

NT=5;

var team:array[1..NT] of string[10]=

('','','','','');

procedure TForm1.Button1Click(Sender: TObject);

var

st:string; //

i:integer; // ,

begin

//

for i:=1 to NT do

st:=st +IntToStr(i)+' '+team[i]+#13;

//

Label1.Caption:=st;

end;

end.

8.2

- .

, . : StringGrid Memo.

8.2.1 StringGrid

StringGrid . StringGrid Additional ( 8.2).

(StringGrid) 8.2 Additional

1.StringGrid

Name

. .

ColCount

Count

Cells

. , col row Cells[col,row]

FixedCols

. .

FixedRows

. .

Options.goEditing

. True - , False- .

Options.goTab

(True) (False) .

Options.GoAlways-ShowEditor

. False , , .

DefaultColWidth

DefaultRowHeight

GridLineWidth

Left

Top

Height

Width

Font

ParentFont

.

StringGrid .

( 8.3).

(Label1Label2Button1StringGrid)

8.3

StringGrid , Label1 Label2 , Button1- . StringGrid . 2- .

2.

ColCount

5

FixedCols

0

RowCount

1

DefaultRowHeight

24

Height

24

DefaultColWidth

64

Width

328

Options.goEditing

True

Options.AlwaysShowEditing

True

Options.goTabs

True

8.2

unit Sum_AO;

interface

uses

Windows, Messages, SysUtils, Variants,

Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Grids;

type

TForm1 = class(TForm)

Label1: TLabel;

StringGrid1: TStringGrid;

Button1: TButton;

Label2: TLabel;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var

a:array[1..5] of integer;//

summ:integer; //

sr:real; //

i:integer;//

begin

// ,

// ,

//

for i:=1 to 5 do

if Length(StringGrid1.Cells[i-1,0])0

then a[i]:=StrToInt(StringGrid1.Cells[i-1,0])

else a[i]:=0;

//

summ:=0;

for i:=1 to 5 do

summ:=summ+a[i];

sr:=summ/5;

//

Label2.Caption:=

' :'+InttoStr(summ)+#13+

' :'+FloatToStr(sr);

end;

end.

, . . OnKeyPress . . .

8.3 OnKeyPress

procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);

begin

case Key of

#8,'0'..'9':; //

#13: //

if StringGrid1.Col0 then

begin

st:=' : ' +#13;

for i:=1 to n do

st:=st+IntToStr(i)+' '+a[i]+#13;

ShowMessage(st);

end;

end;

end.

:

1 ?

2 ?

3 StringGridMemo .

9

()

: , .

. () : () , . () () , , .

() StringGrid1, ( 1), (label1, Label2) , (Button1) ( 9.1).

1.StringGrid1

ColCount

005

FixedCols

000

RowCount

001

DefaultRowHeight

024

Height

024

DefaultColWidth

064

Width

328

Options.goEditing

True

Options.AlwaysShowEditing

True

Options.goTabs

True

Button1 OnClick .

9.1

9.1 .

unit min;

interface

uses

Windows, Messages, SysUtils, Variants,Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, Grids;

type

TForm1 = class(TForm)

StringGrid1: TStringGrid;

Label1: TLabel;

Button1: TButton;

Label2: TLabel;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

const

SIZE=5;

var

a:array[1..SIZE] of integer; //

min:integer; //

i:integer; //

begin

//

for i:=1 to SIZE do

a[i]:=StrToInt(StringGrid1.Cells[i-1,0]);

//

min:=1; //

for i:=2 to SIZE do

if a[i]SIZE) or (found=TRUE);

if found

then ShowMessage(' '+IntToStr(i)+#13

+' ')

else ShowMessage(' ');

end;

end.

9.3

. , . :

a[1] < a[2] < < a[size]

size .

- , .

() . .

;

.

9.3.1

i ii: . ii ii i , i i . i ii i 1-i , i . :

i i ii, ;

iii;

i i ;

;

.

( 9.3).

, (Button1) . StringGrid1 . (Label2) .

9.3

9.3.

procedure TForm1.Button1Click(Sender: TObject);

const

SIZE=10;

var

a:array[1..SIZE] of integer;

min:integer; {

}

j:integer; { }

buf:integer; { }

i,k:integer;

begin

//

for i:=1 to SIZE do

a[i]:=StrToInt(StringGrid1.Cells[i-1,0]);

label2.Caption:='';

for i:=1 to SIZE-1 do

begin

{ a[1] a[SIZE] }

min:=i;

for j:=i+1 to SIZE do

if a[j]a[k+1] then begin // k- k+1

buf:=a[k]; a[k]:=a[k+1]; a[k+1]:=buf;

changed:=true;

end;

//

for i:=1 to SIZE do

label2.Caption:=label2.Caption+' '+IntToStr(a[i]);

label2.Caption:=label2.Caption+#13;

until not changed; // ,

label2.Caption:=label2.Caption+#13+' ';

end;

( 9.7).

9.7

:

1 . .

2 . .

3 . 3- , 5- .

4 10 . , .

5 . . .

10

: .

. , , , . , . - .

. ().

.

1. ( ) . (10.1 )

, ;

, . (Sred+1 niz ), verh- sred+1 , niz .

(VerhsrednizVerhsrednizVerhsredniz)

1

-5

1

-5

1

-5

2

-1

2

-1

2

-1

3

0

3

0

3

0

4

2

4

2

4

2

5

13

5

13

5

13

6

44

6

44

6

44

7

70

7

70

7

70

8

75

8

75

8

75

9

91

9

91

9

91

10.1

( ? ? ?Niz:=sred-1Verh:=sred+1)

10.2

2. , (niz-verh)/2*verh sred , .

10.2 - - , verh niz .

10.3- . Label3 . , . verh, niz, sred . .

10.3

. (Ceckbox ). Checkbox Standart . . 1- .

1.

Name

. .

Caption

Checked

() . , Checked=True, , Checked=False

State

. , , 3 . 3 . cbChecked (), cgGrayed (, ), cbUnChecked ()

Allow

Grayed

? AllowGrayed=False AllowGrayed=True

Checkbox , .

2.

Caption

Checked

True

OnClick . Button1 . . . n . Trunc . . : (niz-verh)/2 , sred . StringGrid1 Edit1 OnKeyPress . .

10.1 OnClick

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Grids;

type

TForm1 = class(TForm)

StringGrid1: TStringGrid;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

Edit1: TEdit;

CheckBox1: TCheckBox;

Button1: TButton;

procedure Button1Click(Sender: TObject);

procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);

procedure Edit1KeyPress(Sender: TObject; var Key: Char);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

{}

procedure TForm1.Button1Click(Sender: TObject);

const size=10;

var

a:array[1..size] of integer;//

obr:integer; //

verh:integer; //

niz:integer; //

sred:integer; //

i:integer;

n:integer; //

found:boolean; // True

begin

//

for i:=1 to size do

a[i]:=StrToInt(StringGrid1.Cells[i-1,0]);

obr:=StrToInt(Edit1.text);

//

verh:=1;

niz:=size;

n:=0;

found:=False;

Label3.Caption:='';

if CheckBox1.State=cbChecked

then Label3.Caption:='verh' +#9+'niz'#9'sred'#13;

//

repeat

sred:=Trunc((niz-verh)/2)+verh;

if CheckBox1.Checked then Label3.Caption:=label3.Caption+IntToStr(verh)+#9+IntToStr(niz)+#9+IntToStr(sred)+#13;

n:=n+1;

if a[sred]=obrthen found:=True

else if obrniz) or found;

if found

then Label3.Caption:= Label3.Caption+

' '+IntToStr(sred)+

#13+''+IntToStr(n)

else Label3.Caption:=label3.Caption+'

';

end;

// StringGrid1

procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);

begin

if key=#13 then //

if StringGrid1.ColstrToInt(tabl.cells[5,m])

then m:=i;

if rm then

begin // r- - m

for c:=0 to 5 do

begin

buf[c]:=tabl.cells[c,r];

tabl.cells[c,r]:=tabl.cells[c,m];

tabl.cells[c,m]:=buf[c];

end;

end;

end;

end;

( 11.2). ( 11.3).

. ? . , , . .

2

9

4

13

8

12

1

7

5

3

2

11

7

14

6

1

8

3

10

6

15

16

5

9

4

12

: .

. , . , Edit1 OnKeyPress , , .

. . . ( 12.1).

12.1

12.1 .

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm1 = class(TForm)

Label1: TLabel; //

Label2: TLabel; //

Edit1: TEdit; //

Button1: TButton; //

procedure Button1Click(Sender: TObject);

procedure Edit1KeyPress(Sender: TObject; var Key: Char);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

//

procedure FuntToKg;

var

f:real; //

kg:real; //

begin

f:=StrToFloat(Form1.Edit1.Text) ;

kg:=f*0.4059;

Form1.Label2.Caption:=Form1.Edit1.Text+'.-'

+FloatToStrF(kg,ffgeneral,4, 2) +' .';

end;

//

procedure TForm1.Button1Click(Sender: TObject);

begin

FuntToKg; // FuntToKg

end;

//

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);

begin

if Key=Char(VK_RETURN)

then FuntToKg; // FuntToKg

end;

end.

. , , , . , . , . , .

. Delphi : .

, .

, . , .

. .

. .

:

;

.

. .

12.1

- .

. .

:

:= ();

:

;

;

. .

:

, ;

- .

12.2

:

function(1:1,.... :):;

var

//

begin

//

:=;

end;

function ;

. ;

. var , . ;

.

. .

IsInt IsFlot . IsInt . . IsFloat . IsFloat : .

// .

//

function IsInt(ch:char):boolean;

begin

if (ch>='0') and (ch='0') and (ch='0')

and (st[Length(st)]='0') and (ch='0')

and (st[Length(st)]x0+w);

y:=y0+dy;

ly:=dly;

repeat

MoveTo(x0-3,y); LineTo(x0+3,y);

TextOut(x0-20,y,FloatToStr(ly));

Pen.Style:=psDot;

MoveTo(x0+3,y); LineTo(x0+w,y);

Pen.Style:=psSolid;

y:=y-dy;

ly:=ly+dly;

until (y=x2);

//

my:=h/abs(y2-y1);

mx:=w/abs(x2-x1);

x0:=1;

y0:=b-Abs(Round(y1*my));

with Form1.Canvas do

begin

//

MoveTo(l,b); LineTo(l,b-h);

MoveTo(x0,y0); LineTo(x0+w,y0);

TextOut(1+5,b-h,FloatToStrF(y2,ffGeneral,6,3)) ;

TextOut(1+5,b,FloatToStrF(y1,ffGeneral,6,3)) ;

//

x:=x1;

repeat

y:=f(x);

Pixels[x0+Round(x*mx),y0-Round(y*my)]:=clRed;

x:=x+dx;

until (x>=x2);

end;

end;

procedure TForm1.FormPaint(Sender: TObject);

begin

GrOfFunc;

end;

//

procedure TForm1.FormResize(Sender: TObject);

begin

form1.Canvas.FillRect(Rect(0,0,ClientWidth,ClientHeight));

//

GrOfFunc;;

end;end.

14.8 y=2sin(x)x/5

GrOfFunc . (y2) (y1) [x1,x2] . (Form1.ClientWidth - 40) (Form1.ClientHeidth - 40) X(mx), Y(my) .

. GrOfFunc OnPaint OnFormResize . TForm1.FormResize . . .

- . , .

14.5.9

bmp, jpg, ico . Additional Image . :

1.

Picture

Width, Heigth

. , AutoSize Strech False .

AutoSize

.

Strech

.

Visible

, .

. Picture . Load Picture Editor . , Strech True Width, Heigth . Form1.Image1.Picture.LoadFromFile(e:\temp\bart.bmp) .

LoadFromFile BMP, WMF, JPEG .

:

1 Delphi- ?

2 ?

3 ?

4 ?

15

DEPLHI- ,

: Delphi .

, , , ( 15.1). , Events onPaint .

15.1 , , ,

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;

type

TForm1 = class(TForm)

procedure FormPaint(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormPaint(Sender: TObject);

begin

with form1.Canvas do

begin

Pixels[420,50]:=clBlack;//

MoveTo(280,70);

LineTo(400,150); //

Pen.Width:=2; // 2

Pen.Color:=clBlue;//

Brush.Color:=clGreen;//

Ellipse(50,50,130,130); //

Brush.Color:=clRed;// ()

Rectangle(180,30,250,150); //

Font.Name:='Times Kaz';//

Font.Size:=12;//

Font.Style:=[fsbold,fsitalic]; //

TextOut(380,60,'');

TextOut(380,160,'');

TextOut(60,140,'');

TextOut(160,160,'');

end;

end;

end.

15.1

15.1 . Animate, ProgressBar, Timer .

.

Delphi , . .

Animate .

ProgressBar , .. .

Timer Windows- . . Enabled true , Interval . onTimer.

1. , Win32 Animate1, ProgressBar1; System Timer1, Label1 ( 15.2);

2. Animate1 CommonAvi aviCopyFile , ProgressBar1 Step 1 ;

3. Timer1 onTimer :

15.2 Timer1 onTimer

procedure TForm1.Timer1Timer(Sender: TObject);

begin

Animate1.Active:=true;

Label1.Caption:=TimeToStr(Time);

ProgressBar1.StepIt;

end;

end.

4. , . .

15.2

:

1 .

2 .

3 y=cos(x2)+5x .

4 .

5 - .

16

DELPHI . CALCULATOR

: , Delhi . - : , , .

. - . , . 1997 22 .

. Turbo Pascal7.0, Visual Basic, Delhi, C++ ..

. . , , 1- 9- . 30- 35 . : . . , , . .

15 :

15

152

789

634

. 9 . 6 , 2, 9 4 .

6

152

789

634

9 . 4 , 2 . 6, 3 4 . .

8 . :

7

152

789

634

5 . 2 , 2 , .

16.1

SpeedButton, Panel ( 16.1). - Exit, - NewGame, - Comp.begins, level, - Help . Label . Button . Memo , Label . Form1 . Caption Calculator . Fil Save All calc.dpr . Tolls Environment Options Designer Grid size 4 4 .

Panel , . Name Panel1 , Left=24, Top=24, Width=141, Height=41. Font Style fsBold . Size=28.

Memo . Lines (TStrings) . String List Editor Memo1 Your moves: My moves. Courier New, 12 . Memo1 218 , -218, -180, -24 .

Button , Memo1 : btNew, btCompBegins, btLevel, btHelp, btExit (Name) , (Caption) New Game, Comp. begins, Level, Help, Exit. 411 , 48 . btLevel laLevel () . , 12 , 496, 122 . .

Additional SpeedButton . . , 12 45 . (), () . , k00, k01, k02, k10, k11, k12, k20, k21, k22 . , . Caption 0- 9- .

16.1 Calculator

16.2

. Unit.pas .

var

Form1: TForm1;

var . const. {SR*.dfm} . .

const

DEPTHS: array[0..8] of byte=(2,3,4,5,6,7,8,9,99);

. .

INTOSTR=0 - ;

INTOCOL=1- ;

RESLOST=0 ;

RESWON=1

RESNOTKNOWN=2 - ;

HUMAN_MOVE=0 ;

COMP_MOVE=1 .

16.1 .

depth: byte=0;

depth0: byte;

tabl: array[0..2,0..2] of byte=((1,2,3),(4,5,6),(7,8,9));

indicator: integer;

level: integer=2;

movenum,oldstrnum,oldcolnum,compbegins: integer;

isplayersmove: boolean;

movenum ;

oldstrnum ;

oldcolnum ;

compbegins ;

isplayersmove TRUE , , .

{$R *.dfm} . .

SwapByte ;

ShowLevel deptho;

ShowIndicator ;

ShowResult . $BBGGRR .

. . ShowDigits : . 0 2-. i j . . FindComponent sb

sb.Font.Color:=0;

if (i=redstr) or (j=redcol) then sb.Font.Color:=$BO;

DoMove, . Memo1 Application. ProcesMessages . CompMove . .

NewGameFormCreate btNew . tab1 . .

Form1 . Events OnCreate , FormCreate . ShowLevel NewGame.

btNew, btCompBegins, btLevel, btHelp, btExit. .

16.2

// "Comp. begins"

procedure TForm1.btCompBeginsClick(Sender: TObject);

begin

if movenum = 0 then CompMove;

end;

// "New Game"

procedure TForm1.btNewClick(Sender: TObject);

begin

NewGame;

end;

// "Level"

procedure TForm1.btLevelClick(Sender: TObject);

begin

if movenum = 0 then

begin

level:=(level+1) mod 9;

ShowLevel;

end;

end;

// "Help"

procedure TForm1.btHelpClick(Sender: TObject);

begin

if not Assigned(fmHelp) then fmHelp:=TfmHelp.Create(Form1);

with fmHelp do

begin

left:=Form1.Left;

top:=Form1.Top;

ShowModal;

Free;

fmHelp:=NIL;

end;

end;

// "Exit"

procedure TForm1.btExitClick(Sender: TObject);

begin

Close;end;

SpeedButton . SBClick . onCick .

16.3

. File New|Form . Form2 . Caption Help . BorderIcons BorderStyle . Project|Options ( 16.2). Forms . Auto-create forms . fmHelp Available forms .

16.2 Calculator

16.3 fmHelp .

Ifnot Assigned (fmHelp) then fmHelp:=T fmHelp.Create(Form1);

With fmHelp do

Begin

Left:= Form1.Left;

Top:= Form1. Top;

ShowModa1;

Free;

fmHelp:=NIL;

end;

. Memo1 . WordWrap = True 10 . Memo1 :

, , 1- 9- . 30- 35 . : . . , , . .

Memo1 btOk OK , btExit . ModalResult mrOk . . KeyPreview True . Events OnKeyPress FormKeyPress . :

if key = char(VK_ ESCAPE) then Close;

16.4 Unit1.pas .

{$B-}

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,

Dialogs, Buttons, ExtCtrls, StdCtrls;

type

TForm1 = class(TForm)

k00: TSpeedButton;

k01: TSpeedButton;

k02: TSpeedButton;

k12: TSpeedButton;

k10: TSpeedButton;

k11: TSpeedButton;

k22: TSpeedButton;

k20: TSpeedButton;

k21: TSpeedButton;

Panel1: TPanel;

Memo1: TMemo;

btNew: TButton;

btCompBegins: TButton;

btLevel: TButton;

btHelp: TButton;

btExit: TButton;

laLevel: TLabel;

laResult: TLabel;

procedure FormCreate(Sender: TObject);

procedure btNewClick(Sender: TObject);

procedure btLevelClick(Sender: TObject);

procedure btCompBeginsClick(Sender: TObject);

procedure btExitClick(Sender: TObject);

procedure k00Click(Sender: TObject);

procedure k01Click(Sender: TObject);

procedure k02Click(Sender: TObject);

procedure k10Click(Sender: TObject);

procedure k11Click(Sender: TObject);

procedure k12Click(Sender: TObject);

procedure k20Click(Sender: TObject);

procedure k21Click(Sender: TObject);

procedure k22Click(Sender: TObject);

procedure btHelpClick(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

const

DEPTHS: array[0..8] of byte=(2,3,4,5,6,7,8,9,99);

INTOSTR=0;

INTOCOL=1;

RESLOST=0;

RESWON=1;

RESNOTKNOWN=2;

HUMAN_MOVE=0;

COMP_MOVE=1;

var

Form1: TForm1;

depth: byte=0;

depth0: byte;

tabl: array[0..2,0..2] of byte=((1,2,3),(4,5,6),(7,8,9));

indicator: integer;

level: integer=2;

movenum,oldstrnum,oldcolnum,compbegins: integer;

isplayersmove: boolean;

implementation

uses Unit2;

{$R *.dfm}

procedure CompMove; forward;

// b1 b2

procedure SwapByte(var b1,b2: byte);

var

b: byte;

begin

b:=b1; b1:=b2; b2:=b;

end; {SwapByte}

// depth0

procedure ShowLevel;

begin

Form1.laLevel.Caption:=IntToStr(level+1);

//

depth0:=DEPTHS[level]; end; {ShowLevel}

//

procedure ShowIndicator;

begin

Form1.Panel1.Caption:=IntToStr(indicator);

end; {ShowIndicator}

//

procedure ShowResult(resind: integer);

const

RES: array[0..2] of string=(' i ','i ii!',' ');

COLORS: array[0..2] of integer=($E00000,$B0,0);

begin

with Form1.laResult do

begin

Font.Color:=COLORS[resind];

Caption:=': '+RES[resind];

end; end; {ShowResult}

{ . Redstr redcol }

procedure ShowDigits(redstr,redcol: integer);

var

i,j: integer; sb: TSpeedButton;

begin

for i:=0 to 2 do

for j:=0 to 2 do

begin

//

sb:=TSpeedButton(Form1.FindComponent

(Format('k%d%d',[i,j])));

sb.Font.Color:=integer((i = redstr) or (j = redcol))*$B0;

sb.Caption:=IntToStr(tabl[i,j]);

end;

end;{ShowDigits}

{ strnum, colnum . str_col=tstr, , , .: 0 - , 1 - , 2 - . }

function IsWin(indicator,strnum,colnum,str_col: integer): byte;

label

WON,LOST,NOTKNOWN,EX;

var

i,newindicator,tmpres,res: integer;

begin

//

Inc(depth);

if depth > depth0 then goto NOTKNOWN;

//

newindicator:=indicator-tabl[strnum,colnum];

if newindicator < 0 then goto LOST;

if newindicator = 0 then goto WON;

// . .

res:=RESLOST;

for i:=0 to 2 do

begin

if str_col = INTOSTR then

// colnum

tmpres:=IsWin(newindicator,i,colnum,INTOCOL)

else

// strnum

tmpres:=IsWin(newindicator,strnum,i,INTOSTR);

if tmpres = RESWON then goto LOST;

if tmpres = RESNOTKNOWN then res:=RESNOTKNOWN;

end;

if res = RESNOTKNOWN then goto NOTKNOWN;

WON: IsWin:=RESWON;

goto EX;

NOTKNOWN:

IsWin:=RESNOTKNOWN;

goto EX;

LOST: IsWin:=RESLOST;

EX: Dec (depth);

end; {IsWin}

{ strnum, colnum . iscompmove=0, , 1 - }

procedure DoMove(strnum,colnum,iscompmove: integer);

begin

//

Dec(indicator,tabl[strnum,colnum]);

ShowIndicator;

//

if iscompmove = COMP_MOVE then

// Memo1

with Form1.Memo1 do

begin

if movenum = 0 then Lines.Append(' ');

Lines[Lines.Count-1]:=Lines[Lines.Count-1]+' '+IntToStr(tabl[strnum,colnum]);

end

else

//

Form1.Memo1.Lines.Append(' '+IntToStr(tabl[strnum,colnum]));

//

Application.ProcessMessages;

// ?

if indicator < 0 then

begin

ShowResult(iscompmove);

Exit;

end;

//

Inc(movenum);

oldstrnum:=strnum;

oldcolnum:=colnum;

isplayersmove:=not isplayersmove;

if not isplayersmove then

//

CompMove

else

//

if compbegins = 1 then

ShowDigits(-1,colnum)

else

ShowDigits(strnum,-1);

end; {DoMove}

//

procedure CompMove;

var

i,j,res,newindicator,i1,j1,i2,j2: integer;

ind:array[0..8,0..1] of integer;

begin

// ?

if movenum = 0 then compbegins:=1;

//

isplayersmove:=FALSE;

//

Sleep(800);

if indicator = 0 then

// 0 ,

begin

ShowResult(RESWON);

Exit; end;

{ i1, j1, newindicator i, j }

newindicator:=-1;

{ ind tabl }

for res:=0 to 8 do

for i:=0 to 2 do

for j:=0 to 2 do

if tabl[i,j] = res+1 then

begin

ind[res,0]:=i; ind[res,1]:=j;

end;

//

for i:=8 downto 0 do

begin

// i2, j2 -

i2:=ind[i,0]; j2:=ind[i,1];

{ , }

if (movenum > 0) and

((i2 oldstrnum) and (compbegins = 1) or

(j2 oldcolnum) and (compbegins = 0)) then continue;

// i2, j2

res:=IsWin(indicator,i2,j2,1-compbegins);

// ?

if res = RESWON then

// , ,

begin

ShowResult(RESLOST);

DoMove(i2,j2,COMP_MOVE);

Exit; end;

{i2, j2 . ?}

if (res = RESNOTKNOWN) and (indicator-tabl[i2,j2] > newindicator) then

//,

begin

newindicator:=indicator-tabl[i2,j2];

i1:=i2; j1:=j2;

end; end;

{ . , }

if newindicator > -1 then

begin

DoMove(i1,j1,COMP_MOVE);

Exit; end else

//

for i:=0 to 8 do

begin

// i2, j2

i2:=ind[i,0]; j2:=ind[i,1];

{ , }

if (movenum > 0) and

((i2 oldstrnum) and (compbegins = 1) or

(j2 oldcolnum) and (compbegins = 0)) then continue;

{ > 0, , }

if indicator-tabl[i2,j2] > 0 then

begin

DoMove(i2,j2,COMP_MOVE);

Exit; end else

// .

break; end;

ShowResult(RESWON);

end; {CompMove}

//

procedure NewGame;

var

i,j: integer;

begin

Randomize;

// tabl

for i:=0 to 2 do

for j:=0 to 2 do

SwapByte(tabl[i,j],tabl[Random(3),Random(3)]);

//

ShowDigits(-1,-1);

// 30..35

indicator:=Random(6)+30;

ShowIndicator;

//

movenum:=0;

// Memo1

Form1.Memo1.Lines.Clear;

Form1.Memo1.Lines.Append('Ci : :');

//

isplayersmove:=TRUE;

//

ShowResult(RESNOTKNOWN);

end; {NewGame}

//

procedure TForm1.FormCreate(Sender: TObject);

begin

ShowLevel; NewGame;

end;

// "Comp. begins"

procedure TForm1.btCompBeginsClick(Sender: TObject);

begin

if movenum = 0 then CompMove;

end;

// "New Game"

procedure TForm1.btNewClick(Sender: TObject);

begin

NewGame;

end;

// "Level"

procedure TForm1.btLevelClick(Sender: TObject);

begin

if movenum = 0 then

begin

level:=(level+1) mod 9;

ShowLevel;

end;

end;

// "Help"

procedure TForm1.btHelpClick(Sender: TObject);

begin

if not Assigned(fmHelp) then fmHelp:=TfmHelp.Create(Form1);

with fmHelp do

begin

left:=Form1.Left;

top:=Form1.Top;

ShowModal; Free;

fmHelp:=NIL;

end; end;

// "Exit"

procedure TForm1.btExitClick(Sender: TObject);

begin

Close;

end;

// strnum colnum

procedure SBClick(strnum,colnum: integer);

begin

// ?

if not isplayersmove or (indicator < 0) then Exit;

//

if movenum > 0 then

begin

//

if (compbegins = 1) and (colnum oldcolnum) then Exit;

//

if (compbegins = 0) and (strnum oldstrnum) then Exit; end

else

//

compbegins:=0;

// strnum, colnum

DoMove(strnum,colnum,HUMAN_MOVE);

end; {Click}

// .

procedure TForm1.k00Click(Sender: TObject);

begin

SBClick(0,0);end;

procedure TForm1.k01Click(Sender: TObject);

begin

SBClick(0,1);end;

procedure TForm1.k02Click(Sender: TObject);

begin

SBClick(0,2); end;

procedure TForm1.k10Click(Sender: TObject);

begin

SBClick(1,0); end;

procedure TForm1.k11Click(Sender: TObject);

begin

SBClick(1,1); end;

procedure TForm1.k12Click(Sender: TObject);

begin

SBClick(1,2); end;

procedure TForm1.k20Click(Sender: TObject);

begin

SBClick(2,0);end;

procedure TForm1.k21Click(Sender: TObject);

begin

SBClick(2,1); end;

procedure TForm1.k22Click(Sender: TObject);

begin

SBClick(2,2); end;

end.

16.5 Unit2.pas;

unit Unit2;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TfmHelp = class(TForm)

Memo1: TMemo;

btOK: TButton;

procedure FormKeyPress(Sender: TObject; var Key: Char);

private

{ Private declarations }

public

{ Public declarations }

end;

var

fmHelp: TfmHelp;

implementation

{$R *.dfm}

procedure TfmHelp.FormKeyPress(Sender: TObject; var Key: Char);

begin

if key = char(VK_ESCAPE) then Close;

end;

end.

Unit2.pas ( 16.3).

16.3 Calculator fmHelp

17

DELPHI

: , Delhi .

17.1 DELPHI

1: .

:

1 Label1, Label2 , Edit1 Button1 ( 17.1).

2 :

1.

Button1

Caption

Button1

Edit1

Text

Edit1

Form1

Caption

Form1

Label1

Caption

Label1

Label2

Caption

Label2

17.1

Button1 OnClick .

:

procedure TForm1.Button1Click(Sender: TObject);

var s, r: real;

begin

r:=StrToFloat(Edit1.text);

s:=Pi*sqr(r);

Label2.caption:=''+FloatToStrF(s,ffgeneral,7,2);

end;

:

17.2

17.2

2: y(x) z(y) .y=ex+sinx+1; z=(y-1)5; x=0,53;

:

1 Label1, Label2 , Edit1 Button1 ( 17.3).

2 :

2.

Button1

Caption

Button1

Edit1

Text

Edit1

Form1

Caption

Form1

Label1

Caption

Label1

-

Label2

Caption

Label2

17.3

Button1 OnClick .

:

uses

Windows, Messages, SysUtils, Variants, Classes,

Graphics, Controls, Forms,

Dialogs, Math, StdCtrls;

procedure TForm1.Button1Click(Sender: TObject);

var x, y, z: real;

begin

x:=StrToFloat(Edit1.Text);

y:=exp(x+sin(x))+1;

z:=Power((y-1),5);

Label2.caption:='y(x)='+FloatToStrF(y,ffgeneral,7,2)+

'z(y)='+FloatToStrF(z,ffgeneral,7,2);

end;

:

17.4

17.2

3: .

:

1 Label1, Label2 , Edit1, Edit2 Memo1 ,Button1 ( 17.5).

2 :

3.

Button1

Caption

Button1

Edit1

Text

Edit1

Edit2

Text

Edit2

Form1

Caption

Form1

Label1

Caption

Label1

A

Label2

Caption

Label2

X

Memo1

-

-

-

3 Memo1 Lines , [] , String List Editor .

17.5

Button1 OnClick .

:

procedure TForm1.Button1Click(Sender: TObject);

var x, z: real;

a: integer;

begin

a:=StrToInt(Edit1.text);

x:=StrToFloat(Edit2.text);

if a>0 then z:=sqr(sin(a*x)) else z:=0;

Memo1.Clear;

Memo1.Lines.add('Z='+FloatToStrF(z,ffgeneral,7,2));

end;

:

17.6

17.4 T .

4:f(x) [a,b] x=a+ih, i=0,1,2,m, h=(b-a)/m .f(x)=sinx+sin2x, a=0 b=2, m=8.

:

1 Label1, Label2, Label3 , Edit1 Edit2, Edit3 Memo1 , Button1 ( 17.7).

2 :

4.

Button1

Caption

Button1

Edit1

Text

Edit1

Edit2

Text

Edit2

Edit3

Text

Edit3

Form1

Caption

Form1

Label1

Caption

Label1

A

Label2

Caption

Label2

B

Label3

Caption

Label3

m

Memo1

-

-

-

3 Memo1 Lines , [] , String List Editor .

17.7

Button1 OnClick .

:

procedure TForm1.Button1Click(Sender: TObject);

var a,b,h,x,y:real;

i, m: integer;

begin

a:=StrToFloat(Edit1.Text);

b:=StrToFloat(Edit2.Text);

m:=StrToInt(Edit3.text);

Memo1.Clear;

h:=(b-a)/m;

for i:=0 to m do

begin

x:=a+i*h;

y:=sin(x)+sin(2*x);

Memo1.Lines.add('x='+FloatToStrF(x,ffgeneral,7,2)+

', f(x)='+FloatToStrF(y,ffgeneral,7,2)+';');

end;

end;

:

17.8

17.5 . ,

5: .

f=f*k; y=y+x/f, x=103,13;

:

1 Label1 , Edit1 Memo1 ,Button1, Button2 .

2 :

5.

Button1

Caption

Button1

Button2

Caption

Button2

Edit1

Text

Edit1

Form1

Caption

Form1

Label1

Caption

Label1

X

Memo1

-

-

-

3 Memo1 Lines, [] , StringListEditor.

17.9

Button1 Button2 OnClick .

:

procedure TForm1.Button1Click(Sender: TObject);

var x,y: real;

i,f,k: integer;

begin

x:=StrToFloat(Edit1.text);

y:=0;

for i:=1 to 7 do

begin

f:=1;

for k:=1 to i do

f:=f*k;

y:=y+x/f

end;

Memo1.Clear;

Memo1.Lines.Add('Y(x)='+FloatToStrF(y,ffgeneral,7,2));

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

Edit1.text:='';

Memo1.Clear;

end;

:

17.10

17.6 .

6: . 10.

:

1 StringGrid1 , Label1 Memo1 ,Button1 .

2 :

6.

Button1

Caption

Button1

Form1

Caption

Form1

max, min

Label1

Caption

Label1

10

Memo1

-

-

-

StringGrid1

ColCount

5

10

DefaultColWidth

64

30

FixedCols

1

0

FixedRows

1

0

goEditing

False

True

goTabs

False

True

goAlwaysShowEditor

False

True

RowCount

5

1

ScrollBars

ssBoth

SsNone

3. Memo1 Lines , [] , StringListEditor.

17.11

Button1 OnClick .

:

procedure TForm1.Button1Click(Sender: TObject);

type w = 0..20;

const

SIZE=10;

var

a:array[1..10] of w;

i: integer;

min, max,sa: real;

begin

Memo1.Clear;

for i:=1 to SIZE do

if length(StringGrid1.Cells[i-1,0]) 0 then

a[i]:=StrToInt(StringGrid1.Cells[i-1,0])

else a[i]:=0;

min:=a[1]; max:=a[1];

for i:=2 to SIZE do

begin

if min>a[i] then min:=a[i];

if max a[max] then max:=j;

buf:=a[i];

a[i]:=a[max];

a[max]:=buf;

end;

for k:=1 to SIZE do Memo1.Lines.Add(IntToStr(a[k]));

end;

:

17.14

17.8

8: :

:

1 StringGrid1 , Label1 Memo1 ,Button1 .

2 :

8.

Button1

Caption

Button1

Form1

Caption

Form1

Label1

Caption

Label1

10

Memo1

-

-

-

StringGrid1

ColCount

5

4

DefaultColWidth

64

60

FixedCols

1

0

FixedRows

1

0

goEditing

False

True

goTabs

False

True

goAlwaysShowEditor

False

True

RowCount

5

2

ScrollBars

ssBoth

SsNone

3 Memo1 Lines , [] , String List Editor .

17.15

Button1 OnClick .

:

procedure TForm1.Button1Click(Sender: TObject);

const

w=4;

h=2;

var a: array[1..w] of array[1..h] of real;

buf: real;

i,j: integer;

begin

for i:=1 to w do

forj:=1 to h do

if StringGrid1.Cells[i-1,j-1] '' then

a[i,j]:=StrToFloat(StringGrid1.Cells[i-1,j-1])

else a[i,j]:=0;

for j:=1 to h do

begin

buf:=a[1,j];

a[1,j]:=a[w,j];

a[w,j]:=buf;

StringGrid1.Cells[0,j-1]:=FloatToStr(a[1,j]);

StringGrid1.Cells[w-1,j-1]:=FloatToStr(a[w,j]);

end;

end; :

17.16

17.9

9: :

f1:=sin(x); f2:=y; f3:=y; f4:=x*y;x=0,59; y=0,35;

:

1 Label1, Label2 , Edit1, Edit2 Memo1 , Button1 .

2 , :

9.

Button1

Caption

Button1

Edit1

Text

Edit1

Edit2

Text

Edit2

Form1

Caption

Form1

Label1

Caption

Label1

X

Label2

Caption

Label2

Memo1

-

-

-

3 Memo1 Lines ,[] , String List Editor .

17.17

Button1 OnClick .

:

:

function f(ni,ki: integer; f1,f2: real): real;

var i: integer;

begin

Result:=1;

for i:=ni to ki do Result:=Result*(Power(f1,i)+Power(f2,10-i));

end;

procedure TForm1.Button1Click(Sender: TObject);

var f1,f2,f3,f4,x,y,w: real;

begin

x:=StrToFloat(Edit1.Text);

y:=StrToFloat(Edit2.Text);

f1:=sin(x); f2:=y; f3:=y; f4:=x*y;

w:=f(1,10,f1,f2)-f(3,7,f3,f4);

Memo1.Clear;

Memo1.Lines.Add('W='+FloatToStrF(w,ffgeneral,7,2));

end;

:

Procedure f(ni,ki: integer; f1,f2: real;

var Result: real);

var i: integer;

begin

Result:=1;

for i:=ni to ki do Result:=Result*(Power(f1,i)+Power(f2,10-i));

end;

procedure TForm1.Button1Click(Sender: TObject);

var f1,f2,f3,f4,x,y,w,p1,p2: real;

begin

x:=StrToFloat(Edit1.Text);

y:=StrToFloat(Edit2.Text);

f1:=sin(x); f2:=y; f3:=y; f4:=x*y;

f(1,10,f1,f2,p1);f(3,7,f3,f4,p2);

w:=p1-p2;

Memo1.Clear;

Memo1.Lines.Add('W='+FloatToStrF(w,ffgeneral,7,2));

end;

:

(0,350,591W=2,186672E-8)

17.18

17.10

10: : SYM DYM () .

:

1 Label1 Memo1 .

2 , :

10.

Form1

Caption

Form1

Label1

Caption

Label1

SYM

Memo1

-

-

-

3 Memo1 Lines, [] , StringListEditor.

17.19

Memo1 OnKeyPress .

:

procedure TForm1.Memo1KeyPress

(Sender: TObject; var Key: Char);

var

f,g: TextFile; x: Char; s: String;

begin

if Key=#13 thenbegins:='';

AssignFile(f,'sym.txt');

Rewrite(f);

write(f,Memo1.Text);

CloseFile(f);

Label1.caption:='DYM :';

Memo1.Clear;

reset(f,'sym.txt');

rewrite(g,'dym.txt');

while not eof(f) do

begin

read(f,x);

if x>