Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trying to create a class
Message
 
To
27/11/2001 14:42:03
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00586547
Message ID:
00586613
Views:
13
This message has been marked as a message which has helped to the initial question of the thread.
Hi Michael,

Just to add to what everyone else said. Think of a class as a template that an object is created from. When you issue a NewObject() or CreateObject(), the new object is based on it's class (template).

To create your class, simply put the code in a .prg and save it. You will need to issue a set procedure to MyClass.prg prior to the CreateObject() call.

If you want to create a .com object you will need to create a new project, add the .prg to it, add the OlePublic keyword at the end of the define class line in the .prg, and then compile the project with any of the COM server options.

You may want to read up on the "Define Class" command in the VFP help.

hth

>This is my first foray into creating a class. I have done some reading but I am still confused. The outcome of this is that I want to be able to creat a .com object. I got the following code from a VFP 6 book, it was labelled as "Source Code for the Timesheet Program Exported from the Class Browser". My question is this: How do I create a class to begin with...and how do I add the following code to it? I tried simply running this code to create a class with no success. Any help would be greatly appreciated.
>
>
DEFINE CLASS timetrans AS line
>
>	Height = 17
>	Width = 100
>	cclient = ("")
>	cdescription = ("")
>	*--Service Code
>	cservice = ("")
>	*--Billing Amount
>	namount = 0.00
>	nrate = 0.00
>	*--The employee who did the work
>	cemployee = ("")
>	*--Date of service
>	ddate = {}
>	*--Hours worked
>	nhours = 0.00
>	Name = "timetrans"
>
>	PROTECTED PROCEDURE CDESCRIPTION_ASSIGN
>		LPARAMETERS vNewVal
>
>	*--Our billing program only prints up to 600 characters for the description
>
>		IF LEN(vNewVal) > 600
>			vNewVal = LEFT(vNewVal, 600)
>		ENDIF
>		this.cdescription = m.vNewVal
>	ENDPROC
>
>	*--sAVES A TRANSACTION TO THE TABLE
>	PROCEDURE save
>	LOCAL lnSelect
>	lnSelect = Select()
>
>	IF !USED("tsTrans")
>		USE tstrans
>	ENDIF
>
>	SELECT tstrans
>	APPEND BLANK
>
>	WITH this
>		REPLACE ;
>			cemployee WITH .cemployee, ;
>			ddate WITH .ddate, ;
>			cclient with .cclient, ;
>			cservice WITH .cservice, ;
>			mDesc WITH .cdescription, ;
>			nhours with .nhours, ;
>			nrate WITH .nrate, ;
>			namount WITH .namount
>	ENDWITH
>
>	SELECT (lnSelect)
>ENDPROC
>
>	*--Clears out everything for a new record to be defined
>	PROCEDURE add
>	WITH this
>		.ddate = {}
>		.cclient = ""
>		.cservice = ""
>		.cdescription = ""
>		.nhours = 0.00
>		.nrate = 0
>		.namount = 0
>		.cemployee = ""
>	ENDWITH
>ENDPROC
>
>	PROTECTED PROCEDURE cservice_assign
>		LPARAMETERS vNewVal
>
>	*--When we get a service in, we need to get the rate so we can do the math on it and then
>	*--save it to the table.
>
>		LOCAL lnSelect, lcOldExact
>		lsSelect = SELECT()
>
>		this.cservice = vNewVal
>
>	*--Check that we got a character value
>
>		IF TYPE("vNewVal") # "C"
>			IF INLIST(_vfp.startmode, 1,2,3)
>				this.cStatus = "cService Error"
>			ELSE
>				MESSAGEBOX("cService expects a CHARACTER type value.", 16)
>			ENDIF
>			RETURN
>		ENDIF
>
>		IF !USED("services")
>			USE services
>		ENDIF
>
>		SELECT services
>		SET ORDER TO service
>
>		lcOldExact = SET("exact")
>		SET EXACT ON
>		SEEK UPPER(ALLTRIM(vNewVal))
>
>		IF !FOUND() OR EMPTY(vNewVal)
>			this.nrate = services.nrate
>		ENDIF
>
>		SET EXACT &lcOldExact
>		SELECT (lnSelect)
>	ENDPROC
>
>	PROTECTED PROCEDURE nrate_asign
>		LPARAMETERS vNewVal
>
>	*--Calculate the billing amount for this number
>
>		this.nrate = vNewVal
>
>		IF TYPE("vNewVal") # "N"
>			IF INLIST(_vfp.startmode, 1,2,3)
>				this.cStatus = "Rate Error"
>			ELSE
>				MESSAGEBOX("nRate expects a NUMERIC type value.", 16)
>			ENDIF
>		ELSE
>			this.namount = this.nrate * this.nhours
>		ENDIF
>	ENDPROC
>
>	PROTECTED PROCEDURE nhours_assign
>		LPARAMETERS vNewVal
>
>	*--Calculate the billing amount for this number
>
>		this.nhours = vNewVal
>
>		IF TYPE("vNewVal") # "N"
>			IF INLIST(_vfp.startmode, 1,2,3)
>				this.cStatus = "Hours Error"
>			ELSE
>				MESSAGEBOX("nHours expects a NUMERIC type value.", 16)
>			ENDIF
>		ELSE
>			this.namount = this.nrate * this.nhours
>		ENDIF
>	ENDPROC
>
>ENDDEFINE
>*
>*--EndDefine: timetrans
>
Roi
'MCP' Visual FoxPro

In Rome, there was a poem.
About a dog, who found two bone.
He lick the one, he lick the other.
He went pyscho, he drop dead!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform