// Before: parent is a class with a SNote array. // After: SNotes with values from filename // have been set up and the SNotes are // loaded to snote. SNotes have a pointer // to parent. public static void readSNotes(Vidmot parent) { snote = new SNote[100]; try { table = Value.LoadFile(filename); } catch(Exception) { table = null; } // If nothing loaded from filename // then snote is initialized, empty // and correct. if(table==null) { snCount=0; return; } // Data invariant: // * i is an index to table values. // * n is an index to snote values. int i=0, n=0; // After: Values have been loaded from // table (from filename) into n SNotes // and the SNotes stored in snote. while(table[i.ToString()] != null) { string[] info = new string[4]; info[0] = (string) table[i.ToString()]; i++; info[1] = (string) table[i.ToString()]; i++; info[2] = (string) table[i.ToString()]; i++; info[3] = (string) table[i.ToString()]; i++; int status = (int) table[i.ToString()]; i++; snote[n] = new SNote(parent); snote[n].updateInfo( info[0], info[1], info[2], info[3], status); n++; } snCount = n; }
public SNote(Vidmot parent) : base() { vbox = new VBox(); title = new Label(); comment = new Label(); date = new Label(); prio = new Label(); status = 0; vbox.Add(title); vbox.Add(comment); vbox.Add(date); vbox.Add(prio); Clicked += delegate { parent.changeSNote(this); }; Add(vbox); }