1. Home
  2. Computing & Technology
  3. Delphi Programming
RTL Reference|Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link Back

TRAVELING LABEL
Spice up your user interface with a marquee style text. Use marquee style text to display scrolling text that you want to catch your Delphi program users' attention.

Dateline: 07/11/2000

   Marquee Delphi Project
We all know what marquee text is: text that scrolls across the Web browser (like MS IE), or in the status bar of the browser.

To achieve the marquee style text in a Delphi project, we'll use a Label component to display the scrolling text.

About Delphi Programming - Marquee Style Text - Use marquee style text to display scrolling text that you want to catch your Delphi program users' attention. Marquee style text Delphi Project at design time
DOWNLOAD CODE

Customization
We can customize the scrolling text by setting options such as direction of travel and speed. The string (message) displayed by the Label component is held in the Edit component's Text property.
We will also need to place a TTimer and a TUpDown component on the form. The Interval property of the TTimer determines the speed of the scrolling. With the TUpDown component we adjust the scrolling speed (Timer.Interval property).
To set the traveling direction we use TRadioGroup component with two items: Left and Right. For example, when Left option is selected, the text scrolls from right to left.
The "Start/Stop" button is used to stop and start text scrolling.

Code
The main code that scrolls the text lies in the OnTimer event of the TTimer component. Let's see how it looks:

procedure TForm1.Timer1Timer(Sender: TObject);
 var txt : string;
begin
 txt:= lblMarquee.Caption;
 
 if rgDirection.ItemIndex = 0 then {left}
  lblMarquee.Caption :=
    Copy(txt, 2, Length(txt) - 1) + Copy(txt,1,1)
 else {right}
  lblMarquee.Caption:=
    Copy(txt, Length(txt)-1,1)
	+ Copy(txt, 1, Length(txt)-1);
end;

What a confusing code, someone might say. Let's see what happens if the direction is set to left:
Suppose that before the OnTimer event we have the following message displayed in the "traveling" label: "DELPHI". What we want to achieve is to have "ELPHID" displayed after the OnTimer event - this will give the illusion of scrolling. Note that letter "D" comes after "ELPHI": we simply cut the first character of the message and move it to the end of message.

Note: String handling function Copy returns a substring of a string, and Length returns the number of characters in a string.

txt := 'DELPHI';
//cut ELPHI from DELPHI 
Copy(txt, 2, Length(txt) - 1)
//cut D from DELPHI 
Copy(txt,1,1) 

That's it. If you need some help with Marquee code, don't hasitate to mail me.

   More info / related

  • TMarquee
    TMarquee is a scrolling marquee component much like what you see on blimps or stadium scoreboards. TMarquee includes properties that allow the programmer to specify font and alignment of text, the size and shape of the dots, the the speed with which the dots fly across the screen and numerous other properties.

     

    All graphics in this feature created by Zarko Gajic.


  • Post your VCLs and Apps to the Delphi Programming Members Area.
  • What do you think? Join the forum. Discuss real Delphi Programming topics.
  • Talk about Delphi Programming, real time.
  • Sign up for free Delphi Programming newsletter!
  • Explore a list of recommended books in Delphi Programming.
  • Don't wait if you have any questions or comments, mail me.
  • Link to the Delphi Programming site from your Web pages.


  • More Features...
  • Delphi Programming tutorials/articles by date: 2000 | 1999 | 1998 or by TOPIC.
  • NEXT ARTICLE: String Types in Delphi.
    Understanding and managing string data types in Delphi's Object Pascal. Learn about differences between Short, Long, Wide and null-terminated strings.


  • Newsletter...
    Subscribe to the Newsletter
    Name
    Email

    Explore Delphi Programming
    About.com Special Features

    Holiday Central

    What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

    Family Tech Center

    Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

    1. Home
    2. Computing & Technology
    3. Delphi Programming

    ©2009 About.com, a part of The New York Times Company.

    All rights reserved.