What am I doing wrong here ???

  • Thread starter Thread starter tiger79
  • Start date Start date
T

tiger79

Hello,
I've made an API which I reference to in one of my programs.
In this API I got a class with some const string variables (not that
variable though ;) )
Now I'd like to copy its values in the calling class :
I'll show some code :
This is the calling function :
obviously using
using Dictionarytest1;

public Form1()

{

InitializeComponent();

Dictionarytest1.peccDictionary Dictionary = new peccDictionary();

ShowDictionary();

}

private void ShowDictionary()

{

name = Dictionary.GetName();

version = Dictionary.GetVersion();

description = Dictionary.GetDescription();

MessageBox.Show("The next Dictionary has been instantiated : "+name+",
version : "+version+", description : "+description+". It's entities will be
loaded");

}



Ok so I made those get functions so that I could retrieve the interested
const variables :



amespace Dictionarytest1

{

public class peccDictionary

{

public const string NAME = "TestDictionary";

public const string VERSION = "0,7";

public const string DESCRIPTION = "First test-version of Dictionary";

public peccDictionary()

{



peccEntities Entities = new peccEntities();

}

public string GetName()

{

return NAME;

}

public string GetVersion()

{

return VERSION;

}

public string GetDescription()

{

return DESCRIPTION;

}

}

}



Ok, can anyone see what I am doing wrong here ?

BTW, the error I get is a nullexception error :(
 
tiger79 said:
Hello,
I've made an API which I reference to in one of my programs.
In this API I got a class with some const string variables (not that
variable though ;) )
Now I'd like to copy its values in the calling class :
I'll show some code :
This is the calling function :
obviously using
using Dictionarytest1;

public Form1()
{
InitializeComponent();
Dictionarytest1.peccDictionary Dictionary = new peccDictionary();
ShowDictionary();
}

private void ShowDictionary()
{
name = Dictionary.GetName();
version = Dictionary.GetVersion();
description = Dictionary.GetDescription();
MessageBox.Show("The next Dictionary has been instantiated : "+name+",
version : "+version+", description : "+description+". It's entities will be
loaded");
}

Assuming you've also got an instance variable called Dictionary, the
problem is that in your constructor you're creating a new local
variable rather than setting the value of the instance variable.
 
U mean in the Form1() Constructor ???

Jon Skeet said:
Assuming you've also got an instance variable called Dictionary, the
problem is that in your constructor you're creating a new local
variable rather than setting the value of the instance variable.
 
tiger79 said:
U mean in the Form1() Constructor ???

Yes. There's no way that ShowDictionary can get at the local variable
you're declaring in the Form1 constructor.
 
tiger79 said:
using Dictionarytest1;

public Form1()
{
InitializeComponent();
Dictionarytest1.peccDictionary Dictionary = new peccDictionary();
ShowDictionary();
}

private void ShowDictionary()
{
name = Dictionary.GetName();
version = Dictionary.GetVersion();
description = Dictionary.GetDescription();
MessageBox.Show("The next Dictionary has been instantiated : "+name+",
version : "+version+", description : "+description+". It's entities will be
loaded");
}

You declare Dictionary in the Form1 constructor as a local variable.
Try this instead...

Dictionarytest1.peccDictionary Dictionary;
public Form1()
{
InitializeComponent();
Dictionary = new peccDictionary();
ShowDictionary();
}
 
Back
Top