Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating Class

3 views
Skip to first unread message

CNT LM

unread,
Jun 24, 2007, 10:50:23 PM6/24/07
to
Probably this is a very basic question for all of you, but I'm still having
problems getting used to VF9.

I'm trying to create a class that only contains code, functions and
procedures. I'm doing so to be able to call this functions or procedures
from anywhere within my program.
The code for this class is not object related, basically it's a group of
mathematical functions and procedures.
How does one transforms a PRG into a class?


Stefan Wuebbe

unread,
Jun 25, 2007, 4:04:26 AM6/25/07
to

"CNT LM" <serv...@contor.pt> schrieb im Newsbeitrag
news:467f2e33$0$28010$a729...@news.telepac.pt...

When you have a PRG containing something like
Function x()
&& code
EndFunc
Function y()
&& code
Endfunc

, you can simply add a Define Class / Enddefine statement as the first
and last line of the file:
Define Class myFunctions As Custom && or Session, whatever
Function x()
&& code
EndFunc
Function y()
&& code
Endfunc
EndDefine

In your calling method you can use NewObject for example:
LOCAL loClass
loClass = NEWOBJECT('myFunctions','progs\myLibs.prg')
? loClass.x()

hth
-Stefan

--
|\_/| ------ ProLib - programmers liberty -----------------
(.. ) Our MVPs and MCPs make the Fox run....
- / See us at www.prolib.de or www.AFPages.de
-----------------------------------------------------------


Olaf Doschke

unread,
Jun 25, 2007, 6:52:41 AM6/25/07
to
> , you can simply add a Define Class / Enddefine statement as the first
> and last line of the file:
> Define Class myFunctions As Custom && or Session, whatever
...
> EndDefine

If functions call each other, eg y() calls x(), you need
to change the call of x() to this.x() within the class methods.

Bye, Olaf.


Paul Pedersen

unread,
Jun 25, 2007, 11:24:21 AM6/25/07
to
To access an object from anywhere in the program, you can use a global
variable as a reference. In general though, global variables are to be
avoided. You're better off limiting access to variables to those systems
that need it.

But here's a very simple example:

PUBLIC myObj
myObj = CREATEOBJECT("myobject")
myObj.sayhi

DEFINE CLASS myobject AS CUSTOM
PROCEDURE sayhi
WAIT WINDOW "Hi there"
ENDDEFINE


"CNT LM" <serv...@contor.pt> wrote in message
news:467f2e33$0$28010$a729...@news.telepac.pt...

0 new messages