Solved

using timed events to create a script for a scroller

Posted on 2004-04-06
16
241 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
  • 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
 
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 100 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now