Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how do i create an array of objects by a function return?

Posted on 2006-11-10
3
Medium Priority
?
186 Views
Last Modified: 2010-04-16
here goes experts:

i have a class lets call it myClass.

i want to create an array of myClass objects by a function return like this:

 myClass[]  l_oClass = myFunction();

myFunction looks like this:
 public myClass[] myFunction()
{
    myClass[] l_oClassArray = new myClass[10];

   // alternate code here

    return l_oClassArray;
}

where it says //alternate code here
i have tried to say
  l_oClassArray.Initialize();

or alternatively:
 for( int i=0; i++; i<10)
{ l_oClassArray[i] = new myClass(); }

neither of which stopped me from seeing "object not set to a reference" error when i tried to use the objects

any suggestions?
i have also tried passing the myClass array by ref into the function and then I get the same "not a reference" error when it comes back  even though its been initialized and used inside myFunction before control is returned.

-thanks
0
Comment
Question by:richardsimnett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
ozymandias earned 2000 total points
ID: 17916939
for( int i=0; i++; i<10)
{ l_oClassArray[i] = new myClass(); }


the above should work (except that you have a couple of the arguments the wrong way round)

for( int i=0; i<10; i++){
    l_oClassArray[i] = new myClass();
}

0
 

Author Comment

by:richardsimnett
ID: 17917078
>except that you have a couple of the arguments the wrong way round
its always fun without intellisense ;)

ok. so what you are saying is basically that what i am doing should work and that if i am seeing an error it must be generated elsewhere in the code.  (obviously there is alot more going on with my classes than what i posted)

let me wait and see if I get anymore interesting responses before awarding you the points.

thanks alot
0
 

Author Comment

by:richardsimnett
ID: 17917307
werd.
you get the points.

it was right all along.  there was a problem with the X|\/|L parsing that was populating the class.

i didnt believe it was right until you agreed, so your help was instrumental.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question