Форум: "Основная";
Текущий архив: 2003.09.01;
Скачать: [xml.tar.bz2];
ВнизEAccessViolation при создании экзэмляра класса Найти похожие ветки
← →
m2003 (2003-08-17 14:06) [0]Уважаемые мастера, подскажите пожалуйста где ошибка?
Создаю модуль.
В нём 3 класса. 2 наследник 1. 3 наследник 2.
Unit U1;
Interface
Type
to1=class
prop1:byte;
constructor Create(prm1:byte);
end;
to2=class(to1)
prop2:byte;
constructor Create(prm1,prm2:byte);
end;
to3=class(to2)
prop3:byte;
constructor Create(prm1,prm2,prm3:byte);
end;
implementation
constructor to1.Create(prm1:byte);
begin
inherited create;
prop1:=prm1;
end;
constructor to2.Create(prm1,prm2:byte);
begin
inherited Create(prm1);
prop2:=prm2;
end;
constructor to3.Create Create(prm1,prm2,prm3:byte);
begin
inherited Create(prm1,prm2);
prop3:=prm3;
end;
end.
Затем в программе пишу
o3:to3;
...
o3:=to3.create(1,2,3);
и в вышеуказаной строчке возникает ошибка EAccessViolation.
← →
m2003 (2003-08-17 14:08) [1]Извините, забыл указать строчку.
constructor to1.Create(prm1:byte);
begin
inherited create;
prop1:=prm1; //<<<< здесь
end;
← →
@Ujin (2003-08-17 14:12) [2]constructor to1.Create(prm1:byte);
begin
inherited create; А надо-ли это?
prop1:=prm1; //<<<< здесь
end;
← →
m2003 (2003-08-17 14:13) [3]может и не надо, но без этого ошибка всё равно остаётся.
← →
VMcL (2003-08-17 14:28) [4]>m2003 © (17.08.03 14:13) [3]
Приведи полный код всех указанных тобой классов.
← →
m2003 (2003-08-17 14:34) [5]unit UObjects;
interface
uses dxdraws,windows;
type
toWin=class
Rct:TRect;
Visible,MouseOn,Down:boolean;
cnv:tdirectdrawsurface;
Col,LightCol,DarkCol:longint;
constructor Create(x1,y1,x2,y2:integer;c1,c2,c3:longint;c:tdirectdrawsurface);
procedure Draw;
procedure MMove(p:tpoint);
procedure MEnter;virtual;
procedure MExit;virtual;
end;
toBut=class(toWin)
LS,checkbox:boolean;
Image:byte;
proc:procedure;
constructor Create(x1,y1,x2,y2:integer;c1,c2,c3:longint;p:pointer;c:tdirectdrawsur face;cb:boolean;Img:byte);
procedure MDown(p:tpoint);
procedure MUp(p:tpoint);
procedure MEnter;override;
procedure MExit;override;
procedure Draw;
end;
toMI=class(tobut)
parentObj:pointer;
procedure Draw;
constructor Create(x1,y1,x2,y2:integer;c1,c2,c3:longint;p1,p2:pointer;c:tdirectdra wsurface;cb:boolean;Img:byte);
end;
implementation
uses uglobal;
function PinR(p:tpoint;r:trect):boolean;
begin
pinr:=(p.x>=r.left)and(p.x<=r.Right)and(p.y>=r.top)and(p.y<=r.Bottom);
end;
procedure toBut.MDown(p:tpoint);
begin
if visible=false then exit;
if pinr(p,rct) then
begin
ls:=down;
down:=true;
end;
end;
constructor toWin.Create(x1,y1,x2,y2:integer;c1,c2,c3:longint;c:tdirectdrawsurface );
begin
visible:=true;
rct.left:=x1;
rct.right:=x2;
rct.top:=y1;
rct.bottom:=y2;
col:=c1;
lightcol:=c2;
darkcol:=c3;
cnv:=c;
end;
procedure toWin.MEnter;
begin
end;
procedure toWin.MExit;
begin
end;
procedure toWin.Draw;
var
r1,r2,r3:trect;
l1,l2:longint;
begin
if visible=false then exit;
r1:=rct;
r2:=rct;
inc(r2.left);
inc(r2.top);
r3:=r2;
dec(r3.right);dec(r3.bottom);
if down then l1:=darkcol else l1:=lightcol;
if l1=lightcol then l2:=darkcol else l2:=lightcol;
cnv.FillRect(r1,l1);
cnv.FillRect(r2,l2);
cnv.FillRect(r3,Col);
end;
procedure toWin.MMove(p:tpoint);
begin
if visible=false then exit;
if mouseon xor pinr(p,rct) then
begin
mouseon:=not mouseon;
if mouseon then MEnter else MExit;
end;
end;
constructor toBut.Create(x1,y1,x2,y2:integer;c1,c2,c3:longint;p:pointer;c:tdirectd rawsurface;cb:boolean;Img:byte);
begin
inherited Create(x1,y1,x2,y2,c1,c2,c3,c);
image:=img;
@proc:=p;
checkbox:=cb;
end;
procedure toBut.MUp(p:tpoint);
begin
if visible=false then exit;
if pinr(p,rct)and down then
begin
if checkbox then
down:=not ls
else
down:=false;
proc;
end;
end;
procedure toBut.Draw;
begin
inherited draw;
sdraw(rct.left+1,rct.top+1,6,image);
end;
procedure toBut.MExit;
begin
if not checkbox then
if down then down:=ls;
end;
procedure toBut.MEnter;
begin
end;
procedure toMI.Draw;
begin
if parentobj=nil then
inherited Draw
else
if toMI(parentobj^).Down then
inherited Draw;
end;
constructor toMI.Create(x1,y1,x2,y2:integer;c1,c2,c3:longint;p1,p2:pointer;c:tdire ctdrawsurface;cb:boolean;Img:byte);
begin
inherited Create(x1,y1,x2,y2,c1,c2,c3,p1,c,cb,Img);
parentobj:=p2;
end;
end.
← →
m2003 (2003-08-17 14:36) [6]Я делаю меню для игры.
← →
InTeGeR (2003-08-17 16:23) [7]Я всё полностью повторил, и у меня нет никакой ошибки.
> constructor to3.Create Create(prm1,prm2,prm3:byte); тут у тебя опечатка
> begin
> inherited Create(prm1,prm2);
> prop3:=prm3;
> end;
Ничего не могу понять(( почему у иебя там может быть ошибка?
← →
VMcL (2003-08-18 14:24) [8]>m2003 © (17.08.03 14:34) [5]
Пользоваться тэгом "...
" религия не позволяет?
← →
VMcL (2003-08-18 14:26) [9]Oops.
>m2003 © (17.08.03 14:34) [5]
Пользоваться тэгом "...
" религия не позволяет?
← →
VMcL (2003-08-18 14:28) [10]>>VMcL © (18.08.03 14:26) [9]
Sorry for flood. Имеется в виду тэг [CODE].
← →
Семен Сорокин (2003-08-18 14:35) [11]попробуй так, может поможет:
Unit U1;
Interface
Type
to1=class
prop1:byte;
constructor Create(prm1:byte); virtual;
end;
to2=class(to1)
prop2:byte;
constructor Create(prm1,prm2:byte); reintroduce;
end;
to3=class(to2)
prop3:byte;
constructor Create(prm1,prm2,prm3:byte); reintroduce;
end;
implementation
constructor to1.Create(prm1:byte);
begin
inherited create;
prop1:=prm1;
end;
constructor to2.Create(prm1,prm2:byte);
begin
inherited Create(prm1);
prop2:=prm2;
end;
constructor to3.Create Create(prm1,prm2,prm3:byte);
begin
inherited Create(prm1,prm2);
prop3:=prm3;
end;
end.
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2003.09.01;
Скачать: [xml.tar.bz2];
Память: 0.48 MB
Время: 0.024 c