Логическая схема юниты
И
нтегрированная среда разработки Delphi.Разработка приложения в Delphi.
Ввод-вывод данных в Delphi.
Windows как среда разработки и выполнения программ.
Структура простого проекта Delphi.
Менеджер проектов.
Компиляция, сборка и выполнение программ.
Установка параметров проекта.
Язык Object Pascal.
Классы.
Типы данных в Object Pascal.
Исключительные ситуации.
Приведение типов данных.
Базовые классы VCL.
Программы, управляемые событиями.
Создание и уничтожение формы.
Стандартные визуальные компоненты.
Дополнительные визуальные компоненты.
Компоненты Internet.
Компоненты доступа к базам данных.
Визуальные компоненты Windows-интерфейса.
С
писки и коллекции.Функции печати
задача №2
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
memo: TMemo;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i,j,b,k:integer;
a:array [1..3267] of integer;
begin
a[1]:=2;
j:=1;
for i:=3 to strtoint(edit1.text) do begin
b:=1;
for k:=1 to j do if ((i mod a[k])=0) then b:=0;
if b=1 then
begin
j:=j+1;
a[j]:=i;
end;
end;
if edit1.Text=inttostr(1) then memo.Text:=inttostr(1);
if edit1.Text=inttostr(2) then memo.Text:=inttostr(2);
if b=1 then memo.Text:=edit1.Text;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
memo.text:=' ';
end;
end.
задача №3
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
ScrollBar1: TScrollBar;
procedure ScrollBar1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
edit1.Width:=scrollbar1.Position*5;
end;
end.
задача №4
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
procedure N3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.N3Click(Sender: TObject);
begin
application.terminate;
end;
end.
задача №5
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
SaveDialog1: TSaveDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var f:textfile;
begin
savedialog1.DefaultExt:='txt';
savedialog1.Filter:='текстовый файл(*.txt)|*.txt';
if savedialog1.Execute then begin
assignfile(f, savedialog1.FileName);
rewrite(f);
write(f,edit1.Text);
end;
closefile(f);
end;
end.
задача №6
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls;
type
TForm1 = class(TForm)
CheckBox1: TCheckBox;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.N1Click(Sender: TObject);
begin
checkbox1.Color:=clred;
checkbox1.font.Color:=clgreen;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
checkbox1.Color:=clblack;
checkbox1.font.Color:=clwhite;
end;
procedure TForm1.N3Click(Sender: TObject);
begin
checkbox1.Color:=clwhite;
checkbox1.font.Color:=clblack;
end;
end.
задача №7
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
x: TEdit;
y: TEdit;
z: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
RadioGroup1: TRadioGroup;
Label5: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if RadioGroup1.Itemindex=0 then
label5.Caption:=inttostr(strtoint(x.text)+strtoint(y.text)+strtoint(z.text))
else if RadioGroup1.Itemindex=1 then
label5.Caption:=inttostr(strtoint(x.text)*strtoint(y.text)*strtoint(z.text))
else if RadioGroup1.ItemIndex=2 then
label5.Caption:=inttostr(sqr(strtoint(x.text))+sqr(strtoint(y.text))+sqr(strtoint(z.text)))
else label5.Caption:=inttostr(error);
end;
end.
задача №8
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Image1.Picture.LoadFromFile(listbox1.items[listbox1.itemindex]);
end;
end.
задача №9
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
for i:=1 to 10 do begin
stringgrid1.Cells[0,i]:='команда'+inttostr(i);
stringgrid1.Cells[1,i]:=inttostr(0);
end;
stringgrid1.Cells[1,0]:='очки';
end;
procedure TForm1.Button1Click(Sender: TObject);
var t,m,s,max:integer;
rab:string;
begin
t:=strtoint(edit2.Text);
m:=strtoint(edit3.Text);
StringGrid1.Cells[1,t]:= inttostr(m);
end;
end.
задача №10
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, StdCtrls, ExtCtrls, TeeProcs, Chart;
type
TForm1 = class(TForm)
Chart1: TChart;
Button1: TButton;
Series1: TPointSeries;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var f:textfile;
b:array [1..10] of double;
a:array [1..10] of string;
i:integer;
begin
opendialog1.DefaultExt:='txt';
opendialog1.Filter:='*.txt|*.txt';
if opendialog1.Execute then
assignfile(f, opendialog1.FileName);
reset(f);
for i:=1 to 10 do begin
readln(f,a[i]);
b[i]:=strtoint(a[i]);
end;
chart1.Series[0].AddArray(b);
end;
end.
задача №11
unit PaintUnit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ExtDlgs, Grids, TeeProcs, TeEngine, Chart, ActnList,
Menus, Buttons, ComCtrls;
type
TPaintMainForm = class(TForm)
Image1: TImage;
Label1: TLabel;
Edit1: TEdit;
ScrollBar1: TScrollBar;
Label2: TLabel;
Edit2: TEdit;
ScrollBar2: TScrollBar;
Label3: TLabel;
Edit3: TEdit;
ScrollBar3: TScrollBar;
Panel1: TPanel;
Label4: TLabel;
ActionList1: TActionList;
Action1: TAction;
Action2: TAction;
Action3: TAction;
Action4: TAction;
Action6: TAction;
Action7: TAction;
Action8: TAction;
Action9: TAction;
Edit4: TEdit;
UpDown1: TUpDown;
Label5: TLabel;
SpeedButton3: TSpeedButton;
Action5: TAction;
Bevel1: TBevel;
Bevel2: TBevel;
procedure FormCreate(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ScrollBar1Change(Sender: TObject);
procedure ScrollBar3Change(Sender: TObject);
procedure ScrollBar2Change(Sender: TObject);
procedure Action1Execute(Sender: TObject);
procedure Action4Execute(Sender: TObject);
procedure Action6Execute(Sender: TObject);
procedure Action7Execute(Sender: TObject);
procedure Action8Execute(Sender: TObject);
procedure Action9Execute(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure Action5Execute(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
PaintMainForm: TPaintMainForm;
implementation
uses PaintUnit2;
{$R *.DFM}
procedure TPaintMainForm.FormCreate(Sender: TObject);
begin
UpDown1.Associate:=Edit4;
UpDown1.Min:=10;
UpDown1.Max:=100;
UpDown1.Increment:=5;
Image1.Canvas.FillRect(clientRect);
Image1.Canvas.Pen.Style:=psSolid;
end;
var drag:boolean=false;
procedure TPaintMainForm.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Var a,code1:integer;
c:Tcolor;
begin
c:=Image1.Canvas.Pen.Color;
val (edit4.text,a,code1);
if code1=0 then
drag:=true;
image1.Canvas.MoveTo(x,y);
end;
procedure TPaintMainForm.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if drag then image1.Canvas.LineTo(x,y);
end;
procedure TPaintMainForm.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
drag:=false;
end;
procedure TPaintMainForm.ScrollBar1Change(Sender: TObject);
var red,green,blue :byte;
c:tcolor;
begin
red:=scrollbar1.Position;
green:=scrollbar2.Position;
blue:=scrollbar3.Position;
edit1.Text:=inttostr(red);
edit2.Text:=inttostr(green);
edit3.Text:=inttostr(blue);
c:= rgb(red,green,blue);
image1.Canvas.brush.Color:=c;
panel1.Color:=c;
image1.canvas.pen.color:=C;
end;
procedure TPaintMainForm.ScrollBar3Change(Sender: TObject);
var red,green,blue :byte;
c:tcolor;
begin
red:=scrollbar1.Position;
green:=scrollbar2.Position;
blue:=scrollbar3.Position;
edit1.Text:=inttostr(red);
edit2.Text:=inttostr(green);
edit3.Text:=inttostr(blue);
c:= rgb(red,green,blue);
image1.Canvas.brush.Color:=c;
panel1.Color:=c;
image1.canvas.pen.color:=C;
end;
procedure TPaintMainForm.ScrollBar2Change(Sender: TObject);
var red,green,blue :byte;
c:tcolor;
begin
red:=scrollbar1.Position;
green:=scrollbar2.Position;
blue:=scrollbar3.Position;
edit1.Text:=inttostr(red);
edit2.Text:=inttostr(green);
edit3.Text:=inttostr(blue);
c:= rgb(red,green,blue);
image1.Canvas.brush.Color:=c;
panel1.Color:=c;
image1.canvas.pen.color:=C;
end;
procedure TPaintMainForm.Action1Execute(Sender: TObject);
begin
Image1.Canvas.FillRect(ClientRect);
end;
procedure TPaintMainForm.Action4Execute(Sender: TObject);
begin
Image1.Canvas.FillRect(ClientRect);
PaintMainForm.Close;
end;
procedure TPaintMainForm.Action6Execute(Sender: TObject);
begin
Image1.Canvas.Pen.Style:=psDash;
end;
procedure TPaintMainForm.Action7Execute(Sender: TObject);
begin
Image1.Canvas.Pen.Style:=psDot;
end;
procedure TPaintMainForm.Action8Execute(Sender: TObject);
begin
Image1.Canvas.Pen.Style:=psDashDot;
end;
procedure TPaintMainForm.Action9Execute(Sender: TObject);
begin
Image1.Canvas.Pen.Style:=psSolid;
end;
procedure TPaintMainForm.SpeedButton3Click(Sender: TObject);
begin
if SpeedButton3.Down=True then Image1.Canvas.Pen.Width:=10;
if SpeedButton3.Down=False then Image1.Canvas.Pen.Width:=1;
end;
procedure TPaintMainForm.Action5Execute(Sender: TObject);
begin
PaintHelpForm.Show;
end;
procedure TPaintMainForm.SpeedButton5Click(Sender: TObject);
begin
Image1.Canvas.FillRect(ClientRect);
Image1.Canvas.Brush.Color:=clWhite;
Image1.Canvas.Pen.Color:=clBlack;
Panel1.Color:=clBlack;
end;
end.