Page 1 of 1

Class for PB

Posted: Thu May 18, 2017 6:48 pm
by GPI
At the moment, PB does support Classes/Objects - with Interfaces and structures there are the basic components of object available and with some code you can use them. The only thing that is missing, is a declaration of classes.
I'm only want something, that is technically already possibly!

for declaration:

Code: Select all

Class cFirst ; Extends Nothing ;)
  Method1.i(long1.l, long2.l)
  property1.d
EndClass
Because PureBasic is still a Basic-Language, all methods and properties should be public. When a programmer want to indicate, that it should use a method or property, he can start it with a "_". (like for example in Lua)

the method defintion can be done with procedure:

Code: Select all

Procedure.i cFirst\Method1(Long1.l,Long2.l)
  SELF\property1=0.5*long1*long2
EndProcedure
The Class should support (Copy)Constructors and Destructors. The could be define with a \\ to indicate, that this is a special "method" "cFirst\\CopyConstructor(*rightobject)", "cFirst\\Constructor()" and "cFirst\\Destructor".
With AllocateObject(cFirst), CopyObject(*Object) and FreeObject(*Object) to handle object. It would be nice, when instead of AllocateObject(cFirst) a simple cFirst(). would be possible.

Really nice would be a start parameter block

Code: Select all

Class CSecond (value.d)
  pValue.d
EndClass

*obj.CSecond=CSecond(10.5)
debug *obj\pValue ; should return 10.5

Procedure CSecond\\Constructor(value.d)
  SELF\pValue=value
  ProcedureReturn #true ; Constructor has initialized the Object correct.
EndProcedure

Really, really nice would be, if PB handle the define complete.

Code: Select all

procedure.d Test()
  protected obj.CSecond(10.5)
  If <something>
     ProcedureReturn obj\pValue 
  EndIf
  ProcedureReturn NaN()
EndProcedure
The Obj in Test() should be destroyed after the Programm leaves the Procedure (on ProcedureReturn or EndProcedure).

Re: Class for PB

Posted: Fri May 19, 2017 7:44 am
by User_Russian

Re: Class for PB

Posted: Sat May 20, 2017 10:23 am
by c4s
I think it would already be a very big advantage if we would be able to instantiate Modules. My feature request with surprisingly PB-like behavior and only minor syntactical changes: "Class Modules" (Create Instances of a Module)