Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Using Timer to set Memo.lines Posted by MikeClegg on 30 Oct 2003 at 9:58 AM
Hi
I would like to be able to change a Memo's lines programmatically using a Timer.
I want to be able to switch between
Memo1.lines.loadfromfile('Items.txt') and
Memo1.lines.loadfromfile('Details.txt')
Can I do this using a Timer? or is there another way?

Cheers

Mike
Report
Re: Using Timer to set Memo.lines Posted by Perran on 30 Oct 2003 at 10:14 AM
: Hi
: I would like to be able to change a Memo's lines programmatically using a Timer.
: I want to be able to switch between
: Memo1.lines.loadfromfile('Items.txt') and
: Memo1.lines.loadfromfile('Details.txt')
: Can I do this using a Timer? or is there another way?
:
: Cheers
:
: Mike
:
Sure you can. Set the interval property to the desired time and put the code above inside an OnTimer event handler. You might have to do a clear in between loading the the two text files. I'm not sure about that, but it can certainly be tested easily enough. HTH
Report
Re: Using Timer to set Memo.lines Posted by MikeClegg on 30 Oct 2003 at 11:05 AM
: : Hi
: : I would like to be able to change a Memo's lines programmatically using a Timer.
: : I want to be able to switch between
: : Memo1.lines.loadfromfile('Items.txt') and
: : Memo1.lines.loadfromfile('Details.txt')
: : Can I do this using a Timer? or is there another way?
: :
: : Cheers
: :
: : Mike
: :
: Sure you can. Set the interval property to the desired time and put the code above inside an OnTimer event handler. You might have to do a clear in between loading the the two text files. I'm not sure about that, but it can certainly be tested easily enough. HTH
:
Thanks for the swift response
If I want a label to blink I can code something like...
Label.visible:=not label1.visible
and put that code inside a Timer.
How can I put the Lines.loadfromfile stuff in similar fashion so that the Timer will change the file used each time?
Sorry if I've explained this badly.
Mike
Report
Re: Using Timer to set Memo.lines Posted by Perran on 30 Oct 2003 at 2:10 PM
: : : Hi
: : : I would like to be able to change a Memo's lines programmatically using a Timer.
: : : I want to be able to switch between
: : : Memo1.lines.loadfromfile('Items.txt') and
: : : Memo1.lines.loadfromfile('Details.txt')
: : : Can I do this using a Timer? or is there another way?
: : :
: : : Cheers
: : :
: : : Mike
: : :
: : Sure you can. Set the interval property to the desired time and put the code above inside an OnTimer event handler. You might have to do a clear in between loading the the two text files. I'm not sure about that, but it can certainly be tested easily enough. HTH
: :
: Thanks for the swift response
: If I want a label to blink I can code something like...
: Label.visible:=not label1.visible
: and put that code inside a Timer.
: How can I put the Lines.loadfromfile stuff in similar fashion so that the Timer will change the file used each time?
: Sorry if I've explained this badly.
: Mike
:
The label thing should work. If I were going to code the file loading, I think I'd make an array of string constants to hold the filenames and use a counter to loop thru it. That's just one way. There a lot of others that you or others would think of.
Report
Re: Using Timer to set Memo.lines Posted by zibadian on 30 Oct 2003 at 2:21 PM
This message was edited by zibadian at 2003-10-30 14:27:14

: : : : Hi
: : : : I would like to be able to change a Memo's lines programmatically using a Timer.
: : : : I want to be able to switch between
: : : : Memo1.lines.loadfromfile('Items.txt') and
: : : : Memo1.lines.loadfromfile('Details.txt')
: : : : Can I do this using a Timer? or is there another way?
: : : :
: : : : Cheers
: : : :
: : : : Mike
: : : :
: : : Sure you can. Set the interval property to the desired time and put the code above inside an OnTimer event handler. You might have to do a clear in between loading the the two text files. I'm not sure about that, but it can certainly be tested easily enough. HTH
: : :
: : Thanks for the swift response
: : If I want a label to blink I can code something like...
: : Label.visible:=not label1.visible
: : and put that code inside a Timer.
: : How can I put the Lines.loadfromfile stuff in similar fashion so that the Timer will change the file used each time?
: : Sorry if I've explained this badly.
: : Mike
: :
: The label thing should work. If I were going to code the file loading, I think I'd make an array of string constants to hold the filenames and use a counter to loop thru it. That's just one way. There a lot of others that you or others would think of.
:
In case of such an array, you can use the Tag property as the counter. The code itself is quite simple. Also you don't need to clear the lines before loading, since loading replaces the entire contents.
If you are just switching between two filenames, then you can also use a simple if-then statement. Here's an example:
  if Timer1.Tag = 0 then begin
    Memo1.Lines.LoadFromFile('somefile.txt');
    Timer1.Tag := 1;
  end else begin
    Memo1.Lines.LoadFromFile('someotherfile.txt');
    Timer1.Tag := 0;
  end;

You can also use a case-of in this fashion:
  case Timer1.Tag of
    0: Memo1.Lines.LoadFromFile('file1.txt');
    1: Memo1.Lines.LoadFromFile('file2.txt');
    2: Memo1.Lines.LoadFromFile('file3.txt');
  end;
  if Timer1.Tag = 2 then
    Timer1.Tag := 0
  else
    Timer1.Tag := Timer1.Tag + 1;

This is slightly shorter to code than a complete array, but is less flexible.
Report
Re: Using Timer to set Memo.lines Posted by MikeClegg on 31 Oct 2003 at 6:04 AM
: This message was edited by zibadian at 2003-10-30 14:27:14

: : : : : Hi
: : : : : I would like to be able to change a Memo's lines programmatically using a Timer.
: : : : : I want to be able to switch between
: : : : : Memo1.lines.loadfromfile('Items.txt') and
: : : : : Memo1.lines.loadfromfile('Details.txt')
: : : : : Can I do this using a Timer? or is there another way?
: : : : :
: : : : : Cheers
: : : : :
: : : : : Mike
: : : : :
: : : : Sure you can. Set the interval property to the desired time and put the code above inside an OnTimer event handler. You might have to do a clear in between loading the the two text files. I'm not sure about that, but it can certainly be tested easily enough. HTH
: : : :
: : : Thanks for the swift response
: : : If I want a label to blink I can code something like...
: : : Label.visible:=not label1.visible
: : : and put that code inside a Timer.
: : : How can I put the Lines.loadfromfile stuff in similar fashion so that the Timer will change the file used each time?
: : : Sorry if I've explained this badly.
: : : Mike
: : :
: : The label thing should work. If I were going to code the file loading, I think I'd make an array of string constants to hold the filenames and use a counter to loop thru it. That's just one way. There a lot of others that you or others would think of.
: :
: In case of such an array, you can use the Tag property as the counter. The code itself is quite simple. Also you don't need to clear the lines before loading, since loading replaces the entire contents.
: If you are just switching between two filenames, then you can also use a simple if-then statement. Here's an example:
:
:   if Timer1.Tag = 0 then begin
:     Memo1.Lines.LoadFromFile('somefile.txt');
:     Timer1.Tag := 1;
:   end else begin
:     Memo1.Lines.LoadFromFile('someotherfile.txt');
:     Timer1.Tag := 0;
:   end;
: 

: You can also use a case-of in this fashion:
:
:   case Timer1.Tag of
:     0: Memo1.Lines.LoadFromFile('file1.txt');
:     1: Memo1.Lines.LoadFromFile('file2.txt');
:     2: Memo1.Lines.LoadFromFile('file3.txt');
:   end;
:   if Timer1.Tag = 2 then
:     Timer1.Tag := 0
:   else
:     Timer1.Tag := Timer1.Tag + 1;
: 

: This is slightly shorter to code than a complete array, but is less flexible.
:
Yes, this is just what I need. Thanks
Report
Re: Using Timer to set Memo.lines Posted by MikeClegg on 30 Oct 2003 at 2:32 PM
: : : : Hi
: : : : I would like to be able to change a Memo's lines programmatically using a Timer.
: : : : I want to be able to switch between
: : : : Memo1.lines.loadfromfile('Items.txt') and
: : : : Memo1.lines.loadfromfile('Details.txt')
: : : : Can I do this using a Timer? or is there another way?
: : : :
: : : : Cheers
: : : :
: : : : Mike
: : : :
: : : Sure you can. Set the interval property to the desired time and put the code above inside an OnTimer event handler. You might have to do a clear in between loading the the two text files. I'm not sure about that, but it can certainly be tested easily enough. HTH
: : :
: : Thanks for the swift response
: : If I want a label to blink I can code something like...
: : Label.visible:=not label1.visible
: : and put that code inside a Timer.
: : How can I put the Lines.loadfromfile stuff in similar fashion so that the Timer will change the file used each time?
: : Sorry if I've explained this badly.
: : Mike
: :
: The label thing should work. If I were going to code the file loading, I think I'd make an array of string constants to hold the filenames and use a counter to loop thru it. That's just one way. There a lot of others that you or others would think of.
:
Thanks
I'll give it a try



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.