here i go whit a new problem and yet the same... i think.
on one of the forums i posted my last question in (im lost) the answer was that i could set i to be 0 from start in form load procedure. i did and it worked for a time. now it comes whit this error

Exception class EAccesViolation with message 'Acces violation at adress 004bb914 in module 'security screensaver.exe' read of adress 00000020'.

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


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


end;
end;

i hope someone now the answer cause im simply lost.

first it work, then not and i need to set i to be 0 from the start, then it works... and now suddenly a new error pops up..
i really cant understand the problem.

best regards,
Darkyere

Once again, debug it, follow what "i" is, and see what item you're referencing. Once again, no code tags, so im not even going to bother reading it this time.

You dont seem to do any validation to check wether i is a valid item or not

if i = Listview1.Items.Count -1 then
      begin
        if checkbox1.Checked = true then
            begin
                i := 0;
              item := listview1.Items[i];
              form2.image1.Picture.LoadFromFile(item.Caption);
            end
        else
          begin
            timersec.Enabled := false;
          end;
      end
    else
      begin
        if checkbox2.Checked = true then {if randomize is true}
          begin
	  end
        else
          begin
            i := i + 1;
            item := listview1.Items[i];
            form2.image1.Picture.LoadFromFile(item.Caption); {this is where the error occurs}

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

          end;
      end;

im sorry that i forget to put the code tags on. as u mention this is enforently not the first time.

im rather new at programming and am still learning.

something i dont now for an instance. how do i debug it. ive searched all menus in delphi 2009 after the debug option but i cant seem to find it.

and how do i validate an item to check if tis an valid item?

im sorry that im so much noob i need to get everything in with a spoon. but i hope u understand, and if u do i thank you for your time and understanding.

best regards,
Darkyere

on one of the forums i posted a person created these wonderful line of code


You need to check the value of i and your items.count...

begin
  if YourListView.Items.Count > 0 then begin
    if (i +1 < 0) or (i +1 >= YourListView.Items.Count) then begin
      //reset i to 0 or do something else...
 
    end else begin
      Inc(i);
      //get the item...

    end;
  end else begin
    //so sorry, no items for you...
 
  end;
end;

"There is a theory which states that if ever anybody discovers
exactly what the Universe is for and why it is here, it will
instantly disappear and be replaced by something even more
bizarre and inexplicable. There is another theory which states
that this has already happened."
-- Douglas Adams

Chris

Best regards,
Darkyere

to debug it, I guess you havent found the inserting of break points and stepping through code (or just plain stepping through it from the beginning)

Darkyere,

Check out this site:

http://blogs.codegear.com/nickhodges/2006/08/15/26687

These demonstration files are excellent tutorials for beginners on many features of Delphi including using the debugger. Since your new, it would pay to spend a day going through all of them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.