Too stupid - help, help...

Everything else that doesn't fall into one of the other PB categories.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Too stupid - help, help...

Post by fsw »

Can somebody out there help me out with this?
If you look at the Name Procedure it should return a string.
When it's used directly it works, but if it's used as oop procedure it doesn't return a string.
The whole thing works with numbers though as you can see at the Number procedure.

Thanks in advance.

Code: Select all

;this code is for testing purposes only...
;derived from an old oop example by Danilo

;shows that there is something wrong with
;procedure returning strings as oop object...

#HEAP_ZERO_MEMORY = $00000008

Procedure GetHeap()
  !MOV dword  EAX ,[PB_MemoryBase]
  !MOV dword [ESP], EAX
  ProcedureReturn Heap
EndProcedure

Structure DEFAULT_OBJ
  VTable.l
  ObjData.l
EndStructure

Procedure GetDataPointer(*obj.DEFAULT_OBJ)
  ProcedureReturn *obj\ObjData
EndProcedure

;#######################################################
;- CLASS Book  start
  ; Book CLASS Interface
  Interface Book
    Book(Name$, Number.l)
    Name()
    Number()
  EndInterface
 
  ; Book CLASS Data Struct
  Structure Book_DATA
    Name$
    Number.l
  EndStructure

  ; Book CLASS Object
  Structure Book_OBJ
    VTable.l
    ObjData.l
    Functions.l[SizeOf(Book)/4]
  EndStructure

 
  Procedure Book__Book(*this.Book, Name$, Number.l)
    *this_data.Book_DATA = GetDataPointer(*this)
    *this_data\Name$ = Name$
    *this_data\Number = Number
  EndProcedure

  Procedure Book__Number(*this.Book)
    *this_data.Book_DATA = GetDataPointer(*this)
    ProcedureReturn *this_data\Number
  EndProcedure

  Procedure.s Book__Name(*this.Book)
    *this_data.Book_DATA = GetDataPointer(*this)
    Name$ = *this_data\Name$
    ProcedureReturn Name$
  EndProcedure

  ; Book CLASS Constructor
  Procedure Book__CONSTRUCTOR(ExtendFunction, ExtendData)
    ; Function Table
    *object.Book_OBJ = HeapAlloc_(GetHeap(), #HEAP_ZERO_MEMORY, ExtendFunction + SizeOf(Book_OBJ))
    If *object=0: ProcedureReturn 0: EndIf
    *object\VTable  = *object + OffsetOf(Book_OBJ, Functions)
    
    ; Data
    *ObjData.Book_DATA = HeapAlloc_(GetHeap(), #HEAP_ZERO_MEMORY, ExtendData + SizeOf(Book_DATA))
    If *ObjData=0: HeapFree_(GetHeap(), 0, *object) : ProcedureReturn 0: EndIf
    *object\ObjData = *ObjData
    
    ; Declare Functions
    *object\Functions[0] = @Book__Book()
    *object\Functions[1] = @Book__Name()
    *object\Functions[2] = @Book__Number()
    
    ProcedureReturn *object
  EndProcedure
 
  ; Book CLASS itself
  Procedure Book()
    ProcedureReturn Book__CONSTRUCTOR(0,0)
  EndProcedure
;- CLASS Book  end


;- Program Start
MyApp.Book = Book()
If MyApp
  MyApp\Book("My Name", 123456)
  Debug Book__Number(MyApp)
  Debug MyApp\Number()
  Debug Book__Name(MyApp)
  Debug MyApp\Name()
EndIf

End
Suppose it's because of the way PB handles strings, but I can be wrong.
I'm surely am (as always...)
Last edited by fsw on Mon Aug 30, 2004 9:49 pm, edited 1 time in total.
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

Here's you're problem!
You didn't define the Interface correctly... Name() should be Name.s()

Code: Select all

Interface Book 
  Book(Name$, Number.l) 
  Name.s() ;-FIXED! :)
  Number() 
EndInterface 
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Yep, that's it.
Thanks a lot.
I was searching for oop trouble and didn't see the obvious.

Thanks again.

BTW: made a correction on the subject... 8O
Post Reply