-
September 3rd, 2015, 06:55 AM
#1
Transferring data from a form to a separate class file
Hi,
I have a form where the user selects strings from combo boxes and text-boxes in the form of flight destination cities, user name, and number of passengers. I have to make separate custom class files that pulls that information, adds specific parts and then returns it back to be displayed in the form. I am having problems pulling the information from the form to create passenger, ticket, and destination city objects from the appropriate classes and put the data from the form into those objects. I need help figuring out what I am missing. I've had issues because of lacking resources, so any help would be appreciated. Thanks.
My Form.h
#pragma once
#include "Ticket.h"
#include "Passenger.h"
#include "Destinations.h"
namespace TicketGUI {
using namespace System;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:ata;
using namespace System:rawing;
/// <summary>
/// Summary for TGUIForm
/// </summary>
public ref class TGUIForm : public System::Windows::Forms::Form
{
public:
TGUIForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~TGUIForm()
{
if (components)
{
delete components;
}
}
Passenger^NInfo;
Passenger^YInfo;
///////////////////////////////////////////////
}
#pragma endregion
private: System::Void TGUIForm_Load(System::Object^ sender, System::EventArgs^ e) {
Passenger^ nPassenger = gcnew Passenger();
nPassenger->NInfo = NameP->Text;
nPassenger->YInfo = YOB->Text;
}
The Passenger.h
#pragma once
#include "TGUIForm.h"
#ifndef PASSENGER_H
#define PASSENGER_H
using namespace System;
public ref class Passenger
{
private:
String^ Nm;
String^ Yr;
public:
Passenger(){
}
Passenger(String^ name, String^ YOB);
String^ NInfo(void);
String^ YInfo(void);
};
The Passenger.cpp file;
#include "Passenger.h"
#include "TGUIForm.h"
using namespace System;
Passenger::Passenger(String^ name, String^ YOB){
Nm = name;
Yr = YOB;
}
String^ Passenger::NInfo(void){
return Nm;
}
String^Passenger::YInfo(void){
return Yr;
}
#endif
-
September 4th, 2015, 07:44 AM
#2
Re: Transferring data from a form to a separate class file
Your question is rather vague. What are the concrete problems you're facing, like compilation error messages or exceptions you get, or data objects not having the expected values?
Your TGUIForm_Load() event handler probably dos not do what you want: The Passenger object you're creating there is a local variable, which means that it is gets lost as soon as the handler function exits.
Please use code tags when posting code.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|