to show timeleft to next picture

Reply

Join Date: Nov 2008
Posts: 17
Reputation: darkyere is an unknown quantity at this point 
Solved Threads: 0
darkyere darkyere is offline Offline
Newbie Poster

to show timeleft to next picture

 
0
  #1
Dec 10th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: to show timeleft to next picture

 
0
  #2
Dec 11th, 2008
Firstly without code tags thats kinda hard to read
Secondly, you dont mention in what way your time remaining hasnt worked.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 17
Reputation: darkyere is an unknown quantity at this point 
Solved Threads: 0
darkyere darkyere is offline Offline
Newbie Poster

Re: to show timeleft to next picture

 
0
  #3
Dec 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: to show timeleft to next picture

 
0
  #4
Dec 11th, 2008
Then mark the thread as solved.

However, a better statement of the problem would have helped too.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC