Page 1 of 1
Posted: Tue Apr 15, 2003 8:19 pm
by BackupUser
Restored from previous forum. Originally posted by Amiga5k.
I know the benefits of OOP have been exagerrated, but there are times when it could come in handy. I was thinking of a 'simple' addition to PB that would be a pretty large step in supporting Objects. Consider:
Code: Select all
Structure alien
x.w
y.w
speed.b
Procedure Init() ; This is called when a new 'alien' type is
; created. A reserved name.
; initialization code goes here
EndProcedure
Procedure Default() ; A reserved procedure name. This procedure
; is automatically called whenever any of the
; variables are are referenced in this
; structure. It is global to all 'alien'
; types.
; default code goes here
EndProcedure
Procedure Destroy() ; Called when this type is destroyed
; Code goes here
EndProcedure
Procedure Explode(arg.l) ; A user-defined procedure which is auto-
; matically called if it is referenced by
; name like this:
; my.alien\Explode = #True
; (the value of #True is passed to
; Explode() )
EndProcedure
EndStructure
For 'private' functions, that ONLY apply to THIS type, you could add them in during the creation process, like this:
Code: Select all
AddPrivateProc my.alien, @Private ; Where @Private would point to
; a procedure for it's own static
; use.
So basically, just the automatic calling of these functions could go a long way to 'emulate' OOP programming. Is this doable? If not, it could be 'faked' by puting the address of procedures in the Structure and then explictly calling them via the address. Is there a command to do this with internal procedures? (I know about CallFunction(), but I think it is only for external functions?)
Russell
***Commodore 64 - Over one million cycles per second, 16 vibrant colors, 3 incredible audio channels and 38,911 Basic Bytes Free! Who could ask for anything more?***
Posted: Tue Apr 15, 2003 10:15 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.
CallFunctionFast()
El_Choni
Posted: Tue Apr 15, 2003 10:55 pm
by BackupUser
Restored from previous forum. Originally posted by Kale.
could you elaborate a little more El_Choni? are you saying we can access procedures from within structures using CallFunctionFast()?
--Kale
In love with PureBasic! 
Posted: Wed Apr 16, 2003 6:58 am
by BackupUser
Restored from previous forum. Originally posted by theogott.
Sounds intresting. NOT because of OOP but because of the possibilities.
However, everyone who suggests such complicated structures, should know that these things may affect
a) compile-time
b) execution speed
c) bug-possibility in early developement stages
If currently a structure is "pure data" its safe cause it will normally not EXECUTE "data in it".
If its later "mixed between data and program" (which is MS's biggest security problem) this may even lead to security problems in ready applications ("buffer overflow"-> execution of data as code).
Depending on implementation.
However if all those things WOULD work well it sounds nice

...
*************************
The best time to do things is now !
Posted: Wed Apr 16, 2003 8:12 am
by BackupUser
Restored from previous forum. Originally posted by El_Choni.
You can use CallFunctionFast() with any long value, doesn't matter where it comes from. I think your idea is not bad, but you can work with what is present now. In fact, COM method tables are just structures of pointers to procedures:
Code: Select all
Structure ClassFactoryObject
lpVtbl.l
nRefCount.l
EndStructure
Structure IUnknown
QueryInterface.l
AddRef.l
Release.l
EndStructure
Structure MyInterface
IUnknownMethods.IUnknown
ShowMessage.l
EndStructure
Structure MyObject
ClassFactory.ClassFactoryObject
nValue.l
EndStructure
Structure GUID
Data1.l
Data2.w[2]
Data3.b:)
EndStructure
Declare MyComQueryInterface(*Object.MyObject, *MyGuid.GUID, pInterface)
Declare MyComAddRef(*Object.MyObject)
Declare MyComRelease(*Object.MyObject)
Declare MyComShowMessage(*Object.MyObject, Message$)
Procedure MyComQueryInterface(*Object.MyObject, *MyGuid.GUID, pInterface)
If *Object
PokeL(pInterface, *Object\ClassFactory\lpVtbl)
ProcedureReturn #S_OK
Else
ProcedureReturn #S_FALSE
EndIf
EndProcedure
Procedure MyComAddRef(*Object.MyObject)
If *Object
*Object\ClassFactory\nRefCount+1
ProcedureReturn *Object\ClassFactory\nRefCount
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure MyComRelease(*Object.MyObject)
If *Object
*Object\ClassFactory\nRefCount-1
ProcedureReturn #S_OK
Else
ProcedureReturn #S_FALSE
EndIf
EndProcedure
Procedure MyComShowMessage(*Object.MyObject, Message$)
If *Object
MessageRequester("Message from COM object:", Message$, 0)
ProcedureReturn #S_OK
Else
ProcedureReturn #S_FALSE
EndIf
EndProcedure
Object1.MyObject
Interface1.MyInterface
Object1\ClassFactory\lpVtbl = Interface1
Interface1\IUnknownMethods\QueryInterface = @MyComQueryInterface()
Interface1\IUnknownMethods\AddRef = @MyComAddRef()
Interface1\IUnknownMethods\Release = @MyComRelease()
Interface1\ShowMessage = @MyComShowMessage()
It's incomplete for now, I will come back to this in a few days, I'm going on holidays

Bye,
El_Choni
Posted: Wed Apr 16, 2003 12:21 pm
by BackupUser
Restored from previous forum. Originally posted by tinman.
Originally posted by El_Choni
Data3.b:)
Hey, how do I type the 8-ball into PureBasic ;p
--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.51, external editor)
Posted: Wed Apr 16, 2003 12:50 pm
by BackupUser
Restored from previous forum. Originally posted by Manolo.
Hi tinman,
The 8 ball is one problemn of with the smilies in this program forum.
This is diferent "["+"8"+"]" but is the same.

is one array of structure that contents 8 elements, but in the forum not is possible write, but yes anothe num [7], [9], etc
Manolo
Posted: Wed Apr 16, 2003 6:23 pm
by BackupUser
Restored from previous forum. Originally posted by tinman.
Originally posted by Manolo
The 8 ball is one problemn of with the smilies in this program forum.
I know, it was a joke.
--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.51, external editor)
Posted: Wed Apr 16, 2003 7:28 pm
by BackupUser
Restored from previous forum. Originally posted by Berikco.
Yes, very cool forum tricks....
like the structure COLOR****
Code: Select all
Structure COLOR****
Color.l
****.l
Endstructure
hehe, its not possible to post the word "S"+"H"+"I"+"T"
Regards,
Berikco
http://users.pandora.be/berikco/purebasic.htm
Posted: Wed Apr 16, 2003 9:28 pm
by BackupUser
Restored from previous forum. Originally posted by Thomas.
SH
IT
no problem
Posted: Wed Apr 16, 2003 10:35 pm
by BackupUser
Restored from previous forum. Originally posted by Amiga5k.
I've experimented a little with placing pointer data in Structures and then calling them as though they were part of the 'object', but I wasn't sure if CallFunctionFast was for external functions only. I guess IsFunction works with all functions? But the docs for IsFunction say: 'Check if the #Library, previously opened with OpenLibrary(), contains the given function' which implies that it is for external functions. I'll give it a try, though
But getting back to my example, I was thinking that the functions-in-structures would be optional only, and would be completely up to the programmer - including the task of making sure that their data is secured in some way. I think it would make interfacing with 3rd party libraries that make use of various objects much easier. Also, gui programming could be more streamlined:
Code: Select all
Ok.btn ; This would create a button called Ok and call its 'init' function
Ok\text = "&Ok" ; This would change the default text from "" to "&Ok" and then call
; its 'Default' function, which would update the button.
And so on. The description for the various gui 'objects' would be contained in some header file (btn = button, rdo = radio, scl = scroll, etc). This is one of the few elements of Visual Basic that I like.
Defintely this would require some extra hooks to be put in PB, but the possibilities are awesome. All buttons could even be grouped together so that you could universally apply certain attributes to all of them (such as disable). Yikes, I'm starting to sound like a c programmer!
Anyway, this would make PB the only other OO basic besides VB, I think. Hmm...
Russell
***Commodore 64 - Over one million cycles per second, 16 vibrant colors, 3 incredible audio channels and 38,911 Basic Bytes Free! Who could ask for anything more?***
Posted: Wed Apr 16, 2003 10:40 pm
by BackupUser
Restored from previous forum. Originally posted by Amiga5k.
Instead of 'AddPrivateProc my.alien, @Private' to add a private procedure, a 'private' keyword could be added to a procedure declaration within the original structure definition, meaning that each type created will have its own separate (but identical) version of that procedure. A non-private (public?) procedure would be shared by all of the created types to save memory.
Russell
***Commodore 64 - Over one million cycles per second, 16 vibrant colors, 3 incredible audio channels and 38,911 Basic Bytes Free! Who could ask for anything more?***