Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
GeneralRe: Passing pointers 'round and 'round? Pin
o m n i8-Dec-09 19:58
o m n i8-Dec-09 19:58 
GeneralRe: Passing pointers 'round and 'round? Pin
Richard MacCutchan8-Dec-09 22:25
mveRichard MacCutchan8-Dec-09 22:25 
QuestionC++ project to c# Pin
faheemnadeem8-Dec-09 18:37
faheemnadeem8-Dec-09 18:37 
AnswerRe: C++ project to c# Pin
dan!sh 8-Dec-09 18:42
professional dan!sh 8-Dec-09 18:42 
GeneralRe: C++ project to c# Pin
faheemnadeem8-Dec-09 19:22
faheemnadeem8-Dec-09 19:22 
AnswerRe: C++ project to c# Pin
N a v a n e e t h8-Dec-09 20:56
N a v a n e e t h8-Dec-09 20:56 
AnswerRe: C++ project to c# Pin
Dave Doknjas9-Dec-09 11:49
Dave Doknjas9-Dec-09 11:49 
QuestionMe, again... Confused Again... Pin
Roger Wright8-Dec-09 18:29
professionalRoger Wright8-Dec-09 18:29 
I thought passing an object to another object would be easy, since objects are passed by reference. Wrong.

I've managed to populate the members of an object nicely, using a series of forms for user input - that was no mean feat for me, but it works. The next step in my plan was to pass the object on to another slice of code for handling the interface to a database. If I can get that to work, it's about 75% of what the program has to do. I thought I understood that objects, as reference types, could be passed as parameters to other parts of the program, but I'm having difficulty doing so. In fact, I haven't found anything here or via Google that clearly shows anyone else trying this, so I may be completely off base.

To test my approach without getting into the database can of worms, I thought I'd test ways to do this by creating yet another form, passing the object to it, then extracting the individual members to labels for display. If that works, I can apply the same principles to a database handler module of some kind.

First I tried creating the test form with a constructor that takes one argument - my object. When I instantiated the form I passed the local object as an argument. That compiled nicely, but crashed with an unhandled null object exception. I then tried creating the form without the argument, but before displaying it, set the object member in the display form equal to the local object. Same error. I'm either trying to do something impossible, or I'm missing something important here and have no idea what it is. A partial listing follows:

Calling Form:

//Demonstrate passing object Rec to another Form object 
                    frmShowForm frmShowRec = new frmShowForm(Rec);
                    
                    if (frmShowRec.ShowDialog(this) == DialogResult.OK)
                    {
                        frmShowRec.Hide();
                        frmShowRec.Dispose();


Display Form:

public partial class frmShowForm : Form
    {
        public frmShowForm(Recloser recshow)   //Test page to demonstrate passing a Ref object
        {
            Recloser RecShow = new Recloser();
            RecShow = recshow;
            label1.Text = RecShow.Serial;
            this.label2.Text = RecShow.Mfr;
            this.label3.Text = RecShow.Type;
            this.label4.Text = RecShow.Vrated;
            this.label5.Text = RecShow.BIL;


Before anyone comments, I tried the above with and without the 'this' modifier; there was no change in the error message. If either way is preferable (or necessary) I'd appreciate knowing it. This is just the latest attempt, as I've been at it all night trying different approaches to the problem and searching here and with Google. I know I could create a bunch of local variables in the calling form and pass them into the display form, but that would defeat my purpose, which is to accomplish this with as little work as possible. Typical engineer...

Thanks in advance for any assistance!

"A Journey of a Thousand Rest Stops Begins with a Single Movement"

AnswerRe: Me, again... Confused Again... Pin
dan!sh 8-Dec-09 18:46
professional dan!sh 8-Dec-09 18:46 
GeneralRe: Me, again... Confused Again... Pin
Roger Wright8-Dec-09 18:52
professionalRoger Wright8-Dec-09 18:52 
GeneralRe: Me, again... Confused Again... Pin
dan!sh 8-Dec-09 19:11
professional dan!sh 8-Dec-09 19:11 
GeneralRe: Me, again... Confused Again... Pin
Roger Wright8-Dec-09 19:19
professionalRoger Wright8-Dec-09 19:19 
GeneralRe: Me, again... Confused Again... Pin
dan!sh 8-Dec-09 19:20
professional dan!sh 8-Dec-09 19:20 
GeneralRe: Me, again... Confused Again... Pin
Roger Wright8-Dec-09 20:17
professionalRoger Wright8-Dec-09 20:17 
GeneralRe: Me, again... Confused Again... Pin
N a v a n e e t h8-Dec-09 21:09
N a v a n e e t h8-Dec-09 21:09 
AnswerRe: Me, again... Confused Again... Pin
N a v a n e e t h8-Dec-09 21:05
N a v a n e e t h8-Dec-09 21:05 
Questionhow to i delete the file Pin
Joe Rozario8-Dec-09 17:08
Joe Rozario8-Dec-09 17:08 
AnswerRe: how to i delete the file Pin
SeMartens8-Dec-09 20:52
SeMartens8-Dec-09 20:52 
GeneralRe: how to i delete the file Pin
Joe Rozario8-Dec-09 21:36
Joe Rozario8-Dec-09 21:36 
GeneralRe: how to i delete the file Pin
SeMartens8-Dec-09 21:46
SeMartens8-Dec-09 21:46 
Questionpopulate treeview from database Pin
kruegs358-Dec-09 13:28
kruegs358-Dec-09 13:28 
AnswerRe: populate treeview from database Pin
Richard Blythe8-Dec-09 17:50
Richard Blythe8-Dec-09 17:50 
GeneralRe: populate treeview from database Pin
kruegs359-Dec-09 3:10
kruegs359-Dec-09 3:10 
QuestionReportViewer 2005 C# Printing issue [modified] Pin
.NET4Ever8-Dec-09 12:26
.NET4Ever8-Dec-09 12:26 
QuestionTo be liberal or conservative with virtual methods... Pin
CaptainSeeSharp8-Dec-09 10:13
CaptainSeeSharp8-Dec-09 10:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.