Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Using Timer to set Memo.lines

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

Comments

  • PerranPerran Posts: 241Member
    : 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
  • MikeCleggMikeClegg Posts: 5Member
    : : 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
  • PerranPerran Posts: 241Member
    : : : 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.
  • zibadianzibadian Posts: 6,349Member
    [b][red]This message was edited by zibadian at 2003-10-30 14:27:14[/red][/b][hr]
    : : : : 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:
    [code]
    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;
    [/code]
    You can also use a case-of in this fashion:
    [code]
    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;
    [/code]
    This is slightly shorter to code than a complete array, but is less flexible.
  • MikeCleggMikeClegg Posts: 5Member
    : : : : 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
  • MikeCleggMikeClegg Posts: 5Member
    : [b][red]This message was edited by zibadian at 2003-10-30 14:27:14[/red][/b][hr]
    : : : : : 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:
    : [code]
    : 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;
    : [/code]
    : You can also use a case-of in this fashion:
    : [code]
    : 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;
    : [/code]
    : This is slightly shorter to code than a complete array, but is less flexible.
    :
    Yes, this is just what I need. Thanks
Sign In or Register to comment.