The following is a sample program that I used to test some of the syntax. The sample shows:
- Property declaration
- Property initialization
- Add Object clause
- Method declaration
- Access methods
- Custom class and Collection Class to support
Code: Select all
FUNCTION Start() AS VOID
LOCAL oPerson //ASPerson
// VFP compatible object creation, Checks for type at runtime
oPerson := CreateObject("Person", "Fabrice","Foray")
oPerson := Person{"Fabrice","Foray"}
? "First:", oPerson:FirstName
? "Last :", oPerson:LastName
? "Full :", oPerson:
? "Address:"
? oPerson:Address:AddressBlock
WAIT
RETURN
DEFINE CLASS Address AS Custom
PUBLIC Street, Zip, City as STRING // note that we have added the AS Type clause,
// Possible (optional) modifiers are PUBLIC, PROTECT, HIDDEN, INTERNAL
Street = ""
Zip = ""
City = ""
FUNCTION AddressBlock_Access AS STRING // Access method
RETURN This.Street+CRLF+This.Zip+" "+This.City
ENDFUNC
END DEFINE
DEFINE CLASS Person AS Custom
// Untyped. properties
FirstName, LastName
FirstName = "John"
LastName = "Doe"
ADD OBJECT Address AS Address WITH Street = "Main Street 1", ZIP = "12345", City = "Phoenix"
// Access method
FUNCTION FullName_Access as string
RETURN This.FirstName+" "+This.LastName
ENDFUNC
// Init event handler gets called after object has been created.
PROCEDURE init(cFirst, cLast)
DODEFAULT()
FirstName := cFirst
LastName := cLast
END DEFINE
FirstName property gets compiled to:
Code: Select all
public virtual XSharp.__Usual FirstName
{
get
{
return _GetProperty("FirstName");
}
set
{
_SetProperty("FirstName", value);
}
}
Code: Select all
public virtual string AddressBlock => Street + "rn" + Zip + " " + City;
We are wrapping up this build for testing this weekend.
Robert