I am new to VC++ programming. I need to create 2 forms and and collect the data that is input in the forms to a class. Now the forms are defined in the form1.h and form2.h files. I have a class "Railway_Input" in the main cpp file. The cpp file runs the form1 by the command

where Ipform is an object of the class for form1. The form2 class is called within the form1.h file.

I cannot access the Ipform->textBox->Text values in the main cpp file, using the Ipform object. As it complains that the attributes are private and I cant access it. I want to know if VC++ provides getter and setter for each of these properties(like textbox,radiobutton) ?If yes what are they called. I did not find a getText() function for textbox, so not sure what member function I should be looking for.

Another way of doing it is declaring the private variables public , which I do not think is right.
If the getter, setters are not provided I could write one for each of the form required elements.

Please let me know what I could do. Also please provide me some good books or links for VC++ programming.


9 Years
Discussion Span
Last Post by question!!

>I want to know if VC++ provides getter and setter
>for each of these properties(like textbox,radiobutton) ?
No, but it's trivial to write them yourself. You can also force generated controls to be public, but that's not a good practice.


Thx for tht!!

I do have a new problem though :( .

I am designing a project with two input forms. Now the data in the 2 forms is to be assigned into the class attributes of the class "Railway_Input" which is defined in the .cpp file. The main function looks as folllows. A form1.h file defines the class Form1.

int main(array<System::String ^> ^args)
    //Rail_Input RS;
    Form1^ Ipform = gcnew Form1();
    // Enabling Windows XP visual effects before any controls are created

    // Create the main window and run it
    return 0;

I first call the forms by the Application::Run command, once the data is entered I need that to be entered in the class Railway_Input. So the Railway_Input attributes are populated from the Ipform object of the form. So could I write the code for that after the Application::Run command?

When I run my program now it compiles but gives me an execution error. But if instead of using the object Ipform in the command Application::Run(IPform), I say Application::Run(gcnew Form1()). The program executes. I have pasted my error below. Please tell me what I am doing wrong.

Also sugest any good books or websites for VC++ project development

'Window_form.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\\mscorlib.dll', No symbols loaded.
'Window_form.exe' (Managed): Loaded 'c:\Documents and Settings\Lab\My Documents\Visual Studio 2005\Projects\Window_form\debug\Window_form.exe', Symbols loaded.
'Window_form.exe' (Managed): Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_5490cd9f\msvcm80d.dll', Symbols loaded.
'Window_form.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System\\System.dll', No symbols loaded.
'Window_form.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\\System.Windows.Forms.dll', No symbols loaded.
'Window_form.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\\System.Drawing.dll', No symbols loaded.
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll

Additional information: SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.

The program '[2948] Window_form.exe: Managed' has exited with code -532459699 (0xe0434f4d).

Thx in Advance

Edited by Reverend Jim: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.