Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.06.27;
Скачать: CL | DM;

Вниз

Сделал первую часть лабораторной по графике. Начал развивать заех   Найти похожие ветки 

 
beregok ©   (2004-06-10 01:08) [0]

Сделал лабораторную по графике. Плавают рыбки в виде треугольничков и стрелочек. Сначала надо создать обект TFish и чтоб все двигалось и обплывало препятствия , развитие задачи: создать TKarp и TPike как дети от TFIsh. Без этих детей все работало на ура. А щас не запускается.
Помогите разобраться. И еще в дальнейшем развитии задачи нужно чтобы щуки(TPike) пожирали карпов (TKarp) как сделать деструктор объекта (т.е. уничтожить рыбку)? У меня в книге просто упомянуто, что есть конструктор (это я понял) и деструктор(это тоже понял,но что в нем писать?). Помогите.

*******************************Это код с детьми. Не работает
При запуске вырисовывает препятствия (Cliff1, Cliff2, cliff3) и на этом останавливается на строчке Pike1.Init(100,100,.....)
Unit Unit1;
Interface
Uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 ExtCtrls, StdCtrls, Math;
Type
 TForm1 = class(TForm)
   Image1: TImage;
   Button1: TButton;
   Button2: TButton;
   Timer1: TTimer;
   Procedure Button1Click(Sender: TObject);
   Procedure Button2Click(Sender: TObject);
   Procedure Timer1Timer(Sender: TObject);
 Private
     { Private declarations }
 Public
   { Public declarations }
end;
    Procedure DrawCliffs;
Type
TFish = class
   fX, fY, fDir, fSize, fSpeed : Integer;
   Constructor Init(X, Y, Dir, Speed, Size : Integer);
   Procedure Draw; Virtual;
   Procedure Hide;
   Procedure Look;
   Procedure Run;
   end;
TPike = class(TFish)
   Procedure Draw; override;
   end;
TKarp = class(TFish)
   Procedure Draw; override;
   end;
TAquarium = class
   Pike1 : TPike;
   Karp1 : TKarp;
   Karp2 : TKarp;
   Karp3 : TKarp;
   Procedure Init;
   Procedure Run;
   end;
const
Water = clBlue;
Cliff1 : Array [1..7] of TPoint = ((x : 100; y : 200), (x : 120; y : 180),(x : 140; y : 160), (x : 160; y : 180),(x : 180; y : 200), (x : 160; y : 220),(x : 100; y : 200));
Cliff2 : Array [1..9] of TPoint = ((x : 300; y : 300), (x : 340; y : 260),(x : 380; y : 310), (x : 390; y : 330),(x : 360; y : 330), (x : 370; y : 350),(x : 345; y : 360), (x : 335; y : 370), (x : 280; y : 340));
Cliff3 : Array [1..3] of TPoint = ((x : 370; y : 50), (x : 444; y : 30),(x : 370; y : 200));
var
 Form1: TForm1;
 Aqua : TAquarium;
 W, H : Integer;
Implementation
{$R *.DFM}
//--------------------------------------------------------
Constructor TFish.Init(X, Y, Dir, Speed, Size : Integer);
begin
fX := X; fY := Y;
fSpeed := Speed; fSize := Size;
fDir := Dir;
Draw;
end; Procedure TFish.Draw;
begin
end;

Procedure TPike.Draw;
var x1, y1, x2, y2, x3, y3 : Integer;
begin
Form1.Image1.Canvas.Pen.Color := clGreen;
Form1.Image1.Canvas.Pen.Style := psSolid;
x1 := fx + Round(Cos(fDir / 180*Pi) * fSize);
y1 := fy + Round(Sin(fDir / 180*Pi) * fSize);
x2 := fx + Round(Cos((fDir + 150) / 180*Pi) * fSize);
y2 := fy + Round(Sin((fDir + 150) / 180*Pi) * fSize);
x3 := fx + Round(Cos((fDir - 150) / 180*Pi) * fSize);
y3 := fy + Round(Sin((fDir - 150) / 180*Pi) * fSize);
with Form1.Image1.Canvas do
   begin
   MoveTo(x1, y1);
   LineTo(x2, y2);
   LineTo(x3, y3);
   end;
end;


 
beregok ©   (2004-06-10 01:10) [1]

Procedure TKarp.Draw;
var x1, y1, x2, y2, x3, y3, Style : Integer;
   Fish_Arr : Array [1..4] of TPoint;
begin
Style := Round(Random(9));
case Style of
1 : Form1.Image1.Canvas.Brush.Style := bsSolid;
2 : Form1.Image1.Canvas.Brush.Style := bsClear;
3 : Form1.Image1.Canvas.Brush.Style := bsHorizontal;
4 : Form1.Image1.Canvas.Brush.Style := bsVertical;
5 : Form1.Image1.Canvas.Brush.Style := bsFDiagonal;
6 : Form1.Image1.Canvas.Brush.Style := bsBDiagonal;
7 : Form1.Image1.Canvas.Brush.Style := bsCross;
8 : Form1.Image1.Canvas.Brush.Style := bsDiagCross;
end; // end of "case Style of"

Form1.Image1.Canvas.Brush.Color := clRed;
Form1.Image1.Canvas.Pen.Color := clRed;
Form1.Image1.Canvas.Pen.Style := psSolid;
x1 := fx + Round(Cos(fDir / 180*Pi) * fSize);
y1 := fy + Round(Sin(fDir / 180*Pi) * fSize);
x2 := fx + Round(Cos((fDir + 150) / 180*Pi) * fSize);
y2 := fy + Round(Sin((fDir + 150) / 180*Pi) * fSize);
x3 := fx + Round(Cos((fDir - 150) / 180*Pi) * fSize);
y3 := fy + Round(Sin((fDir - 150) / 180*Pi) * fSize);
Fish_Arr[1].x := x1; Fish_Arr[1].y := y1;
Fish_Arr[2].x := x2; Fish_Arr[2].y := y2;
Fish_Arr[3].x := x3; Fish_Arr[3].y := y3;
Fish_Arr[4].x := x1; Fish_Arr[4].y := y1;
with Form1.Image1.Canvas do PolyGon(Fish_Arr);
end; //end of TKarp.Draw
//--------------------------------------------------------

Procedure TFish.Hide;
var x1, y1, x2, y2, x3, y3 : Integer;
   Fish_Arr : Array [1..4] of TPoint;
begin
x1 := fx + Round(Cos(fDir / 180*Pi) * fSize);
y1 := fy + Round(Sin(fDir / 180*Pi) * fSize);
x2 := fx + Round(Cos((fDir + 150) / 180*Pi) * fSize);
y2 := fy + Round(Sin((fDir + 150) / 180*Pi) * fSize);
x3 := fx + Round(Cos((fDir - 150) / 180*Pi) * fSize);
y3 := fy + Round(Sin((fDir - 150) / 180*Pi) * fSize);
Fish_Arr[1].x := x1; Fish_Arr[1].y := y1;
Fish_Arr[2].x := x2; Fish_Arr[2].y := y2;
Fish_Arr[3].x := x3; Fish_Arr[3].y := y3;
Fish_Arr[4].x := x1; Fish_Arr[4].y := y1;
Form1.Image1.Canvas.Pen.Color := Water;
Form1.Image1.Canvas.Brush.Color := Water;
Form1.Image1.Canvas.Brush.Style := bsSolid;
with Form1.Image1.Canvas do PolyGon(Fish_Arr);
end; //end of TFish.Hide
//--------------------------------------------------------

Procedure TFish.Look;
var x, y : Integer;
begin
X := fx + Round(Cos((fDir + 20) / 180*Pi) * fSize * 2);
Y := fy + Round(Sin((fDir + 20) / 180*Pi) * fSize * 2);
if Form1.Image1.Canvas.Pixels[X, Y] <> Water then fDir := fDir - 45;

X := fx + Round(Cos((fDir - 20) / 180*Pi) * fSize);
Y := fy + Round(Sin((fDir - 20) / 180*Pi) * fSize);
if Form1.Image1.Canvas.Pixels[X, Y] <> Water then fDir := fDir + 45;

