IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Bruce Peaslee on January 14, 2006, 12:12:14 PM

Title: Where to fill array
Post by: Bruce Peaslee on January 14, 2006, 12:12:14 PM
I have a class that manipulates an array of a structure. Where in the class should the values be set? I have tried the Constructor and OnCreate(), both of which fail. If I put the assignment statements in the method I am working on, it works fine.

(Eventually the data will be read from disk, but I would like to solve this problem so I will know.)
Title: Re: Where to fill array
Post by: Parker on January 14, 2006, 03:14:42 PM
It shouldn't really matter where you put the statements, the code should get executed. I don't know why it would fail. If you're using a pointer to an array, make sure you're using NEW() in the constructor, or at least before the array is used. And make sure the destructor deletes the array.
Title: Re: Where to fill array
Post by: Bruce Peaslee on January 14, 2006, 10:00:22 PM
I would think it doesn't matter, but if I cut and paste the code into either the constructor or OnCreate() it doesn't work.

The array is declared at the top in the class statement. There are no pointers involved.
Title: Re: Where to fill array
Post by: Parker on January 14, 2006, 10:06:27 PM
Your class isn't global is it? Because if it is, the constructor will never be called. Make sure you declare it inside of main() or some other function. And that should make it work. If not, I have no idea and you should post some code demonstrating the problem.

Even if it isn't global, it's a good reminder to keep your classes non-global, since most won't work as globals.
Title: Re: Where to fill array
Post by: Bruce Peaslee on January 14, 2006, 10:12:46 PM
It's declared at the top of a dlg:dialog class - that's where its methods are called, in the dialog's methods.

I'm too tired nowÂÃ,  :P - I'll try some more tomorrow.

Thanks.
Title: Re: Where to fill array
Post by: Bruce Peaslee on January 15, 2006, 09:15:56 AM
Here's the outline:

struct ConstantData
{
ÂÃ,  ...
}

class ConstantConversion
{
ÂÃ,  ...
ÂÃ,  ConstantData myData[100];ÂÃ,  //this is the struct array
}

ConstantConversion::LoadData()ÂÃ,  ÂÃ,  ÂÃ, // this works. putting this in Constructor or OnCreate does not
{
ÂÃ,  myData[0] = 1;
ÂÃ,  myData[1] = 6;
ÂÃ,  ...
}

Class dlg:dialog
{
ÂÃ,  declare OnInit();
ÂÃ,  ConstantConversion myCC;
ÂÃ,  ...
}

dlg::OnInit()
{
ÂÃ,  ...
ÂÃ,  myCC.LoadData();
}
Title: Re: Where to fill array
Post by: Parker on January 15, 2006, 02:33:53 PM
I have a feeling it's because you defined those variables as a structure array and you're trying to set them to numbers. Try something like this:
struct ConstantData
{
    int x;
    ...
}

...
ConstantConversion::LoadData()
{
    myData[0].x = 1;
    myData[1].x = 6;
    ...
}
...


It's probably a compiler bug that's letting you do that.
Title: Re: Where to fill array
Post by: Ionic Wind Support Team on January 15, 2006, 07:49:31 PM
Actually it's part of the OOP functionallity that is not quite finished yet.

Just as global classes don't get there constructors called yet, either do static classes that are defined as class members.   Which is why you see me use NEW anytime I have an embedded class.

When a class gets constructed the compiler doesn't look through its member variables yet to see if any other classes need constructing too.

class MyClass
{
    ...
    SomeOtherClass m_scl;  //constructor not called for embedded classes yet
}
---------------------------------

Set it up like this and it'll work fine.


class MyClass
{
   MyClass();
   _MyClass();
   SomeOtherClass *m_pscl;  //constructor will be called by NEW
}

MyClass::MyClass()
{
    m_pscl = NEW(SomeOtherClass,1);
}

MyClass::_MyClass()
{
     Delete  m_pscl;
}


Should have the prior form working soon.  The recursive nature of it was making me pull my hair out during my last attempt so I put it  on hold to get Alpha2 out the door.

Keep in mind that we still have a way to go ;)
Title: Re: Where to fill array
Post by: Bruce Peaslee on January 15, 2006, 11:00:54 PM
Quote from: Ionic Wizard on January 15, 2006, 07:49:31 PM
Actually it's part of the OOP functionallity that is not quite finished yet.

Should have the prior form working soon.ÂÃ,  The recursive nature of it was making me pull my hair out during my last attempt so I put itÂÃ,  on hold to get Alpha2 out the door.

That's OK. I can stop pulling my hair out now that I know you are pulling out yours.ÂÃ,  :D

My way of doing it works fine and I can wait to adjust until we're ready.

Thanks.