Another OOP PreCompiler

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Superadnim, cool off, step back. That's trolling and you know it. Comments like those only make me react in one way:

YOU write something better, and THEN you're allowed those kind of comments.

(Show us something you wrote, then WE can laugh.)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
oldBear
Enthusiast
Enthusiast
Posts: 121
Joined: Tue Jul 05, 2005 2:42 pm
Location: berrypatch

Post by oldBear »

If I remember correctly, Superadnim has been warned at least once before about this kind of behavior.

Shame some people just don't learn.
User avatar
the.weavster
Addict
Addict
Posts: 1531
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Post by the.weavster »

mk-soft you rock.

superadnim - is he really super?

Write your answers on the back of a five pound note and send them to:
the.weavster
...
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Hi,

For which you use my Precompiler and run it?

Need still for the advancement still two stable functions with rollback.

Code: Select all

Procedure RegDLL(ProgID.s, CLSID.UIID, InprocServer32.s = "Apartment")

EndProcedure 

Procedure UnregDLL(CLSID.UIID)

EndProcedure
who can help me?

Thanks :wink:

P.S. Helpertools for UUID as DataSection is Ready. Download UuidGenerate
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Simply OOP Dialog example. Using Threadsave.

Code: Select all


Class DlgWindow Extends BaseClass
  ; Attributes
  WinID.l
  hThread.l
  Exit.l
  Caption.s
EndClass


; Method DlgWindow_Function(*this.DlgWindow)
; 
;   With *this
;   
;   EndWith
;   
; EndMethod

Method DlgWindow_Create(*this.DlgWindow)

  With *this
    \WinID = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 300, 200, \Caption)
    
  EndWith
  
EndMethod

Method DlgWindow_Event(*this.DlgWindow)
  
  Protected event.l
  
  With *this
    Repeat
      event = WaitWindowEvent()
      Select event
        Case #PB_Event_CloseWindow
          \Exit = #True
      EndSelect
    Until \Exit
    Debug "Exit Thread ID " + Str(\hThread)
    CloseWindow(\WinID)
  EndWith
  
EndMethod

Method DlgWindow_IsExit(*this.DlgWindow)

  ProcedureReturn *this\Exit
  
EndMethod


; Private
Procedure DlgInit(*this.IDlgWindow)
  *this\Create()
  *this\Event()
EndProcedure

Method DlgWindow_Run(*this.DlgWindow, Caption.s)

  With *this
    \Caption = Caption
    \hThread = CreateThread(@DlgInit(), *this)
  EndWith
  
EndMethod

; Test
Define.IDlgWindow *dlg1, *dlg2

*dlg1 = NewObject(DlgWindow)
*dlg2 = NewObject(DlgWindow)
*dlg1\Run("Diaglog 1")
*dlg2\Run("Diaglog 2")

Debug "Start.."
Repeat: Delay(100) : Until *dlg1\IsExit() And *dlg2\IsExit()

*dlg1\Release()
*dlg2\Release()

Debug "Ready."
GT :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
neotoma
User
User
Posts: 84
Joined: Sun Dec 14, 2003 6:38 pm
Location: Germany, Mechernich
Contact:

Post by neotoma »

very impressive.

i tried with that, and i'm missing a 'Super'-Var/pointer to call a method on the class from we inherited.
(Maybe as a pointer).

With that we can use also the functionality from the 'Parent'-Object.
Say - if we write a Baseclass that has the functionality to serialize itself (only the important vars). If we derive from that we also 'overwrite' the serialize-function. but instead to serialize all the vars, we only call the 'Parent' (in java as Super())-Function (it serialze the vars of the parent object, and now we only have to serialize the vars we need for my class (members).


Mike
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Sorry, i don´t understand complete what you mean. (my english)

but when you need a method from myclass, only define the method from myclass.

Code: Select all

Class MyClass Extends BaseClass
  ; Attributes
EndClass

Method MyClass_Function1(*this.MyClass)
  With *this
    Debug "Test 1"
  EndWith
EndMethod

Method MyClass_Function2(*this.MyClass)
  Protected *self.iMyclass = *this
  With *this
    *self\function1()
  EndWith
EndMethod

*obj.imyclass = NewObject(myclass)
*obj\function2()
This is all for self and inherited method, not parend class object because is not exists.

P.S. I added an optional parameter by NewObject(Class, ParendClass) at time.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
neotoma
User
User
Posts: 84
Joined: Sun Dec 14, 2003 6:38 pm
Location: Germany, Mechernich
Contact:

Post by neotoma »

mk-soft wrote:Sorry, i don´t understand complete what you mean. (my english)
Same for my english... if germans write english... ;-)

But i think it is also interesting for the people here around. So i try to explain this a little bit more (next try..)
Say i have a Baseclass like :

