using timed events to create a script for a scroller

I am trying to use a freeware componet called LedScreen to do some neat scrolling tricks.  This is working out fine creating a single string and having it scroll on a seperate form.

What i want to do is to create a script using some kind of timed events so i can introduce a new string and have it appear after the previous has finished scrolling.  so far its not working out at all and I can't figure out how to do it.

The scroller has Finish parameter that supposedly signals a 0 to indicate when the scroll has done but its at zero the second the line is excuted.

All this needs to be done so when i click back to the main form the scroller will disappear.

if the code fragment doesnt help maybe i can email the source code of the component to someone.

thanks.

TLedScreen = class(TCustomControl)
  private
    Leds         : TBitmap;
    ScreenImage  : TBitmap;
    ScreenData   : Array [1..90] of Byte;
    TextData     : PTextData;
    TextLength   : Integer;
    TextSize     : Integer;
    Timer        : TTimer;
    First,Last   : Integer;
    ScrollCount  : Integer;
    Loops        : Integer;
    ShiftCount   : Integer;
    LeftShift    : Boolean;
    LastLine     : Integer;
    FinishTag    : Word;
    FinishedRows : Array [0..7] of Boolean;
    ScreenBits   : Array [1..180,0..7] of Boolean;
    VisibleLeds  : Integer;
    VisibleCols  : Integer;
    FLightColor  : TColor;
    FDarkColor   : TColor;
    FBackground  : TColor;
    FFinish      : Word;
    FOnFinish    : TNotifyEvent;
    FAbout       : TAboutProperty;
    procedure SetLightColor(Value : TColor);
    procedure SetDarkColor(Value : TColor);
    procedure SetBackground(Value : TColor);
  protected
    procedure CreateLeds; virtual;
    procedure DrawLed(IsOn : Boolean; X,Y : Integer); virtual;
    procedure CreateText(Text : String; FillLine : Boolean; Alignment : TAlignment); virtual;
    procedure LeftScroll(Sender : TObject); virtual;
    procedure RightScroll(Sender : TObject); virtual;
    procedure DownScroll(Sender : TObject); virtual;
    procedure UpScroll(Sender : TObject); virtual;
    procedure LeftSlideIn(Sender : TObject); virtual;
    procedure RightSlideIn(Sender : TObject); virtual;
    procedure UpSlideIn(Sender : TObject); virtual;
    procedure DownSlideIn(Sender : TObject); virtual;
    procedure LeftSlideOut(Sender : TObject); virtual;
    procedure RightSlideOut(Sender : TObject); virtual;
    procedure UpSlideOut(Sender : TObject); virtual;
    procedure DownSlideOut(Sender : TObject); virtual;
    procedure LeftSlideLinesIn(Sender : TObject); virtual;
    procedure RightSlideLinesIn(Sender : TObject); virtual;
    procedure LeftSlideLinesOut(Sender : TObject); virtual;
    procedure RightSlideLinesOut(Sender : TObject); virtual;
    procedure UpSlideLinesIn(Sender : TObject); virtual;
    procedure DownSlideLinesIn(Sender : TObject); virtual;
    procedure UpSlideLinesOut(Sender : TObject); virtual;
    procedure DownSlideLinesOut(Sender : TObject); virtual;
    procedure Paint; override;
  public
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
    procedure ScrollLeft(Text : String; Loop : Integer; Finish : Word); virtual;
    procedure ScrollRight(Text : String; Loop : Integer; Finish : Word); virtual;
    procedure ScrollDown(Text : String; Loop : Integer; Finish : Word;
      Alignment : TAlignment); virtual;
    procedure ScrollUp(Text : String; Loop : Integer; Finish : Word;
      Alignment : TAlignment); virtual;
    procedure SlideInLeft(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideInRight(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideInUp(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideInDown(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideOutLeft(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideOutRight(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideOutUp(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideOutDown(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideLinesInLeft(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideLinesInRight(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideLinesOutLeft(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideLinesOutRight(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideLinesInUp(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideLinesInDown(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideLinesOutUp(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    procedure SlideLinesOutDown(Text : String; Finish : Word; Alignment : TAlignment); virtual;
    property Finish : Word read FFinish;
  published
    property LightColor : TColor read FLightColor write SetLightColor;
    property DarkColor  : TColor read FDarkColor write SetDarkColor;
    property Background : TColor read FBackground write SetBackground;
    property OnFinish   : TNotifyEvent read FOnFinish write FOnFinish;
    property About      : TAboutProperty read FAbout write FAbout;
  end;
maidenbeast666Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
shaneholmesConnect With a Mentor Commented:
OK this example will change the string evry five seconds

Drop a LedScreen component on your form, A TListBox, & a TTimer & two buttons (Start & Stop)

Fill the TListBox with Strings (or sentences)

and use the folowing code

//LedScreen Components OnFinish event
procedure TForm1.LedScreen1Finish(Sender: TObject);
begin
 inc(strIndex);
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
 strIndex:= 0;
end;


//Start Button
procedure TForm1.Button1Click(Sender: TObject);
begin
 Timer1.Enabled:= True;
 LedScreen1.ScrollLeft(ListBox1.Items[strIndex],1,1);
end;


//timer onTimer event
procedure TForm1.Timer1Timer(Sender: TObject);
begin
 LedScreen1.ScrollLeft(ListBox1.Items[strIndex],1,1);
end;


//Stop Button
procedure TForm1.Button2Click(Sender: TObject);
begin
 Timer1.Enabled:= False;
end;
0
 
shaneholmesCommented:
I would create TStringList and store all of your strings to display in that list

 
MyStringList:= TStringList.Create;

Note: Dont forget to free it when your done with it

MyStringList.Free;

in the OnFinish event of the component,

1.) clear the text

2.) call the sleep function sleep(X) x= number of seconds (example 1000 = 1 sec)

3.) get new text from stringlist to display (note pull from top of stringlist - Example MyStringList[0])

4.) Delete top list item and prepare for next string in the list to display

 MySTringList.Delete(0);

Shane
0
 
shaneholmesCommented:
If you dont want to delete the strings from the StringList, ratehr you would like to cycle back through them

then do the following

Create a Index variable to keep track of the index you are on in the StringList

var
 StrIndex: Integer

in the OnFinish event of the component,

1.) clear the text

2.) call the sleep function sleep(X) x= number of seconds (example 1000 = 1 sec)

3.) get new text from stringlist to display ( Example MyStringList[StrIndex])

4.) Increment StrIndex - Example : inc(StrIndex)

Shane




0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
maidenbeast666Author Commented:
i tried calling the sleep function before coming here and the problem with it is that it hangs up the application completely.

i am also having trouble with accessing the onFinish event to the component.  whats the code for that exactly?

i'm not so good at this OO stuff, i've come from a straight c background.
0
 
shaneholmesCommented:
Its an event called by the component (if not nil - assigned by you) when the text has finished scrolling.

SHane
0
 
shaneholmesCommented:
can you send me the component and i will take a look at it?

holmesshane AT charter DOT net

Shane
0
 
maidenbeast666Author Commented:
thanks shane, just emailed it.
0
 
shaneholmesCommented:
The component wasn't attached!

Shane
0
 
shaneholmesCommented:
Here is the code addition to make it recycle through

//LedScreen Components OnFinish event
procedure TForm1.LedScreen1Finish(Sender: TObject);
begin
 if StrIndex = ListBox1.Items.Count - 1 do //if its the last item
  STrIndex:= 0  //reset to first item
 else
  inc(strIndex); //set to next item
end;


Shane
0
 
maidenbeast666Author Commented:
hmm well this kind of works.

the problem i have with this is 2 things.

1.  the scoller keeps repeating the first message until i press button2.  then it finishes the current message and starts the second the message.

2.  manually controlling the onfinish isn't allowing my brain to see the solution of having no user intervention on this.  

the thing i am trying to achieve is various scrolling types with different strings when someone clicks my "About"  screen, so my real problem is how do i insert events in realtime without any user intervention.  

what i need is the second the scoller finishes the first message it automatically picks up each subsequent message one after the other.  do you see what i mean?
0
 
shaneholmesCommented:
You call also create a TRadioGroup and add all the methods

 ScrollLeft
 ScrollRight

then in the Start Buttons OnCLick event

test for the index of the TRadioGroup to decide which method to call

example

//Start Button
procedure TForm1.Button1Click(Sender: TObject);
begin
 Timer1.Enabled:= True;
 case RadioGroup1.ItemIndex of
  0: LedScreen1.ScrollLeft(ListBox1.Items[strIndex],1,1);
  1: LedScreen1.ScrollRight(ListBox1.Items[strIndex],1,1);
  2: etc.....
 end;
end;
0
 
shaneholmesCommented:
You didn't code it the way I presented it to you

It will move from one message to the next / with 5 seconds in between (unless you change this)

I tested it and it worked great

Shane
0
 
maidenbeast666Author Commented:
ah seems its my fault.

increasing the timer to 3000 fixed it.

thanks shane.
0
 
shaneholmesCommented:
Great, glad ya got it working

Shane
0
 
maidenbeast666Author Commented:
set the timer to 1000 you'll see what i mean :P

right this is perfect now.  i will try and implement using different scroll types for each message and see how it fares.
0
 
shaneholmesCommented:
Good Luck!

Shane
0
All Courses

From novice to tech pro — start learning today.