New topic: 

Changing the number of elements in object array

<http://forums.realsoftware.com/viewtopic.php?t=47615>

         Page 1 of 1
   [ 8 posts ]                 Previous topic | Next topic          Author  
Message        tseyfarth          Post subject: Changing the number of elements 
in object arrayPosted: Tue Apr 16, 2013 7:06 pm                         
Joined: Sat Dec 04, 2010 9:14 pm
Posts: 894                Hello All,

I have a class that is created as an array
RemoteResponseData(0) = New clsRemoteResponseData
RemoteResponseData.Remove 0


I want to increase the array size without using an Append.  I tried to do it 
like this but it yields the new element as Nil.
//Increase the Objects array size
If N > 0 Then
  Redim RemoteResponseData(N)
End If


I also tried like this:
RemoteResponseData.Insert N

That failed too.... Can anyone tell me the correct way to do this?
Thank you,
Tim   
                             Top                frankvanolffen          Post 
subject: Re: Changing the number of elements in object arrayPosted: Tue Apr 16, 
2013 7:13 pm                         
Joined: Wed Mar 26, 2008 6:48 pm
Posts: 76                tseyfarth wrote:Hello All,

I have a class that is created as an array
RemoteResponseData(0) = New clsRemoteResponseData
RemoteResponseData.Remove 0


I want to increase the array size without using an Append.  I tried to do it 
like this but it yields the new element as Nil.
//Increase the Objects array size
If N > 0 Then
  Redim RemoteResponseData(N)
End If


I also tried like this:
RemoteResponseData.Insert N

That failed too.... Can anyone tell me the correct way to do this?
Thank you,
Tim

If you do a redim you will lose all data in the array.

The Insert (does not exist) command is the same as Append (exist) so why is 
insert well exeptable en Append not??   
                             Top                Jason_Adams          Post 
subject: Re: Changing the number of elements in object arrayPosted: Tue Apr 16, 
2013 7:23 pm                                 
Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1772
Location: Michigan, USA                I'm not sure I follow what you're trying 
to do, Tim. Are you hoping to expand the array to a certain size with each 
element instantiated?

Dim RemoteResponseData() as clsRemoteResponseData
For Index As Integer = 1 To 10
  RemoteResponseData.Append New clsRemoteResponseData
Next

Like this?      
_________________
Windows 7 Ultimate x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult 
and not tried." - G.K. Chesterton  
                             Top                tseyfarth          Post 
subject: Re: Changing the number of elements in object arrayPosted: Tue Apr 16, 
2013 7:30 pm                         
Joined: Sat Dec 04, 2010 9:14 pm
Posts: 894                Hello and thanks for the responses.

What I am trying to do is to expand the array on the fly.  This array is used 
to hold decoded data and so it is destroyed each time a decode operation is 
performed.  The thing is, I never know how large the array is going to be until 
well into decoding a msg.  I do not want to loose any data that is present too.

Since my post, I have tried this, which appears to do the trick - what I did 
not realize when writing the post, was that the object appending this array 
does not have to be "filled" with data. It appears to just have to exist.

Dim RRD As New clsRemoteResponseData
RemoteResponseData.Append RRD


So I think this does solve the problem - although it may not be "correct"....

Thanks again!
Tim   
                             Top                doofus          Post subject: 
Re: Changing the number of elements in object arrayPosted: Tue Apr 16, 2013 
7:38 pm                                 
Joined: Thu Sep 10, 2009 2:50 am
Posts: 400
Location: Santa Cruz, CA, USA                tseyfarth wrote:So I think this 
does solve the problem - although it may not be "correct"....

It is correct (valid and reasonable). Why don't you want to use Append?   
                             Top                Jason_Adams          Post 
subject: Re: Changing the number of elements in object arrayPosted: Tue Apr 16, 
2013 7:41 pm                                 
Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1772
Location: Michigan, USA                Ah, I see. Well, this is a OOP moment, 
really. The array isn't an array of objects, per se; it's an array of pointers 
to said objects. Just like any moment when you create an object pointer (i.e. 
Dim MyObject As SomeObject), you're initially dealing with a pointer with no 
object; that is, a nil object. So when you append to an object array, you're 
immediately creating a new pointer with no object. If you want to append an 
instantiated pointer, do this:
RemoteResponseData.Append New clsRemoteResponseData
Hope this helps!     
_________________
Windows 7 Ultimate x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult 
and not tried." - G.K. Chesterton  
                             Top                tseyfarth          Post 
subject: Re: Changing the number of elements in object arrayPosted: Tue Apr 16, 
2013 7:43 pm                         
Joined: Sat Dec 04, 2010 9:14 pm
Posts: 894                Sorry Guys, 
I did leave out the fact that it is a pointer.

Thanks Jason, I will try your suggestion.

Tim   
                             Top                tseyfarth          Post 
subject: Re: Changing the number of elements in object arrayPosted: Tue Apr 16, 
2013 8:02 pm                         
Joined: Sat Dec 04, 2010 9:14 pm
Posts: 894                I just tested, and in fact using .Append works, even 
as a pointer.

Thanks guys!

Tim   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 8 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to