| 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.

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 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.
More Features...
Understanding and managing string data types in Delphi's Object Pascal. Learn about differences between Short, Long, Wide and null-terminated strings.
Newsletter...

