some code ive been using whit out any problems suddenly wont work..

Whats the really weird parts is when its a random number it got no problems lodaing the image.

But when its

i := i +1
item := listview1.Items;
form2.image1.Picture.LoadFromFile(item.Caption); {here it chrashes]

it crashes whit an error called "Exception class EAccesViolation with message 'Acces Violation at address 004bb6b8 in module 'SecuritySDcreensaver'. Read of address 00000020'

this is how my code looks:

if i = Listview1.Items.Count -1 then
begin
if checkbox1.Checked = true then {if repeat list is true}
begin
i := 0;
item := listview1.Items;
form2.image1.Picture.LoadFromFile(item.Caption);
end
else {else stop the process}
begin
timersec.Enabled := false;
end;
end
else
begin
if checkbox2.Checked = true then {if randomize is true}
begin


if checkbox5.Checked = false then timersec.Enabled := false;


form2.Label9.Caption := 'Start time:' + timetostr(now);;
startime := now;


randomnr := random(listview1.Items.Count -1);


form2.ProgressBar1.Max := listview1.Items.Count;


for n:=1 to ListView1.Items.Count do
begin
application.ProcessMessages;


if form2.checkbox1.checked = true then break; { if "Stop random nr. generation is true}



form2.ProgressBar1.Position := form2.ProgressBar1.Position + 1;


form2.LblList1.Caption := 'Lisview1 : ' + inttostr(form2.ProgressBar1.Position) + ' out of ' + inttostr(form2.ProgressBar1.Max);


SetWindowPos(form3.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);


if checkbox3.Checked = true then { If "dont make the same number appear twice" is true then }
begin



x := 0;


form2.ProgressBar2.Max := listview2.Items.Count;


While x<listview2.Items.Count do
begin


application.ProcessMessages;
if form2.checkbox1.checked = true then break;


if inttostr(randomnr) = listview2.Items[x].Caption then
begin



form2.Label2.Caption := 'Randum number found... Generating new one!';
randomnr := random(listview1.Items.Count);
x := 0;
form2.ProgressBar2.Position := 0;


SetWindowPos(form3.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
end
else
begin


form2.ProgressBar2.Position := form2.ProgressBar2.Position + 1;


form2.LblList2.Caption := 'Lisview2 : ' + inttostr(form2.ProgressBar2.Position) + ' out of ' + inttostr(form2.ProgressBar2.Max);


form2.Label2.Caption := 'looking if random number exist (in listview 2)...';
x := x +1;


form2.Label10.Caption := 'Time went: ' + timetostr(now - startime);
currenttime := now - startime;


timeleft := lasttime - currenttime;
form2.label12.caption := 'Time left:' + timetostr(timeleft);


form2.Label13.Caption := 'Current time: '+ timetostr(now);
SetWindowPos(form3.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);


form2.Image1.Cursor := crhourglass;
form2.Panel1.Cursor := crhourglass;
form2.Panel2.Cursor := crhourglass;
end;
end;
end;
form2.ProgressBar2.Position := 0;
end;


form2.Image1.Cursor := crDefault;
form2.Panel1.Cursor := crDefault;
form2.Panel2.Cursor := crDefault;


if form2.CheckBox1.Checked = false then {if stop loop is false}
begin


item := listview1.Items[randomnr];
form2.image1.Picture.LoadFromFile(item.Caption);


if form9.RadioButton1.Checked = true then { if "stretch image to screen width/height" is true }
begin
form2.Image1.Stretch := true;
end
else { if "stretch image to screen width/height" is false}
begin


form2.Image1.Stretch := false;


if form9.RadioButton2.Checked = true then {if "fit only large images to closets screen borders"
begin


if (form2.image1.picture.height > screen.Height) or (form2.Image1.Picture.Width > screen.Width) then {if the image is larger then the screen}
begin


imageheight := form2.image1.picture.height - form2.height;
imageheightprocent := round(imageheight * 100/ form2.height);


imagewidth := form2.image1.picture.width  - form2.width;
imagewidthprocent := round(imagewidth * 100 / form2.width);


if imageheightprocent > imagewidthprocent then {if its the hight which is the biggest value}
begin
coef:=form2.Image1.Height/form2.Image1.Picture.Height;
form2.image1.width  := Round(form2.image1.Picture.width*coef);
form2.Image1.Stretch := true;


if form9.CheckBox1.Checked = true then
begin
form2.Image1.Left := 0;
end;


if form9.CheckBox2.Checked = true then
begin
form2.Image1.Left := form2.Width div 2 - form2.Image1.Width div 2;
end;


if form9.CheckBox3.Checked = true then
begin
form2.Image1.Left := form2.Width - form2.Image1.Width;
end;


end
else if imagewidthprocent > imageheightprocent then {if its the width which is the bggest value}
begin


end;
end
else {if the image is smaller then the screen}
begin
if form9.CheckBox1.Checked = true then
begin
form2.Image1.Stretch := false;
form2.image1.autosize := true;
form2.Image1.Left := 0;
end;


if form9.checkbox2.checked = true then
begin
form2.Image1.Stretch := false;
form2.Image1.AutoSize := true;
form2.Image1.Left := form2.Width div 2 - form2.Image1.Width div 2;
end;


if form9.CheckBox3.Checked = true then
begin
form2.Image1.Stretch := false;
form2.Image1.AutoSize := true;
form2.image1.Left := form2.Width - form2.Image1.Width;
end;


if form9.CheckBox4.Checked = true then
begin
form2.Image1.Top := 0;
end;


if form9.CheckBox5.Checked = true then
begin
form2.Image1.Top :=  form2.Height div 2 - form2.Image1.Height div 2;
end;


if form9.CheckBox6.Checked = true then
begin
form2.Image1.Top := form2.Height - form2.Image1.Height;
end;
end;
end;
end;


SetWindowPos(form3.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);


form2.label8.Caption := 'Size of image: ' + inttostr(getfilesize(item.Caption) div 1024)  + ' KB';
form2.Label7.Caption :=  item.Caption;


SetWindowPos(form3.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);


item := listview2.Items.Add;
item.Caption :=  inttostr(randomnr); {add the random number to listview 2 for checking after duplet random number}


form2.ProgressBar1.Position := 0;
form2.ProgressBar2.Position := 0;


form2.Label11.Caption := 'Time for last picture: ' + timetostr(now - startime);
lasttime := now - startime;



if listview1.Items.Count = listview2.Items.Count then listview2.Clear;
if (checkbox5.Checked = false) and (lockdown = true) then timersec.Enabled := true;
end;


end
else {if randomize is false}
begin
i := i + 1;
item := listview1.Items;
form2.image1.Picture.LoadFromFile(item.Caption); { its here it crashres whit the above statement }


form2.label8.Caption := 'Size of image: ' + inttostr(getfilesize(item.Caption) div 1024)  + ' KB';
form2.Label7.Caption :=  item.Caption;


end;

its been working before when i started the projekt this was the first i made the random part is a later addon..

Edited 3 Years Ago by happygeek: fixed formatting

Other than you didnt use code tags so your post is painful to read.

When it crashes - check the value of i and item.

Other than you didnt use code tags so your post is painful to read.

When it crashes - check the value of i and item.

i listened to what u said and tried to set i:=0 in the forms load procedure.

and now it works again.. weird how it was possible for it to work before and then suddenly it needs to get a value from the start. weird, really weird...

But thank you for the help and time, i am very grateful that u could read all my code even thought i forgot the code tags. wich i will remember the next time..

Best regards,
Darkyere

This article has been dead for over six months. Start a new discussion instead.