Hello.


Here is a description of the class. (Stores name and age)

class Military { private: AnsiString FIO; int Age; public: Military(AnsiString FIOName, int MA):FIO(FIOName),Age(MA){}; Military(){}; ~Military(){}; int get_Age(){return Age;}; void set_Age(int MA){Age=MA;}; 

I create the Military М1; class Military М1;
I set the age of M1.set_Age(int MA) in the form Form1
However, when trying to call ShowMessage(M1.get _Age()); (getting the value of MA) in the form Form2 , zero is output, i.e. The value of the Age variable of the Military class is reset, although when you call ShowMessage(M1.get _Age()); Form1 displays exactly the value that I assigned to MA and indicated in M1.set_Age(int MA) .


The question is how to correct this error so that it is possible to get the class values ​​in the query from any form?

  • You apparently have different objects in two forms. - KoVadim
  • Well on Form1 there is a field Edit1, M1.set_Age (StrToInt (Edit1-> Text)); and on the 2nd, just by clicking on Button1, ShowMessage (M1.get _Age ()) is executed; - BlackOverlord

1 answer 1

You can close, I declared the classes themselves in the header with their description, but did not include them in other forms, extern 'om)