Click here to Skip to main content
15,887,585 members
Home / Discussions / C#
   

C#

 
GeneralRe: Array of classes nested into array of classes (and serialization) Pin
Pete O'Hanlon24-Mar-14 2:23
mvePete O'Hanlon24-Mar-14 2:23 
GeneralRe: Array of classes nested into array of classes (and serialization) Pin
Mario 5624-Mar-14 2:42
Mario 5624-Mar-14 2:42 
GeneralRe: Array of classes nested into array of classes (and serialization) Pin
Pete O'Hanlon24-Mar-14 2:48
mvePete O'Hanlon24-Mar-14 2:48 
GeneralRe: Array of classes nested into array of classes (and serialization) Pin
Mario 5624-Mar-14 5:54
Mario 5624-Mar-14 5:54 
AnswerRe: Array of classes nested into array of classes (and serialization) Pin
BobJanova24-Mar-14 4:14
BobJanova24-Mar-14 4:14 
GeneralRe: Array of classes nested into array of classes (and serialization) Pin
Mario 5624-Mar-14 6:17
Mario 5624-Mar-14 6:17 
GeneralRe: Array of classes nested into array of classes (and serialization) Pin
Mario 5624-Mar-14 7:44
Mario 5624-Mar-14 7:44 
GeneralRe: Array of classes nested into array of classes (and serialization) Pin
BobJanova24-Mar-14 8:05
BobJanova24-Mar-14 8:05 
You still haven't quite got the concept that an instance of Parameters should contain all references to instances of the subclasses. You're storing references to the inner classes in MainForm – that means they're not in the same object tree and really aren't related to the object 'param' you create.

Your MainForm initialisation should just be
private Parameters param = new Parameters();


Parameters.InitParameters should build the instances of products and products.preProcessing – not as local variables it is now. You're currently building arrays in that function that are never assigned to anything and go out of scope immediately.

public void InitParameters()
        {
            autoLockTime = 0;
            screenOffTime = 0;
            loopAutoStartTime = 0;
 
// Don't do this
//          preProcessing[] pp = new preProcessing[10];
            this.pp = new preProcessing[10];
            for (int i = 0; i < 9; i++)
            {
                pp[i] = new preProcessing();
                pp[i].preProcessId = i;
                pp[i].preProcessingName = "";
                for (int j = 0; j < 5; j++) pp[i].preProcessingParms[j] = 0.0;
            }
 
// or this
//          product[] p = new product[30];
            this.p = new product[30];
            for (int i = 0; i < 30; i++)
            {
                p[i] = new product();
                p[i].enabled = false;
                p[i].unit = "mm";
                p[i].productName = "H2O";
                p[i].zero = 0.0;
                p[i].span = 0.0;
                for (int j = 0; j < 10; j++)                    // we can have at max 10 preProcessing for product
                {
                    p[i].preProcessId[j] = 0;
                }
            }
        }


You'll have to add the declarations for p and pp to the Parameters class as I explained in my previous post to make those assignments work.

Now, all you have to do is serialise an instance of Parameters (i.e. MainForm.param), and it will serialise the whole object tree.
GeneralRe: Array of classes nested into array of classes (and serialization) Pin
Mario 5624-Mar-14 10:24
Mario 5624-Mar-14 10:24 
QuestionRegarding Role based Login Pin
Member 1067835223-Mar-14 22:08
Member 1067835223-Mar-14 22:08 
SuggestionRe: Regarding Role based Login Pin
Richard MacCutchan23-Mar-14 23:01
mveRichard MacCutchan23-Mar-14 23:01 
GeneralRe: Regarding Role based Login Pin
Member 1067835224-Mar-14 18:28
Member 1067835224-Mar-14 18:28 
GeneralRe: Regarding Role based Login Pin
Richard MacCutchan24-Mar-14 22:23
mveRichard MacCutchan24-Mar-14 22:23 
QuestionGeolocation with c# winforms Pin
Member 1069141122-Mar-14 12:37
Member 1069141122-Mar-14 12:37 
AnswerRe: Geolocation with c# winforms Pin
Peter Leow22-Mar-14 17:05
professionalPeter Leow22-Mar-14 17:05 
Questiondynamic sql result not shown in DevExpress DataGrid Pin
Jassim Rahma21-Mar-14 12:26
Jassim Rahma21-Mar-14 12:26 
Questionmoving from iphone to asp.net Pin
dsp120-Mar-14 23:41
dsp120-Mar-14 23:41 
AnswerRe: moving from iphone to asp.net Pin
Vishal Pand3y21-Mar-14 0:06
Vishal Pand3y21-Mar-14 0:06 
AnswerRe: moving from iphone to asp.net Pin
OriginalGriff21-Mar-14 2:16
mveOriginalGriff21-Mar-14 2:16 
QuestionMany instances of the same class by a loop Pin
mrRsChief20-Mar-14 15:32
mrRsChief20-Mar-14 15:32 
AnswerRe: Many instances of the same class by a loop Pin
Dave Kreskowiak20-Mar-14 17:06
mveDave Kreskowiak20-Mar-14 17:06 
AnswerRe: Many instances of the same class by a loop Pin
Wayne Gaylard20-Mar-14 20:03
professionalWayne Gaylard20-Mar-14 20:03 
AnswerRe: Many instances of the same class by a loop Pin
V.20-Mar-14 20:42
professionalV.20-Mar-14 20:42 
AnswerRe: Many instances of the same class by a loop Pin
OriginalGriff20-Mar-14 23:27
mveOriginalGriff20-Mar-14 23:27 
AnswerRe: Many instances of the same class by a loop Pin
BobJanova21-Mar-14 0:28
BobJanova21-Mar-14 0:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.