X := fx + Round(Cos(fDir / 180*Pi) * fSize);
Y := fy + Round(Sin(fDir / 180*Pi) * fSize);
if Form1.Image1.Canvas.Pixels[X, Y] <> Water then fDir := fDir + 180;
if Form1.Image1.Canvas.Pixels[X + 1, Y] <> Water then fDir := fDir + 180;
if Form1.Image1.Canvas.Pixels[X - 1, Y] <> Water then fDir := fDir + 180;
if Form1.Image1.Canvas.Pixels[X, Y + 1] <> Water then fDir := fDir + 180;
if Form1.Image1.Canvas.Pixels[X, Y - 1] <> Water then fDir := fDir + 180;
end; {end of TFish.Look}
//--------------------------------------------------------

Procedure TFish.Run;
begin
Hide;
if Random(2) = 1 then if Random(7) > 3 then
 fDir := fDir + Random(Round(110 / fSize)) else
 fDir := fDir - Random(Round(110 / fSize));
Look;
if (fx + fSize > H) or (fx - fSize < 22) or (fy - fSize < 22)
or (fy + fSize > W) then fDir := (fDir Mod 360) + 180;
fx := fx + Round(Cos(fDir / 180*Pi) * fSpeed);
fy := fy + Round(Sin(fDir / 180*Pi) * fSpeed);
Draw;
end;{end of TFish.Run}
//--------------------------------------------------------

Procedure TForm1.Button1Click(Sender: TObject);
begin
W := Form1.Image1.Width;
H := Form1.Image1.Height;
Randomize;
Aqua.Init;
Timer1.Enabled := True;
end; // end of TForm1.Button1Click
//--------------------------------------------------------

Procedure TAquarium.Init;
var r1 : TRect;
begin
r1 := Rect(0,0,W,H);
with Form1.Image1.Canvas do begin
Pen.Color := clRed;
Pen.Style := psSolid;
Brush.Color := Water;
Brush.Style := bsSolid;
FillRect(r1);
                            end;
DrawCliffs;
        //(X, Y, Dir, Speed, Size : Integer);
Pike1.Init(100, 100, 45, 4, 15);
Karp1.Init(200, 100, 0, 2, 5);
Karp2.Init(100, 300, -45, 10, 10);
Karp3.Init(280, 300, -45, 7, 8);
end;{end of TAquarium.Init}
//--------------------------------------------------------

Procedure TAquarium.Run;
begin
Randomize;
Pike1.Run;
Karp1.Run;
Karp2.Run;
Karp3.Run;
end;{end of TAquarium.Run}
//--------------------------------------------------------

Procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;//end of TForm1.Button2Click
//--------------------------------------------------------

Procedure TForm1.Timer1Timer(Sender: TObject);
begin
DrawCliffs;
Aqua.Run;
end; //end of TForm1.Timer1Timer
//--------------------------------------------------------

Procedure DrawCliffs;
begin
with Form1.Image1.Canvas do begin
Pen.Color := clRed;
Pen.Style := psSolid;
Brush.Color := clWhite;
Brush.Style := bsCross;
Polygon(Cliff1);

Brush.Color := clFuchsia;
Brush.Style := bsCross;
Polygon(Cliff2);

Brush.Style := bsDiagCross;
Brush.Color := clYellow;
Polygon(Cliff3);
                            end;
end; //end of DrawCliffs
//--------------------------------------------------------
end.


 
beregok ©   (2004-06-10 01:13) [2]

Вот рабочая версия без разделения рыб на окуней и карпов

Unit Unit1;

Interface

Uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 ExtCtrls, StdCtrls, Math;

Type
 TForm1 = class(TForm)
   Image1: TImage;
   Button1: TButton;
   Button2: TButton;
   Timer1: TTimer;
   Procedure Button1Click(Sender: TObject);
   Procedure Button2Click(Sender: TObject);
   Procedure Timer1Timer(Sender: TObject);

 Private
     { Private declarations }

 Public
   { Public declarations }
end;

    Procedure DrawCliffs;

Type

TFish = object
   fX, fY, fDir : Integer;
   fSize, fColor, fSpeed : Byte;
   Procedure Init(X, Y, Dir, Speed,
                  Size, Color : Integer);
   Procedure Draw;
   Procedure Hide;
   Procedure Look;
   Procedure Run;
   end; //end of class description