Code: Select all

Class cBase
    cBase()
    serialize(*xml_node)
    deserialize(*xml_node)
    id.l
    name.s
    type.l
EndClass

Procedure cBase.cBase()
EndProcedure

Procedure cBase.serialize(*xml_node)
  ;
  ;.. write id, name and type as tags to the xml.
  ;
EndProcedure

Procedure cBase.deserialize(*xml_node)
  ;
  ;.. read id, name and type as tags from the xml.
  ;
EndProcedure

Now i want hav a class the derives from the base class :

Code: Select all

Class cAction 
  cAction()
  execute()
  serialize(*xml_node)
  deserialize(*xml_node)
;now only the vars for this Action
;we iherited the id,name and type from the base-class
  actionName.s
  actionPath.s
  actionTimeout.l
EndClass

Procedure cAction.cAction()
    ;; should able to call the parent Constructor
    ;; for basic initis.
   ;;but without knowing the name of the Base-Class
EndProcedure 

Procedure cAction.execute()
   ;;Do the Action
EndProcedure 

Procedure cAction.serialize(*xml_node)
    ;;call parent first 
    *parent\serialize(*xml_node)
  ;;
  ;; now write my own vars to the xml
EndProcedure


Procedure cAction.deserialize(*xml_node)
    ;;call parent first 
    *parent\deserialize(*xml_node)
  ;;
  ;; now read my own vars from the xml
EndProcedure

This ends up with the 'feature' that i can have a Array or LinkedList filled with different action-objects, but i have only to call 'execute() to start the action, and using a serialize() to write them (completly) or a deserialize() to read them back.
I have not to know the parent of a class. That should be capsuled via OO.

I hope that clears what i want . So i was a C++/Java man, and i wrote the Pattern (Command-Pattern) often enough. And i really like it much.
Would be nice - and important - to get that work.

BTW: I cannot understand Fred with his ignorance against OOP. He gives us the Interface as a basic step to OOP but denies support via Compiler.
So he has not to reinvent the complete Purebasic only to add a feature. that the people can use - if the want. Maybe as for some extra cash.
(i would pay for that !)
But its a fact that OO is a good solution for greater projects.

Mike








EndClass
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Update v0.35 (Only Windows, Linux at time)

NewObject calling the Method "InitObject()". Now can overwrite this method for initialzed the object.

example:

Code: Select all

; Example Part 3 - avoidance of memory leak with self method Release

Class MemClass Extends BaseClass
  *mem1
  *mem2
EndClass

; Init memory
Method Overwrite MemClass_InitObject(*this.MemClass) ; <- NewObject call InitObject
  With *this
    Debug "InitObject: AllocateMemory."
    \mem1 = AllocateMemory(10*1024)
    \mem2 = AllocateMemory(20*1024)
  EndWith
EndMethod

Method MemClass_GetMemPointer(*this.MemClass, number.l)
  Select number
    Case 1 : ProcedureReturn *this\mem1
    Case 2 : ProcedureReturn *this\mem2
    Default : ProcedureReturn 0
  EndSelect
EndMethod

Method Overwrite MemClass_Release(*this.MemClass)
  
  ; Decrease internal refcounter
  If *this\__Ref > 1 
    *this\__Ref - 1
    ProcedureReturn *this\__Ref
  Else
    Debug "Release: Free Memory."
    FreeMemory(*this\mem1)
    FreeMemory(*this\mem2)
    ; Release Object
    ProcedureReturn DeleteObject(*this)
  EndIf

EndMethod



; Test Part 3
Debug "Test Part 3"
Debug ""
Debug "Mem Test 1"
*mem.IMemClass = NewObject(MemClass)
Debug "Address of mem1: " + Str(*mem\GetMemPointer(1))
Debug "Address of mem2: " + Str(*mem\GetMemPointer(2))
*mem\Release()
Debug ""

Debug "Mem Test 2"
*mem.IMemClass = NewObject(MemClass)
Debug "Address of mem1: " + Str(*mem\GetMemPointer(1))
Debug "Address of mem2: " + Str(*mem\GetMemPointer(2))
*mem\Release()
Debug ""
GT :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Update v0.36

Bugfix: InitObject()

------------------------------
Edit
Super var-pointer does not correspond the COM objects to specification. There tries to remain compatible for later DLL´s for these will not integrate itself. Who white still another solution those the integrity does not injure.

Sorry,
------------------------------


I have still no solution for parent method.

Code: Select all


Class cBase Extends BaseClass
  ; Method
  ; cBase()
  ;serialize(*xml_node)
  ;deserialize(*xml_node)
  ; Attribues
  id.l
  name.s
  type.l
EndClass

Method cBase_InitObject(*this.cBase)

EndMethod

