It is currently Tue Sep 26, 2017 10:55 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Class for PB
PostPosted: Thu May 18, 2017 6:48 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1328
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:
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:
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:
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:
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).


Top
 Profile  
Reply with quote  
 Post subject: Re: Class for PB
PostPosted: Fri May 19, 2017 7:44 am 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 976
Location: Russia
This has been discussed many times. viewtopic.php?f=3&t=53235
viewtopic.php?f=3&t=65070
Unfortunately Fred refuses to add classes in PB. viewtopic.php?p=403070#p403070

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: Class for PB
PostPosted: Sat May 20, 2017 10:23 am 
Offline
Addict
Addict

Joined: Thu Nov 01, 2007 5:37 pm
Posts: 1981
Location: Germany
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)

_________________
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye