943,866 Members | Top Members by Rank

Ad:
Nov 19th, 2008
0

Need help whit code

Expand Post »
I have made this application where theres a tlistview whit image destinations in it.

Then i got a timer to shift the picture.

then ive addet a random function to shuffle through the picture.

now what i want to happen is that the same picture dont get shown twice.

So what i tried was to put the number of the picture in another tlistview and make a "While do" to check if randomly generated number is shown in the list.

this is the code ive tried using.

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

x := 0;

While x<listview2.Items.Count - 1 do
begin
if listview2.Items[x].Caption = inttostr(randomnr) then
begin
randomnr := random(listview1.Items.Count -1);
x := 0;
end;
x := x +1;
end;

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

listview2.Items.Add.Caption := inttostr(randomnr);

This is how the form looks like
http://img.photobucket.com/albums/v2...ilesDialog.jpg

All help is apreciatet

Best regards,
Darkyere
Last edited by darkyere; Nov 19th, 2008 at 4:16 pm. Reason: Not well enough explained
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkyere is offline Offline
17 posts
since Nov 2008
Nov 20th, 2008
0

Re: Need help whit code

Click to Expand / Collapse  Quote originally posted by darkyere ...
While x<listview2.Items.Count - 1 do
begin
if listview2.Items[x].Caption = inttostr(randomnr) then
begin
randomnr := random(listview1.Items.Count -1);
x := 0;
end;
x := x +1;
end;

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

listview2.Items.Add.Caption := inttostr(randomnr);
You might want to skip the while loop and try:
If listview2.findcaption (1,inttostr(randomnr)), false, true, true)=nil Then //no match found


ALso check the parameters to see if they are correct
Reputation Points: 11
Solved Threads: 11
Junior Poster in Training
jsosnowski is offline Offline
68 posts
since Nov 2007
Nov 21st, 2008
0

Re: Need help whit code

I found a solution elsewhere my code now looks like:
for n:=1 to ListView1.Items.Count do begin
randomnr := random(listview1.Items.Count -1);

if checkbox3.Checked = true then
begin

x := 0;

While x<listview2.Items.Count - 1 do begin
if inttostr(randomnr) = listview2.Items[x].Caption then
begin
randomnr := random(listview1.Items.Count -1);
x := 0;
end
else x := x +1;
end;
end;



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

listview2.Items.Add.Caption := inttostr(randomnr);

if listview1.Items.Count -1 = listview2.Items.Count -1 then listview2.Clear;

end;
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkyere is offline Offline
17 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: Bug in Free Pascal
Next Thread in Pascal and Delphi Forum Timeline: delphi





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


Follow us on Twitter


© 2011 DaniWeb® LLC