Method cBase_serialize(*this.cBase, *xml_node)
  ;
  *this\name = "cBase Serialize"
  ;
EndMethod

Method cBase_deserialize(*this.cBase, *xml_node)
  ;
  ;.. read id, name and type as tags from the xml.
  *this\name = "cBase deserialize"
  ;
EndMethod


Class cAction Extends cBase
  ; inherited methods
  ;serialize(*xml_node)
  ;deserialize(*xml_node)
  ; Methods
  ;cAction()
  ;execute()
  ;now only the vars for this Action
  ;we iherited the id,name and type from the base-class
  actionName.s
  actionPath.s
  actionTimeout.l
EndClass

Method Overwrite cAction_InitObject(*this.cAction)
  ;; should able to call the parent Constructor
  ;; for basic initis.
  ;;but without knowing the name of the Base-Class
EndMethod

Method cAction_execute()
   ;;Do the Action
EndMethod

Method Overwrite cAction_serialize(*this.cAction, *xml_node)
    ;;call parent first
    cbase_serialize(*this, *xml_node) ; <- Call old method: I have still no solution
    Debug *this\name 
    ;;
    ;; now write my own vars to the xml
EndMethod


Method Overwrite cAction_deserialize(*this.cAction, *xml_node)
    ;;call parent first
    cbase_deserialize(*this, *xml_node)
    Debug *this\name 
    ;;
    ;; now read my own vars from the xml
EndMethod

*obj.icAction = NewObject(cAction)
*obj\serialize(100)
*obj\deserialize(100)
[/b]
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Update v0.36

Linux version now available

GT :wink:

P.S. OOP-Dialog under a linux not running :?: :?: :?:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Update v0.37

Structure BaseClass have now a pointer to parent object :wink:

Chaos example:

Code: Select all

; Example for parent object
; Structure BaseClass have now a pointer to parent object

Class Sub Extends BaseClass
  text.s
EndClass

Class Master Extends BaseClass
  ; Attribute
  text.s
  sub.ISub[20]
EndClass


; Sub Class Methods

; Method Sub_Function(*this.Sub)
;   With *this
;   
;   EndWith
; EndMethod

Method Sub_InitObject(*this.Sub)
  With *this
    Debug "Parent Pointer: " + Str(\parent)
  EndWith
EndMethod

Method Sub_Test(*this.Sub)
  Protected *parent_data.master = *this\parent ; Set pointer to parent data
  Protected *parent_method.imaster = *this\parent ; Set pointer to parent interface
  With *this
    \text = "SubText = Parent Text -> " + *parent_data\text  
    Debug \text
    Debug "Parent Method GetText() = " + *parent_method\GetText()
  EndWith
EndMethod


; Master Class Methods

; Method Master_Function(*this.Master)
;   With *this
;   
;   EndWith
; EndMethod

; Method Init Object

Method Master_InitObject(*this.Master)
  With *this
    \text = "Hello Master Text"
  EndWith
EndMethod

Method.s Master_GetText(*this.Master)
  With *this
    ProcedureReturn \text
  EndWith
EndMethod

Method Master_NewSub(*this.Master, ID)
  With *this
    \sub[ID] = NewObject(sub)
    ProcedureReturn \sub[id]    
  EndWith
EndMethod

*master.imaster = NewObject(master)
Debug *master\gettext()

*sub1.isub = *master\NewSub(0)
*sub1\test()
Who writes a better example
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
SofT MANiAC
Enthusiast
Enthusiast
Posts: 142
Joined: Mon Sep 17, 2007 10:28 am
Location: P.O.P
Contact:

Post by SofT MANiAC »

really good work!
POiNT.OF.PRESENCE group
SofT MANiAC
Enthusiast
Enthusiast
Posts: 142
Joined: Mon Sep 17, 2007 10:28 am
Location: P.O.P
Contact:

Post by SofT MANiAC »

superadnim wrote:I guess I'll have to continue mine after all...
Chatter and chatter :lol:
POiNT.OF.PRESENCE group
SofT MANiAC
Enthusiast
Enthusiast
Posts: 142
Joined: Mon Sep 17, 2007 10:28 am
Location: P.O.P
Contact:

Post by SofT MANiAC »

Fatal error!

Code: Select all

XIncludeFile #PB_Compiler_Home + "somefile.pbi"
Class MyClass Extends BaseClass
EndClass
- not works (Syntax error, topfile.oop not created)!

Code: Select all

XIncludeFile "d:\PB4\somefile.pbi"
Class MyClass Extends BaseClass
EndClass
- works (not always - e.g. I can't include DX9-includes by Steven (Dreglor) Garcia)!

Fix please?

@inc
You have this problem too (remind my issue?)
POiNT.OF.PRESENCE group
Post Reply