Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss. print.
CREEPING LINE

The Problem
Visual FoxPro supplies developer by full set of controls for screen form creation. However, sometimes you need to create a vivid and remembered form. In this case it is appropriate use such elements as animated images, creeping line and etc.
Unfortunately FoxPro has not classes prepared for use. As a result of it many developers find and use ActiveX controls. Usage of ActiveX occasionally is very problematically, especially in Visual FoxPro. You may have problem when you try to implant element into form or when you want to distribute an application.

The Solution
In many cases a search of appropriate ActiveX control is not best choice. You can try to create your own class based on Visual FoxPro base classes. This class will have the wanted properties and the required methods. Let's take up a creation of such class. It may be a Creeping Line class.

Firstly, we must form requirements to new class. For example they are:

- An object of the class must be easy to place itself on a form like Label class.
- It must have properties of Label class
- It must have additional properties and methods controlling speed, start and stop of the Creeping Line.

Secondly, we need to choose a correct base class. From the generated requirements it is visible, that the new class should inherit properties of Label class and Timer class.

We choose Container class as base class to implement such inheritance. It allows us to encapsulate the Label object and the Timer object into Creeping Line class.


So, we can define a set of properties and methods for our class:
- Methods: Stop(), Start()
- Properties: Interval, FontName, FontSize, FontBold, FontItalic, ForeColor, Alignment.
- Class definition:
DEFINE CLASS runline AS CONTAINER
	WIDTH = 158
	HEIGHT = 28
	BACKSTYLE = 0
	BORDERWIDTH = 0
	NAME = "runline"
	*-- Specifies the text displayed in an object's caption.
	CAPTION = ‘’
	*-- Specifies if the text is italic.
	FONTITALIC = .F.
	*-- Specifies if the text is bold.
	FONTBOLD = .F.
	*-- Specifies the font size for text displayed with an object.
	FONTSIZE = 10
	*-- Specifies the name of the font used to display text.
	FONTNAME = 'Arial'
	*-- Specifies the number of milliseconds between
	*-- calls to a Timer control's Timer event.
	INTERVAL = 500
	*-- Specifies the alignment of text associated with a control.
	ALIGNMENT = 0
	ADD OBJECT TEXT AS LABEL WITH ;
		AUTOSIZE = .F., ;
		BACKSTYLE = 0, ;
		CAPTION = "Label1", ;
		HEIGHT = 17, ;
		LEFT = 0, ;
		TOP = 6, ;
		WIDTH = 40, ;
		NAME = "Text"
	ADD OBJECT TIMER AS TIMER WITH ;
		TOP = 3, ;
		LEFT = 129, ;
		HEIGHT = 23, ;
		WIDTH = 23, ;
		INTERVAL = 500, ;
		NAME = "Timer"
	PROCEDURE caption_access
		RETURN THIS.TEXT.CAPTION
	ENDPROC
	PROCEDURE caption_assign
		LPARAMETERS vNewVal
		THIS.TEXT.CAPTION = m.vNewVal
	ENDPROC
	PROCEDURE forecolor_access
		RETURN THIS.TEXT.FORECOLOR
	ENDPROC
	PROCEDURE forecolor_assign
		LPARAMETERS vNewVal
		THIS.TEXT.FORECOLOR = m.vNewVal
	ENDPROC
	PROCEDURE fontitalic_access
		RETURN THIS.TEXT.FONTITALIC
	ENDPROC
	PROCEDURE fontitalic_assign
		LPARAMETERS vNewVal
		THIS.TEXT.FONTITALIC = m.vNewVal
	ENDPROC
	PROCEDURE fontbold_access
		RETURN THIS.TEXT.FONTBOLD
	ENDPROC
	PROCEDURE fontbold_assign
		LPARAMETERS vNewVal
		THIS.TEXT.FONTBOLD = m.vNewVal
	ENDPROC
	PROCEDURE fontsize_access
		RETURN THIS.TEXT.FONTSIZE
	ENDPROC
	PROCEDURE fontsize_assign
		LPARAMETERS vNewVal
		THIS.TEXT.FONTSIZE = m.vNewVal
	ENDPROC
	PROCEDURE fontname_access
		RETURN THIS.TEXT.FONTNAME
	ENDPROC
	PROCEDURE fontname_assign
		LPARAMETERS vNewVal
		THIS.TEXT.FONTNAME = m.vNewVal
	ENDPROC
	PROCEDURE interval_access
		RETURN THIS.TIMER.INTERVAL
	ENDPROC
	PROCEDURE interval_assign
		LPARAMETERS vNewVal
		THIS.TIMER.INTERVAL = m.vNewVal
	ENDPROC
	PROCEDURE START
		THIS.TIMER.ENABLED=.T.
	ENDPROC
	PROCEDURE stop
		THIS.TIMER.ENABLED=.F.
	ENDPROC
	PROCEDURE alignment_access
		RETURN THIS.TEXT.ALIGNMENT
	ENDPROC
	PROCEDURE alignment_assign
		LPARAMETERS vNewVal
		THIS.TEXT.ALIGNMENT = m.vNewVal
	ENDPROC
	PROCEDURE INIT
		THIS.TEXT.WIDTH=THIS.WIDTH
		THIS.TEXT.HEIGHT=THIS.HEIGHT
	ENDPROC
	PROCEDURE TIMER.TIMER
		LOCAL lcFirstChar, lcSubLine
		lcFirstChar=SUBSTR(THIS.PARENT.TEXT.CAPTION,1,1)
		lcSubLine=SUBSTR(THIS.PARENT.TEXT.CAPTION,2)
		THIS.PARENT.TEXT.CAPTION=lcSubLine+lcFirstChar
	ENDPROC
ENDDEFINE


The Conclusion
Created class is easy to be placed on a form and to be controlled by an application. It works like standard Visual FoxPro classes.

Download code
You can download this article and the program sample here. The download
is a zipfile. Its size is 18.877 bytes.

ABOUT THE AUTHOR: VLADIMIR TRUKHIN

Vladimir Trukhin Vladimir Trukhin is Visual FoxPro developer and author. He has been developing program systems and applications since 1983. He specializes in software system development, user interface design, object oriented programming, developer support, training and other services. Vladimir has written for FoxTalk magazine. Visual FoxPro is his everyday tool and assistant. You can contact him by e-mail at vlt@votges.ru. You can find additional information about Vladimir on home page at http://www.geocities.com/vhpcg/resume.html.

FEEDBACK

Sajan Jacob @ 6/22/2011 9:37:02 AM
Can you provide me source code of runline form.
I tried to paste above coding in the form. which is not working.
I was looking for the same in my application to be run company name, current date, and time to run like as in your runline.app

Sajan Jacob



Your Name: 
Your Feedback: 

Spam Protection:
Enter the code shown: