Hej,
Jeg er i gang med et lille vendespil.
Det compiler uden det mindste brok, men jeg får flere fejl under kørslen. Bl.a. en abstract error.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Timer1: TTimer;
Timer2: TTimer;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MyOnClick(Sender: TObject);
procedure FormDblClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure del(lvl: integer);
procedure Timer2Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Level, point, par: real;
Last: String;
lastobj, newobj: TObject;
implementation
{$R *.dfm}
procedure TForm1.MyOnClick(Sender: TObject);
var
slet, skjul: boolean;
begin
slet := false;
skjul := false;
if Sender <> lastobj then
begin
If (Sender is TImage) then // Is it a image?
begin
(Sender as TImage).Picture.LoadFromFile('tema\\1\\billeder\\'+ListBox1.Items[strtoint((Sender as TImage).Hint)-1]);
if last <> '' then
begin
if last = ListBox1.Items[strtoint((Sender as TImage).Hint)-1] then
begin
point := point + level;
Form1.Caption := 'Point: '+floattostr(point);
//last := '';
//sleep(500);
slet := true;
//(Sender as TImage).Picture.LoadFromFile('tema\\1\\billeder\\bag.bmp');
//(lastobj as TImage).Picture.LoadFromFile('tema\\1\\billeder\\bag.bmp');
end
else
begin
if ListBox1.Items[strtoint((Sender as TImage).Hint)-1] = 'joker.bmp' then
begin
point := point + (level*2);
Form1.Caption := 'Point: '+floattostr(point);
newobj := Sender;
timer2.Enabled := true;
end
else
begin
//last := '';
//sleep(500);
slet := false;
skjul := true;
//(Sender as TImage).Picture.LoadFromFile('tema\\1\\billeder\\bag.bmp');
//(lastobj as TImage).Picture.LoadFromFile('tema\\1\\billeder\\bag.bmp');
end;
end;
end
else
begin
if ListBox1.Items[strtoint((Sender as TImage).Hint)-1] = 'joker.bmp' then
begin
point := point + (level*2);
Form1.Caption := 'Point: '+floattostr(point);
newobj := Sender;
timer2.Enabled := true;
end
else
begin
last := ListBox1.Items[strtoint((Sender as TImage).Hint)-1];
lastobj := Sender;
slet := false;
skjul := false;
end;
end;
end;
if slet then
begin
par := par+1;
(Sender as TImage).Free;
if last <> '' then
begin
(lastobj as TImage).Free;
end;
last := '';
if par = int(((level+1)*(level+1)) / 2) then
begin
showmessage('Du har klaret level '+floattostr(level)+' og har nu '+floattostr(point)+' point.');
par := 0;
//slet := false;
//skjul := false;
last := '';
level := level + 1;
del(strtoint(floattostr(level)));
end;
end
else
begin
if skjul then
begin
newobj := Sender;
last := '';
timer1.Enabled := true;
end;
end;
end;
end;
procedure TForm1.del(lvl:integer);
var
i, j, k: integer;
begin
Form1.ListBox1.Items.LoadFromFile('tema\\1\\settings\\levels\\'+floattostr(lvl)+'.txt');
Randomize;
for k := 1 to Form1.ListBox1.Items.Count do
Form1.ListBox1.Items.Move(Random(Form1.ListBox1.Items.Count), 0);
for i := 1 to lvl + 1 do
begin
for j := 1 to lvl + 1 do
begin
with TImage.Create(form1) do
begin
Parent := Form1;
Width := ( 420 - ( ( lvl + 2 ) * 4 ) ) div ( lvl + 1);
Height := Width;
Left := j * 4 + ( Width * ( j - 1 ) );
Top := i * 4 + ( Height * ( i - 1 ) );
Hint := inttostr( j + ( ( i - 1 ) * ( lvl + 1 ) ) );
Name := 'Image'+inttostr( j + ( ( i - 1 ) * ( lvl + 1 ) ) );
OnClick := Form1.MyOnClick;
Stretch := true;
Picture.LoadFromFile('tema\\1\\billeder\\bag.bmp');
Visible := True;
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled := false;
del(strtoint(floattostr(Level)));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Level := 1;
Button1.Visible := false;
del(strtoint(floattostr(Level)));
Form1.Color := clBlack;
Form1.ClientWidth := 420;
Form1.ClientHeight := 420;
end;
procedure TForm1.FormDblClick(Sender: TObject);
begin
//Form1.Close;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
timer1.Enabled := false;
(newobj as TImage).Picture.LoadFromFile('tema\\1\\billeder\\bag.bmp');
(lastobj as TImage).Picture.LoadFromFile('tema\\1\\billeder\\bag.bmp');
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
timer2.Enabled := false;
(newobj as TImage).Free;
if last <> '' then
begin
last := '';
(lastobj as TImage).Picture.LoadFromFile('tema\\1\\billeder\\bag.bmp');
end
else
begin
last := '';
end;
end;
end.
Jeg ville gerne ligge det hele op inkl. billeder og andre filer, men det kan jeg desværre ikke via skolens net.
Håber i kan hjælpe mig.
Fejl koder jeg får:
Access violation at address 00004010 in module 'Project1.exe'. Read of address 00004010.
Access violation at address 00403349 in module 'Project1.exe'. Read of address 00000033.
Access violation at address 00403349 in module 'Project1.exe'. Read of address 00003A98.
Access violation at address 00403342 in module 'Project1.exe'. Read of address FFFFFFD1.
Access violation at address 00403342 in module 'Project1.exe'. Read of address FFFFFFD0.
Access violation at address 00403340 in module 'Project1.exe'. Read of address 00000001.
Access violation at address 00403350 in module 'Project1.exe'. Read of address 00153000.
Abstract Error.
De kommer ikke alle hver gang, og det er tilfældigt hvornår i spillet de kommer. Den mest hyppige er:
Access violation at address 00403349 in module 'Project1.exe'. Read of address 00003A98.
M.v.h. Johnny.
På forhånd tak!