943,754 Members | Top Members by Rank

Ad:
Dec 10th, 2008
0

to show timeleft to next picture

Expand Post »
Ive made a Security Screensaver whit the options to show random pictures. and it show the start time, time went and then im trying to get it to show time left by minus lasttime whit currenttime

It just doesnt work,
if anyone could help me i would very much appreciate it this is how the code looks:

procedure TForm7.TimerSecTimer(Sender: TObject);
var item : tlistitem; N : integer; randomnr : integer; x : integer; startime : tdatetime; timeleft : tdatetime; lasttime : tdatetime; currenttime : tdatetime;
begin
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
begin

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

form2.Label9.Caption := 'Start time:' + timetostr(now); {here i show the start time}
startime := now; {saves the starttime}

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;


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
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 := 'Processing...';
x := x +1;

form2.Label10.Caption := 'Time went: ' + timetostr(now - startime); { here i show how much time has gone.}
currenttime := now - startime; {here the "Currenttime" gets updated}

timeleft := lasttime - currenttime; {here i calculate timeleft whit lasttime - currenttime. But it count upwards instead of down}
form2.label12.caption := 'Time left:' + timetostr(timeleft); {here i show timeleft}

SetWindowPos(form3.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
end;
end;
end;
form2.ProgressBar2.Position := 0;
end;


if form2.CheckBox1.Checked = false then
begin

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

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);

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

form2.Label11.Caption := 'Time for last picture: ' + timetostr(now - startime); {Here i show how long it was to calculate the last picture}
lasttime := now - startime; {here i save the time for the last image.}

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



end
else
begin
i := i + 1;
item := listview1.Items[i];
form2.image1.Picture.LoadFromFile(item.Caption);

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

Best regards,
Darkyere
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkyere is offline Offline
17 posts
since Nov 2008
Dec 11th, 2008
0

Re: to show timeleft to next picture

Firstly without code tags thats kinda hard to read
Secondly, you dont mention in what way your time remaining hasnt worked.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 11th, 2008
0

Re: to show timeleft to next picture

I would use my time on making the question more understandable if not ive found the answer elsewhere...

here it is.

I think you should declare starttime and lasttime outside of your procedure TimerSecTimer. You will always access to the same two memory spots, which I'm afraid isn't the case when you declare these variables inside TimerSecTimer. This procedure is sort of closed when it's finished, and another is opened next time OnTimer event is fired.

Best regards,
Darkyere
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkyere is offline Offline
17 posts
since Nov 2008
Dec 11th, 2008
0

Re: to show timeleft to next picture

Then mark the thread as solved.

However, a better statement of the problem would have helped too.
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: How to make a screensaver run in delphi 2009 on xp/vista
Next Thread in Pascal and Delphi Forum Timeline: can you help me - 2D array





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


Follow us on Twitter


© 2011 DaniWeb® LLC