Deni Atanasov


I create my own class but when but i cant use function wich is included in this class. This syntax didnt work:

SET DEFAULT TO "D:\working\class"

CREATE CLASSLIB "hostupd"

DEFINE CLASS CHostUpd as Custom

FUNCTION Select

CLOSE TABLES ALL

SET DEFAULT TO "C:\customClass"

SELECT * from merchants

ENDFUNC

ENDDEFINE


Then i call for function with this syntax:



SET DEFAULT TO "D:\working\class"

SET CLASSLIB TO "hostupd" ALIAS chost

*DEFINE CLASS chost as CHostUpd

DEFINE CLASS asd as chost

hupd = CREATEOBJECT('dani.asd')

hupd.Select()



Where is my mystace



Re: DEFINE CLASS problem

CetinBasoz


Deni,

A custom class can be part of a classlib (VCX) or it might be in a prg file. It's not clear where you created it. Anyway here is a sample assuming you want it to be in a prg.

* d:\working\class\mytestclasses.prg
define class CHostUpd as Custom
procedure Select
select * from ("c:\customclass\merchants") && strange but this is a sample anyway
endproc
enddefine

You call it like:

local oTest as "CHostUpd" of "d:\working\class\myTestClasses.prg" && part starting from "as" is optional - intellisense
oTest = newobject("CHostUpd", "d:\working\class\myTestClasses.prg")
oTest.Select()






Re: DEFINE CLASS problem

AndyKr

First, you should not use the name "SELECT" this is a reserved word in VFP and is both an Existing Function in its own right and part of the defined SQL Language. It will work, but it is bad design to use reserved words for your own classes.

Second, CREATE CLASSLIB creates a VISUAL class library - if you are defining a class in a PRG then you do not need to create a class library, the program file itself is the class library, and you use SET PROCEDURE instead of SET CLASSLIB to register it.

So your code should be:

SET DEFAULT TO "D:\working\class"
MODIFY COMMAND prgclasses

DEFINE CLASS CHostUpd as Custom
FUNCTION RunQuery
CLOSE TABLES ALL
SET DEFAULT TO "C:\customClass"
SELECT * from merchants
ENDFUNC
ENDDEFINE


and then to run it you can use either:

SET DEFAULT TO "D:\working\class"
SET PROCEDURE TO prgclasses ADDITIVE
oUpd = CREATEOBJECT( 'cHostUpd' )
oUpd.RunQuery()

OR:
SET DEFAULT TO "D:\working\class"
oUpd = NEWOBJECT( 'cHostUpd', 'prgclasses.prg' )
oUpd.RunQuery()

If you want to use CREATEOBJECT() then you must use SET PROCEDURE first, but if you use NEWOBJECT() you don't have to do that, you can just name the class library (The same is true for visual classes too)







Re: DEFINE CLASS problem

Deni Atanasov

Its works !!!

Thx Cetin ur the teh man :D :P




Re: DEFINE CLASS problem

Deni Atanasov

Ok i will try and that one :D