TAquarium = object
   Fish1 : TFish;
   Fish2 : TFish;
   Fish3 : TFish;
   Fish4 : TFish;
   Procedure Init;
   Procedure Run;
   end; //end of class description

const

Water = clBlue;
Cliff1 : Array [1..7] of TPoint = ((x : 100; y : 200), (x : 120; y : 180),
                                  (x : 140; y : 160), (x : 160; y : 180),
                                  (x : 180; y : 200), (x : 160; y : 220),
                                  (x : 100; y : 200));
Cliff2 : Array [1..9] of TPoint = ((x : 300; y : 300), (x : 340; y : 260),
                                  (x : 380; y : 310), (x : 390; y : 330),
                                  (x : 360; y : 330), (x : 370; y : 350),
                                  (x : 345; y : 360), (x : 335; y : 370),
                                  (x : 280; y : 340));
Cliff3 : Array [1..3] of TPoint = ((x : 370; y : 50), (x : 444; y : 30),
                                  (x : 370; y : 200));

var

 Form1: TForm1;
 Aqua : TAquarium;
 W, H : Integer;
Implementation

{$R *.DFM}
//--------------------------------------------------------
Procedure TFish.Init(X, Y, Dir, Speed,
                    Size, Color : Integer);
begin
fX := X; fY := Y;
fSpeed := Speed; fSize := Size;
fColor := Color;
fDir := Dir;
Draw;
end; //end of TFish.Init
//--------------------------------------------------------

Procedure TFish.Draw;
var x1, y1, x2, y2, x3, y3, Style : Integer;
   Fish_Arr : Array [1..4] of TPoint;
   Col : TColor;
begin
case fColor of
1 : Col := clBlack;
2 : Col := clMaroon;
3 : Col := clAqua;
4 : Col := clYellow;
5 : Col := clSilver;
6 : Col := clRed;
7 : Col := clLime;
8 : Col := clFuchsia;
9 : Col := clWhite;
end; //end of "case fColor of"

Style := Round(Random(9));
case Style of
1 : Form1.Image1.Canvas.Brush.Style := bsSolid;
2 : Form1.Image1.Canvas.Brush.Style := bsClear;
3 : Form1.Image1.Canvas.Brush.Style := bsHorizontal;
4 : Form1.Image1.Canvas.Brush.Style := bsVertical;
5 : Form1.Image1.Canvas.Brush.Style := bsFDiagonal;
6 : Form1.Image1.Canvas.Brush.Style := bsBDiagonal;
7 : Form1.Image1.Canvas.Brush.Style := bsCross;
8 : Form1.Image1.Canvas.Brush.Style := bsDiagCross;
end; // end of "case Style of"

Form1.Image1.Canvas.Brush.Color := Col;
Form1.Image1.Canvas.Pen.Color := Col;
Form1.Image1.Canvas.Pen.Style := psSolid;
x1 := fx + Round(Cos(fDir / 180*Pi) * fSize);
y1 := fy + Round(Sin(fDir / 180*Pi) * fSize);
x2 := fx + Round(Cos((fDir + 150) / 180*Pi) * fSize);
y2 := fy + Round(Sin((fDir + 150) / 180*Pi) * fSize);
x3 := fx + Round(Cos((fDir - 150) / 180*Pi) * fSize);
y3 := fy + Round(Sin((fDir - 150) / 180*Pi) * fSize);
Fish_Arr[1].x := x1; Fish_Arr[1].y := y1;
Fish_Arr[2].x := x2; Fish_Arr[2].y := y2;
Fish_Arr[3].x := x3; Fish_Arr[3].y := y3;
Fish_Arr[4].x := x1; Fish_Arr[4].y := y1;
with Form1.Image1.Canvas do PolyGon(Fish_Arr);
end; //end of TFish.Draw
//--------------------------------------------------------


 
beregok ©   (2004-06-10 01:13) [3]

Procedure TFish.Hide;
var x1, y1, x2, y2, x3, y3 : Integer;
   Fish_Arr : Array [1..4] of TPoint;
