VHP Computing Group. Home Page.  
TechnologiesSpecialistsDownloadLinksSign GuestbookView Guestbook

15 September, 2000
Vladimir Trukhin
Senior Software Engineer
JSC "Votkinsk Hydroelectric Power Plant"
Fax: +7 (34241) 63297
E-mail:
vlt@votges.ru

Creeping line.

The Problem

Visual FoxPro supplies developer with a full set of controls for a screen forms creation. However, sometimes you need create a vivid and showy form. In this case it is appropriate to use such elements as animated images, creeping line and etc.

Unfortunately FoxPro has not classes, which would be designed for such 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 a 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 defination:
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.

You can download the article and program sample from file: runline.zip Size: 19KB.
There is a Russian version of article in
file artl003r.zip Size: 13KB.


Home Page | Technologies | Specialists | Download | Links | Sign Guestbook | View Guestbook