Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Acessing Collection Object methods within wrapper class 1

Status
Not open for further replies.

Aseem1234

Programmer
Nov 26, 2003
33
US
Hello,

I have a collection class called DataColl and my program creates this collection object and passes it back to another form...I also want to pass more information about the state of the current form to the second form, so I decided it would be best to use a wrapper class...this is my code for the wrapper class...

Define Class Wrapper as Custom

nCount = 10

Define Class DataColl as Collection

Function addSample (lcClientNum)

local loSample

loSample = Createobject("Data")

With loSample
.setClientNum(lcClientNum)
.setReferenceNum(lcReferenceNum)
.setFName(lcFName)
.setLName(lcLName)
.setSSN(lcSSN)
Endwith

this.Add(loSample)

Endfunc

EndDefine

EndDefine

loSample is the object which I add to the collection...the problem I am now having is that Foxpro says this.Add(loSample) is not a property of this. I used the debugger to find out that "this" is now referring to the outer "Wrapper" class and not the inner class...I cannot seem to find a way to access the methods for the collection class unless I remove the wrapper class...does anyone have any suggestions?

Thanks,

Aseem
 
You can't nest class definitions this way. If you want your wrapper to include your data class, you must do it this way:
Code:
Define Class Wrapper as Custom 

nCount = 10
oData = .NULL.

function Init
   this.oData = createobject("DataColl")
endfunc

Enddefine

Define Class DataColl as Collection 

Function addSample (lcClientNum)

    local loSample
            
    loSample = Createobject("Data")
            
    With loSample
        .setClientNum(lcClientNum)
        .setReferenceNum(lcReferenceNum)
        .setFName(lcFName)
        .setLName(lcLName)
        .setSSN(lcSSN)
    Endwith

    this.Add(loSample)
            
Endfunc

EndDefine
Then use oWrapper.oData to access the data class (assuming you've created an object reference to the wrapper called oWrapper).



-BP
 
hi BP,

I tried this earlier...however instead of using a function to create the collection, I just had a variable in the wrapper class that created the Collection class...but the problem I had then was that I could not call the main function addSample(lcClientNum)!! I was trying soemthing to the effect of thisform.oWrapper.oData.addSample(lcClientNum), but that gave me an error? Any ideas? Or I am calling that function in teh wrong way?

Thanks a lot,

Aseem
 
Hello BP, actually they way you wrote your code, that problem does not occur. It works great! Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top