en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en nl en en en en en en en hbs_lat en de en en en en en nl en en en en en en en en en en en en nl en en en en en en en en hbs_lat en en en en en en en en nl en en en en en en nl en en en en nl en en en en en en en en en en de en en en fr en en en en en en en en en pt en en en en en en
By logging into your account, you agree to our Privacy Policy, personal data processing and storage practices as described therein.
Forgot password or user name?
Search in titles only Search in Working with Objects only
You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
All Time Today Last Week Last Month
All Discussions only Photos only Videos only Links only Polls only Events only
Join Date: Aug 1998
27 Mar 2009, 08:46 AM
Can anyone point out what is wrong with the following code. I add 3 container objects to the ship object. When I try to get any container object back from the ship object it always returned the last container object that was added.
'PBWIN 9.00 - WinApi 05/2008 - XP Pro SP3 'OOP example by Steve Pringles ' ====================================================================================================== CLASS cContainer INSTANCE m_Width AS SINGLE INSTANCE m_Length AS SINGLE INSTANCE m_height AS SINGLE INTERFACE iContainer INHERIT IDISPATCH PROPERTY GET WIDTH () AS SINGLE PROPERTY = m_Width END PROPERTY PROPERTY SET WIDTH (BYVAL Value AS SINGLE) m_Width = Value END PROPERTY PROPERTY GET Length() AS SINGLE PROPERTY = m_Length END PROPERTY PROPERTY SET Length(BYVAL Value AS SINGLE) m_Length = Value END PROPERTY PROPERTY GET Height() AS SINGLE PROPERTY = m_Height END PROPERTY PROPERTY SET Height(BYVAL Value AS SINGLE) m_Height = Value END PROPERTY END INTERFACE END CLASS CLASS cShip INSTANCE m_ContainerCount AS WORD INSTANCE m_Volume AS SINGLE INSTANCE m_VolumeUsed AS SINGLE INSTANCE m_Containers() AS iContainer CLASS METHOD CREATE() REDIM m_Containers(0) AS INSTANCE iContainer END METHOD INTERFACE iShip INHERIT IDISPATCH METHOD SetMaxSize(BYVAL nLength AS SINGLE, BYVAL nWidth AS SINGLE, BYVAL nHeight AS SINGLE) m_Volume = nLength * nWidth * nHeight END METHOD METHOD AddContainer(BYVAL iC AS iContainer) AS LONG LOCAL ContainerVolume AS SINGLE IF ISOBJECT(iC) THEN IF IC.Width AND iC.Height AND iC.Length THEN ContainerVolume = iC.Width * iC.Height * iC.Length IF ContainerVolume + m_VolumeUsed   0 AND nItem <= m_ContainerCount THEN METHOD = m_Containers(nItem - 1) ELSE METHOD = NOTHING END IF END METHOD END INTERFACE END CLASS FUNCTION PBMAIN() AS LONG LOCAL cCont AS iContainer LOCAL cBoat AS iShip LOCAL s$ cBoat = CLASS "cShip" cCont = CLASS "cContainer" cBoat.SetMaxSize(20, 20, 40) cCont.Length = 1 cCont.Width = 1 cCont.Height = 1 cBoat.AddContainer(cCont) cCont.Length = 2 cCont.Width = 2 cCont.Height = 2 cBoat.AddContainer(cCont) cCont.Length = 3 cCont.Width = 3 cCont.Height = 3 cBoat.AddContainer(cCont) s$ = "Str$(cBoat.GetContainerCount()) = " & STR$(cBoat.GetContainerCount()) & $CRLF cCont = cBoat.GetContainer(1) s$ = s$ & "Volume used : " & FORMAT$(cBoat.GetVolumeUsed) & " square feet" & $CRLF s$ = s$ & "Capacity left: " & FORMAT$(cBoat.GetCapacityLeft) & " square feet" & $CRLF s$ = s$ & "Width of first container = " & FORMAT$(cCont.Width) & $CRLF cCont = cBoat.GetContainer(2) s$ = s$ & "Width of Second container = " & FORMAT$(cCont.Width) & $CRLF cCont = cBoat.GetContainer(3) s$ = s$ & "Width of Third container = " & FORMAT$(cCont.Width) & $CRLF ?s$ END FUNCTION
Join Date: Oct 1998
27 Mar 2009, 01:02 PM
How about this, Doug?
FUNCTION PBMAIN() AS LONG LOCAL cCont, cCont1, cCont2, cCont3 AS iContainer LOCAL cBoat AS iShip LOCAL cContArr() AS iContainer LOCAL s$ cBoat = CLASS "cShip" cCont = CLASS "cContainer" cBoat.SetMaxSize(20, 20, 40) cCont1 = CLASS "cContainer" cCont1.Length = 1 cCont1.WIDTH = 1 cCont1.Height = 1 cBoat.AddContainer(cCont1) cCont2 = CLASS "cContainer" cCont2.Length = 2 cCont2.WIDTH = 2 cCont2.Height = 2 cBoat.AddContainer(cCont2) cCont3 = CLASS "cContainer" cCont3.Length = 3 cCont3.WIDTH = 3 cCont3.Height = 3 cBoat.AddContainer(cCont3) ... ...
Join Date: Aug 1998
27 Mar 2009, 01:28 PM
The AddContainer method is BYVAL but is acting like BYREF
METHOD AddContainer(BYVAL iC AS iContainer) AS LONG
Also if I recreate that container object between each add it seems to correct the problem.
LOCAL cCont AS iContainer LOCAL cBoat AS iShip LOCAL s$ cBoat = CLASS "cShip" cBoat.SetMaxSize(20, 20, 40) cCont = CLASS "cContainer" cCont.Length = 1 cCont.Width = 1 cCont.Height = 1 cBoat.AddContainer(cCont) cCont = NOTHING cCont = CLASS "cContainer" cCont.Length = 2 cCont.Width = 2 cCont.Height = 2 cBoat.AddContainer(cCont) cCont = NOTHING cCont = CLASS "cContainer" cCont.Length = 3 cCont.Width = 3 cCont.Height = 3 cBoat.AddContainer(cCont) cCont = NOTHING cCont = CLASS "cContainer"
Join Date: Nov 2004
27 Mar 2009, 03:37 PM
Think you might be solving your issue like that, seems that as long as the "parent" object is in existence, any "siblings" or "clones" are connected to the parent, changing the properties of the parent affect the children. When you "destroy" the parent, the reference to the parent is lost by the child and the child becomes independent.
Furcadia, an interesting online MMORPG in which you can create and program your own content.
Join Date: Sep 1998
30 Mar 2009, 01:15 AM
Let me also emphasize that this is not a true collection class since you can only store one particular interface type whereas a true collection doesn't bother with the interface type.
So here we are, this is the end.
But all that dies, is born again.
- From The Ashes (In This Moment)
Copyright © 1998-2022 PowerBASIC Tools, LLC - All Rights Reserved.
Powered by vBulletin® Version 5.7.0
Copyright © 2022 vBulletin Solutions, Inc. All rights reserved.
All times are GMT-5. This page was generated at 03:55 AM.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.