Code:
class mainScreen{
//record r1;
//to keep track of number of records
int recordCount;
fstream _f;
streampos end;
Screen _mainS;
enum{ ID,Name,A1,A2,A3,Mid,Final,Letter,Comments,Overall,Active1,Active2,Active3,Active4,Active5};
int _flds[15];
int _msgs[9];
Field msgField;
TextField txtStudId;
//The Client does not need to access the list
struct node
{
record r;
int recNumb;//so the student record number will be known
node *next;
node *prev;
node(record n,int rn,node *nn=NULL,node *pn=NULL):r(n),recNumb(rn),next(nn),prev(pn){}
};
node *Records;
//The current record
node *currentRecord;
//if update is true the text file is updating a record
//else it is just appending
bool writeToFile();
bool readFromFile();
//go to next node
bool goNext();
bool goPrev();
void changeFields();
int search(bool SearchName);
double nV;
void updateRecord();
//To get the Average grade per assignment/test and get the total of each
void getAverages(double *GradeList,int *CountList);
double calcGrade();
bool (*isValidN)(TextField *,Field *);
bool isName(TextField *txt, Field *msg);
public:
mainScreen();
int edit();
~mainScreen();
};
/*create all the fields */
mainScreen::mainScreen():msgField(24,2,70,""),txtStudId(4,15,10," ",9,isID,&msgField),Records(NULL){
....
_mainS.addField(new Label(6,2,"Student Name: "));
_flds[Name]=_mainS.addField(new TextField(6,17,30,currentRecord->r.studName,30,isName,&msgField));
--->The constructor takes a bool (*isValid)(TextField *,Field *) function pointer(this works when the function is not declared in the class, but I need to declare it inside to do something)
_msgs[Name]=_mainS.addField(new Field(7,2,30,""));
}
//Validation functions
...
//checks name
bool mainScreen::isName(TextField *txt, Field *msg) {
bool ok = true;
if (txt->getLength() == 0) {
ok = false;
if (msg != NULL) {
msg->setData("Enter Student Name");
msg->display();
}
} else {
char *name = new char[txt->getLength() + 1];
txt->getData(name);
for(int i=0;name[i]!='\0';i++){
if(i==0 && isalpha(name[i]) || name[i-1]==' ')
name[i]=toupper(name[i]);
else
name[i]=tolower(name[i]);
}
txt->setData(name);
delete [] name;
}
return ok;
}
....
int main()
{
mainScreen mS;
mS.edit();
return 0;
}
any ideas would be appereciated, thank you