943,708 Members | Top Members by Rank

Ad:
Dec 14th, 2008
0

im lost

Expand Post »
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[i];
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[i];
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[i];
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..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkyere is offline Offline
17 posts
since Nov 2008
Dec 15th, 2008
0

Re: im lost

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

When it crashes - check the value of i and item.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 15th, 2008
0

Re: im lost

Click to Expand / Collapse  Quote originally posted by LizR ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkyere is offline Offline
17 posts
since Nov 2008
Dec 15th, 2008
0

Re: im lost

Dont forget to mark the thread as solved.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: extended to integer
Next Thread in Pascal and Delphi Forum Timeline: TXMLDocument --> TListBox (Easy!)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC