Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using timed events to create a script for a scroller

Posted on 2004-04-06
16
Medium Priority
?
249 Views
Last Modified: 2010-04-05
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;
0
Comment
Question by:maidenbeast666
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 5
16 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10767757
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10767783
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
 

Author Comment

by:maidenbeast666
ID: 10767934
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10768003
Its an event called by the component (if not nil - assigned by you) when the text has finished scrolling.

SHane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10768013
can you send me the component and i will take a look at it?

holmesshane AT charter DOT net

Shane
0
 

Author Comment

by:maidenbeast666
ID: 10768060
thanks shane, just emailed it.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10768085
The component wasn't attached!

Shane
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 400 total points
ID: 10768506
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10768624
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
 

Author Comment

by:maidenbeast666
ID: 10768738
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10768751
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10768770
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
 

Author Comment

by:maidenbeast666
ID: 10768777
ah seems its my fault.

increasing the timer to 3000 fixed it.

thanks shane.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10768811
Great, glad ya got it working

Shane
0
 

Author Comment

by:maidenbeast666
ID: 10768816
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10768831
Good Luck!

Shane
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question