Jump to content

im lost

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Darkyere

Darkyere

    Newbie

  • Members
  • PipPip
  • 13 posts
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..

Edited by WingedPanther, 14 December 2008 - 02:06 PM.
add code tags (the # button)


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I would guess that this line is your issue:
    for n:=1 to ListView1.Items.Count do

It should probably be
    for n:=0 to ListView1.Items.Count-1 do

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Darkyere

Darkyere

    Newbie

  • Members
  • PipPip
  • 13 posts
yes, indeed i needed to fix that. Thank you.

but infortently it didn't stop the error from happening

best regards,
darkyere

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Do you know what line the error occurs on? Have you traced through the code as it runs?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog