I was wondering if anyone can help me here, I need to figure out how to delay my program at certain intervals. I have quite a few pictures on my form and want to make each image appear a certain time apart (about 3-5 seconds will do) but each time i try use an on form create or activate procedure it just doesn't work! I'm not sure how to use the timer so i was wondering if anyone could help me. Is it better to use the timer? am i using the sleep procedure wrong? it's so darn confusing... pls pls pls help!!
Comments
: to delay my program at certain intervals. I have quite a few
: pictures on my form and want to make each image appear a certain
: time apart (about 3-5 seconds will do) but each time i try use an on
: form create or activate procedure it just doesn't work! I'm not sure
: how to use the timer so i was wondering if anyone could help me. Is
: it better to use the timer? am i using the sleep procedure wrong?
: it's so darn confusing... pls pls pls help!!
:
In this case it is easier to use a TTimer component. In the OnTimer() you can increase some sort of counter, which keeps track of the image to display. The following example code assumes a TTimer and a TImage component, and several image files numbered 0 to some number:
[code]
procedure TForm1.Timer1OnTimer(Sender: TObject);
var
filename: string;
begin
filename := Format('%d.jpg', [Timer1.Tag]);
// Timer1.Tag property is used as counter.
// Image filenames are: 0.jpg, 1.jpg, 2.jpg, etc.
if not FileExists(filename) then
begin
Timer1.Tag := 0; // If end of image is reached, start again
filename := Format('%d.jpg', [Timer1.Tag]);
end;
Image1.Picture.LoadFromFile(filename);
Timer1.Tag := Timer1.Tag + 1; // prepare the next filename
end;
[/code]
This code can be modified to take the filenames from an array of string or a TStrings object.
: : to delay my program at certain intervals. I have quite a few
: : pictures on my form and want to make each image appear a certain
: : time apart (about 3-5 seconds will do) but each time i try use an on
: : form create or activate procedure it just doesn't work! I'm not sure
: : how to use the timer so i was wondering if anyone could help me. Is
: : it better to use the timer? am i using the sleep procedure wrong?
: : it's so darn confusing... pls pls pls help!!
: :
: In this case it is easier to use a TTimer component. In the
: OnTimer() you can increase some sort of counter, which keeps track
: of the image to display. The following example code assumes a TTimer
: and a TImage component, and several image files numbered 0 to some
: number:
: [code]:
: procedure TForm1.Timer1OnTimer(Sender: TObject);
: var
: filename: string;
: begin
: filename := Format('%d.jpg', [Timer1.Tag]);
: // Timer1.Tag property is used as counter.
: // Image filenames are: 0.jpg, 1.jpg, 2.jpg, etc.
: if not FileExists(filename) then
: begin
: Timer1.Tag := 0; // If end of image is reached, start again
: filename := Format('%d.jpg', [Timer1.Tag]);
: end;
: Image1.Picture.LoadFromFile(filename);
: Timer1.Tag := Timer1.Tag + 1; // prepare the next filename
: end;
: [/code]:
: This code can be modified to take the filenames from an array of
: string or a TStrings object.
thank you so very much! I managed to get it to work thanks to you.