begin
x1 := fx + Round(Cos(fDir / 180*Pi) * fSize);
y1 := fy + Round(Sin(fDir / 180*Pi) * fSize);
x2 := fx + Round(Cos((fDir + 150) / 180*Pi) * fSize);
y2 := fy + Round(Sin((fDir + 150) / 180*Pi) * fSize);
x3 := fx + Round(Cos((fDir - 150) / 180*Pi) * fSize);
y3 := fy + Round(Sin((fDir - 150) / 180*Pi) * fSize);
Fish_Arr[1].x := x1; Fish_Arr[1].y := y1;
Fish_Arr[2].x := x2; Fish_Arr[2].y := y2;
Fish_Arr[3].x := x3; Fish_Arr[3].y := y3;
Fish_Arr[4].x := x1; Fish_Arr[4].y := y1;
Form1.Image1.Canvas.Pen.Color := Water;
Form1.Image1.Canvas.Brush.Color := Water;
Form1.Image1.Canvas.Brush.Style := bsSolid;
with Form1.Image1.Canvas do PolyGon(Fish_Arr);
end; //end of TFish.Hide
//--------------------------------------------------------

Procedure TFish.Look;
var x, y : Integer;
begin
X := fx + Round(Cos((fDir + 20) / 180*Pi) * fSize * 2);
Y := fy + Round(Sin((fDir + 20) / 180*Pi) * fSize * 2);
if Form1.Image1.Canvas.Pixels[X, Y] <> Water then fDir := fDir - 45;

X := fx + Round(Cos((fDir - 20) / 180*Pi) * fSize);
Y := fy + Round(Sin((fDir - 20) / 180*Pi) * fSize);
if Form1.Image1.Canvas.Pixels[X, Y] <> Water then fDir := fDir + 45;

X := fx + Round(Cos(fDir / 180*Pi) * fSize);
Y := fy + Round(Sin(fDir / 180*Pi) * fSize);
if Form1.Image1.Canvas.Pixels[X, Y] <> Water then fDir := fDir + 180;
if Form1.Image1.Canvas.Pixels[X + 1, Y] <> Water then fDir := fDir + 180;
if Form1.Image1.Canvas.Pixels[X - 1, Y] <> Water then fDir := fDir + 180;
if Form1.Image1.Canvas.Pixels[X, Y + 1] <> Water then fDir := fDir + 180;
if Form1.Image1.Canvas.Pixels[X, Y - 1] <> Water then fDir := fDir + 180;
end; {end of TFish.Look}
//--------------------------------------------------------

Procedure TFish.Run;
begin
Hide;
if Random(2) = 1 then if Random(7) > 3 then
 fDir := fDir + Random(Round(110 / fSize)) else
 fDir := fDir - Random(Round(110 / fSize));
Look;
if (fx + fSize > H) or (fx - fSize < 22) or (fy - fSize < 22)
or (fy + fSize > W) then fDir := (fDir Mod 360) + 180;
fx := fx + Round(Cos(fDir / 180*Pi) * fSpeed);
fy := fy + Round(Sin(fDir / 180*Pi) * fSpeed);
Draw;
end;{end of TFish.Run}
//--------------------------------------------------------

Procedure TForm1.Button1Click(Sender: TObject);
var i: byte;
begin
W := Form1.Image1.Width;
H := Form1.Image1.Height;
Randomize;
Aqua.Init;
Timer1.Enabled := True;
end; // end of TForm1.Button1Click
//--------------------------------------------------------

Procedure TAquarium.Init;
var r1 : TRect;
begin
r1 := Rect(0,0,W,H);
with Form1.Image1.Canvas do begin
Pen.Color := clRed;
Pen.Style := psSolid;
Brush.Color := Water;
Brush.Style := bsSolid;
FillRect(r1);
                            end;
DrawCliffs;
         //(X,Y,Dir,Speed,Size,Color : Integer);
Fish1.Init(100,100,45,1,15,1);
Fish2.Init(200,100,0,2,5,2);
Fish3.Init(100,300,-45,10,10,3);
Fish4.Init(280,300,-45,7,8,4);
end;{end of TAquarium.Init}
//--------------------------------------------------------

Procedure TAquarium.Run;
begin
Randomize;
Fish1.Run;
Fish2.Run;
Fish3.Run;
Fish4.Run;
end;{end of TAquarium.Run}
//--------------------------------------------------------

Procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;//end of TForm1.Button2Click
//--------------------------------------------------------

Procedure TForm1.Timer1Timer(Sender: TObject);
begin
DrawCliffs;
Aqua.Run;
end; //end of TForm1.Timer1Timer
//--------------------------------------------------------

Procedure DrawCliffs;
begin
with Form1.Image1.Canvas do begin
Pen.Color := clRed;
Pen.Style := psSolid;
Brush.Color := clWhite;
Brush.Style := bsCross;
Polygon(Cliff1);

Brush.Color := clFuchsia;
Brush.Style := bsCross;
Polygon(Cliff2);

Brush.Style := bsDiagCross;
Brush.Color := clYellow;
Polygon(Cliff3);
                            end;
end; //end of DrawCliffs
//--------------------------------------------------------
end.


 
ЮЮ ©   (2004-06-10 08:54) [4]

>Без этих детей все работало на ура. А щас не запускается.

Интересно, как это работало при таком использовании конструктора?

Может всё же не
Fish1.Init(100,100,45,1,15,1);
а
Fish1 := TFish.Init(100,100,45,1,15,1);

Да и inherited Create, наверное, в конструкторе не помешает.
И зачем вместо всем понятного Create конструктору дано имя Init?


 
panov ©   (2004-06-10 11:08) [5]

В родительском классе у тебя есть конструктор:

Constructor Init(X, Y, Dir, Speed, Size : Integer);

Ему при создании объекта передаются 5 параметров. Соответственно, для правильной инициализации дочернего объекта тебе нужно передавать ему так же эти 5 параметров, перекрывать конструктор. Например:

TPike = class(TFish)
  Procedure Draw; override;
public
  constructor Create(X, Y, Dir, Speed, Size : Integer);
end;
...
constructor TPike.Create(X, Y, Dir, Speed, Size : Integer);
begin
 inherited Init(X, Y, Dir, Speed, Size);
end;

Для создания объектов используется конструкция(см. Ю ©   (10.06.04 08:54) [4]):

Pike1 := TPike.Create(100,100,45,1,15,1);


 
beregok ©   (2004-06-10 11:30) [6]

Без этих детей все работало на ура. А щас не запускается.

Интересно, как это работало при таком использовании конструктора?

Может всё же не
Fish1.Init(100,100,45,1,15,1);
а
Fish1 := TFish.Init(100,100,45,1,15,1);

Да и inherited Create, наверное, в конструкторе не помешает.
И зачем вместо всем понятного Create конструктору дано имя Init?
Переименовал конструктор на Create.

пишу Pike1 := TPike.Init(100,100,45,1,15,1);
и получаю:
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message "Access violation at address 00450E3C in module "Project1.exe". Write of address 00000004". Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------

и теперь пишу по-старому Pike1.Create(100, 100, 45, 4, 15);
а в ответ:
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message "Access violation at address 00450BD3 in module "Project1.exe". Read of address 00000004". Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------

Уж больно они похожи )) Кстати пока я не создал этих детей
Fish1.Init(100,100,45,1,15,1); отлично работало. Может это нечно и не правильно, но факт


 
beregok ©   (2004-06-10 11:34) [7]

Господа я переделал конструкторы по указанному образцу
TFish = class
   Private
   fX, fY, fDir, fSize, fSpeed : Integer;
   Public
   Constructor Create(X, Y, Dir, Speed, Size : Integer);
   Procedure Draw; Virtual;
   Procedure Hide;
   Procedure Look;
   Procedure Run;
   end; //end of class description

TPike = class(TFish)
   Public
   Constructor Create(X, Y, Dir, Speed, Size : Integer);
   Procedure Draw; override;
   end; //end of class description

Constructor TFish.Create(X, Y, Dir, Speed, Size : Integer);
begin
fX := X; fY := Y;
fSpeed := Speed; fSize := Size;
fDir := Dir;
Draw;
end; //end of TFish.Init
//--------------------------------------------------------

constructor TPike.Create(X, Y, Dir, Speed, Size : Integer);
begin
inherited Create(X, Y, Dir, Speed, Size);
end;
//--------------------------------------------------------

Однако результат предний та же ошибка, лишь адрес меняется
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message "Access violation at address 00450BD3 in module "Project1.exe". Read of address 00000004". Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------

программа останавливается на
Pike1.Create(100, 100, 45, 4, 15);

в процедуре
Procedure TAquarium.Init;
var r1 : TRect;
begin
r1 := Rect(0,0,W,H);
with Form1.Image1.Canvas do begin
Pen.Color := clRed;
Pen.Style := psSolid;
Brush.Color := Water;
Brush.Style := bsSolid;
FillRect(r1);
                            end;
DrawCliffs;
        //(X, Y, Dir, Speed, Size : Integer);
Pike1.Create(100, 100, 45, 4, 15);
{ Karp1.Create(200, 100, 0, 2, 5);
Karp2.Create(100, 300, -45, 10, 10);
Karp3.Create(280, 300, -45, 7, 8);}
end;{end of TAquarium.Init}

По-прежнему нужна помощь


 
alless   (2004-06-10 14:48) [8]

constructor TPike.Create(X, Y, Dir, Speed, Size : Integer);
begin
-->inherited Create(X, Y, Dir, Speed, Size);
end;
Otkuda proga znaiet cto delati v:
inherited Create(X, Y, Dir, Speed, Size); ?

Pishi kostructor kak pisal v class  TFish


 
Григорьев Антон ©   (2004-06-10 14:51) [9]

Вам же сказали: добавьте вызов унаследованного конструктора. inherited Create в TFish.Create. Класс TFish тоже имеет предка - TObject, и вызов унаследованного конструктора обязателен.


 
panov ©   (2004-06-10 15:03) [10]

Удалено модератором
Примечание: Дубль


 
panov ©   (2004-06-10 15:04) [11]

>Григорьев Антон ©   (10.06.04 14:51) [9]

В случае предка - TObject вызывать родительский конструктор необязательно.

>beregok ©   (10.06.04 11:34) [7]

разберись вот с этими -

{ Karp1.Create(200, 100, 0, 2, 5);
Karp2.Create(100, 300, -45, 10, 10);
Karp3.Create(280, 300, -45, 7, 8);}


и всеми подобными конструкциями. см. [4] и [5]


 
NAlexey ©   (2004-06-10 15:59) [12]

И не влом вам в этом ковыряться?


 
beregok ©   (2004-06-10 19:57) [13]

Я переделал создания рыб как было сказоно в [4 и 5]
но по-преднему что-то не так. Я впадаю в отчаяние (

Procedure TAquarium.Init;
var r1 : TRect;
begin
r1 := Rect(0,0,W,H);
with Form1.Image1.Canvas do begin
Pen.Color := clRed;
Pen.Style := psSolid;
Brush.Color := Water;
Brush.Style := bsSolid;
FillRect(r1);
                            end;
DrawCliffs;
        //(X, Y, Dir, Speed, Size : Integer);
Pike1 := TPike.Create(100, 100, 45, 4, 15);
Karp1 := TKarp.Create(200, 100, 0, 2, 5);
Karp2 := TKarp.Create(100, 300, -45, 10, 10);
Karp3 := TKarp.Create(280, 300, -45, 7, 8);
end;{end of TAquarium.Init}


 
ЮЮ ©   (2004-06-11 04:51) [14]

В соответствии с у же не раз сказанным, надо не

Aqua.Init;
а
Aqua := TAquarium.Init;


 
beregok ©   (2004-06-11 10:51) [15]

Всем большое спасибо. Теперь дошло окончательно.



Страницы: 1 вся ветка

Текущий архив: 2004.06.27;
Скачать: CL | DM;

Наверх




Память: 0.55 MB
Время: 0.022 c
8-1081715464
Skeptic
2004-04-12 00:31
2004.06.27
пульс!


14-1086590009
ИМХО
2004-06-07 10:33
2004.06.27
"The object invoked has disconnected from its clients"


3-1086009625
Jet
2004-05-31 17:20
2004.06.27
Проблемы с фильтром


14-1086590308
Мазут Береговой
2004-06-07 10:38
2004.06.27
Хотелось бы знать ваше мнение, по одному неприятному


3-1085910917
ertong
2004-05-30 13:55
2004.06.27
Изменение размеров колонки в DBGrid