Hi,
I have a problem with saving data to an object and displaying it. I am calling two functions, one to enter the data into object, and second to display that object data. When i try to debug the program using breakpoints, i see that the data is saved into the object attribute values, but when the display function is called, it sees and displays only the data to which the object is initialised by the class constructor. Basically the object attributes already contain the default values.
Here is the code:
Please help me out!
I have a problem with saving data to an object and displaying it. I am calling two functions, one to enter the data into object, and second to display that object data. When i try to debug the program using breakpoints, i see that the data is saved into the object attribute values, but when the display function is called, it sees and displays only the data to which the object is initialised by the class constructor. Basically the object attributes already contain the default values.
Here is the code:
Code:
Unit1.cpp: #include "Unit1.h" #include "EmployeeList.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; static int Size = 0; static int i = -1; void __fastcall TForm1::CreateEmployeeButtonClick(TObject *Sender) { theEmployeeList.addEmployee(i, Size); theEmployeeList.getEmployee(i).create(EnterEmployeeName, EnterEmployeeSurname, EnterEmployeeSocialNumber, EnterEmployeeSalary); theEmployeeList.getEmployee(i).display(NameField, SurnameField, SocialNumberField, SalaryField); } ___________________________________ ___________________________________ EmployeeList.cpp: #include <vcl.h> #pragma hdrstop #include "Employee.h" #include "EmployeeList.h" //---------------------------------------------------------------------------- Employee *myEmployeeList[10]; static int ListSize=0; void EmployeeList :: addEmployee(int &i, int &SIZE) { i = SIZE; myEmployeeList[i]=new Employee; SIZE++; ListSize = SIZE; } Employee EmployeeList :: getEmployee(int index) { return *myEmployeeList[index]; } ___________________________________ ___________________________________ Employee.cpp #include <vcl.h> #pragma hdrstop #include "Employee.h" //--------------------------------------------------------------------------- void Employee :: create(TEdit *EnterEmployeeName, TEdit *EnterEmployeeSurname, TEdit *EnterEmployeeSocialNumber, TEdit *EnterEmployeeSalary) { //initialise data FirstName = EnterEmployeeName->Text; Surname = EnterEmployeeSurname->Text; Salary = StrToFloat(EnterEmployeeSocialNumber->Text); SocialNumber = StrToInt(EnterEmployeeSalary->Text); } void Employee :: display (TLabel *NameField, TLabel *SurnameField, TLabel *SocialNumberField, TLabel *SalaryField) { (*NameField).Caption = FirstName; (*SurnameField).Caption = Surname; (*SocialNumberField).Caption = SocialNumber; (*SalaryField).Caption = Salary; } Employee :: Employee() { FirstName = ""; Surname = ""; SocialNumber = -1; Salary = -1; } Employee :: ~Employee() { }
Comment