
23.09.2015, 16:05
|
Прохожий
|
|
Регистрация: 07.09.2015
Сообщения: 9
Версия Delphi: Delphi 7
Репутация: 10
|
|
Движение объекта
Программа выдаёт ошибку Access VIolation, Как отрисовывать стрелку в PaintBox1? и как заставить ее двигаться по кругу по законам которые описаны в классе TZakon? Помогите пожалуйста, а то я запутался.может что дописать надо или наоборот убрать из кода.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, MyClasses;
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
Button1: TButton;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MyLine1:TGeometryFigure;
implementation
{$R *.dfm}
//создаёт форму
procedure TForm1.FormCreate(Sender: TObject);
begin
Width:=960; //Ширина формы
Height:=600; //Высота формы
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
MyLine1:=TGeometryFigure.Create(270, ((PaintBox1.Left+PaintBox1.Width) div 2), ((PaintBox1.Left+PaintBox1.Height) div 2), ClBlack, (PaintBox1.Width div 2-10), 10);
MyLine1.Show(); //Рисует линию
PaintBox1.Canvas.Rectangle(8,8,208,208); //Рисует квадрат в паинтбоксе
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Timer1.Enabled then
Timer1.Enabled := False //Таймер выкл
else
Timer1.Enabled := true;//Таймер вкл
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
PaintBox1.Invalidate;
end;
end.
Код:
unit MyClasses;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TZakon=class
private
{ Private declarations }
v:real; //скорость
a:real; //ускорение
s:real; //путь
public
{ Public declarations }
procedure FindSpeed(t:real); //находит скорость
procedure FindAcc(t:real); //Находит ускорение
procedure FindPut(t:real); //Находит путь
end;
//класс точка
type
TMyPoint=class
private
{ Private declarations }
px:integer; // Координата Х точки
py:integer; // Координата У точки
cvet:TColor; //Цвет точки
public
{ Public declarations }
constructor Create(Newpx:integer; Newpy:integer; Newcvet:TColor);
end;
//Класс геометрическая фигура
type
TGeometryFigure=class(TMyPoint)
Canvas:TCanvas;
private
{ Private declarations }
w:real; //Ширина фигуры
h:real; //Высота фигуры
ang:real; //угол поворота фигуры
x:integer; //Координата Х (Докуда рисовать фигуру)
y:integer; //Координата У (Докуда рисовать фигуру)
public
{ Public declarations }
procedure Show(); //Отображает фигуру
constructor Create(Newang:real; Newpx:integer; Newpy:integer; Newcvet:TColor; Neww:real; Newh:real);
end;
implementation
{TZakon1}
procedure TZakon.FindAcc(t:real); //Находит ускорение
begin
a:=sin(t);
end;
procedure TZakon.FindPut(t:real); //Находит путь
begin
s:=t-sin(t);
end;
procedure TZakon.FindSpeed(t:real); //Нахуодит ускорение
begin
v:=-cos(t)+1;
end;
{ TMyPoint }
constructor TMyPoint.Create(Newpx:integer; Newpy:integer; Newcvet:TColor);
begin
px:=Newpx;
py:=Newpy;
cvet:=Newcvet;
end;
{ TGeometryFigure }
constructor TGeometryFigure.Create(Newang:real; Newpx:integer; Newpy:integer; Newcvet:TColor; Neww:real; Newh:real);
begin
inherited Create(Newpx, Newpy, Newcvet);
w:=Neww;
h:=Newh;
ang:=Newang;
end;
procedure TGeometryFigure.Show();
begin
Canvas.LineTo(px,py);
Canvas.MoveTo(x,y);
end;
end.
|