Click here to Skip to main content
15,913,115 members
Home / Discussions / C#
   

C#

 
AnswerRe: Microsoft Office Translations Pin
Ed.Poore19-Mar-07 13:03
Ed.Poore19-Mar-07 13:03 
QuestionProblem receiving data through serial port Pin
naffilk18-Mar-07 2:46
naffilk18-Mar-07 2:46 
AnswerRe: Problem receiving data through serial port Pin
rbirkelbach19-Mar-07 5:03
rbirkelbach19-Mar-07 5:03 
Questionc# word xp textbox Pin
spinis18-Mar-07 0:00
spinis18-Mar-07 0:00 
AnswerRe: c# word xp textbox Pin
Thomas Stockwell19-Mar-07 8:26
professionalThomas Stockwell19-Mar-07 8:26 
QuestionBioinformatic algorithms in C# Pin
bufugus17-Mar-07 23:50
bufugus17-Mar-07 23:50 
AnswerRe: Bioinformatic algorithms in C# Pin
b0ksah19-Mar-07 0:28
b0ksah19-Mar-07 0:28 
QuestionGeneral info passer? Pin
gvanto17-Mar-07 22:39
gvanto17-Mar-07 22:39 
I am trying to create a class which other classes can use for passing info to the main form, called: class InfoDisplay:

<code>
class InfoDisplay
{
public delegate void ehMainInfoShow(string s);
public event ehMainInfoShow evtMainInfoShow;

public InfoDisplay()
{
// do nothing
}

public void ShowMainInfo(string s)
{
evtMainInfoShow(s);
}
}
</code>

In my main form's constructor, I have the following (for linking the delegate to the function I think?):

<code>
...
private InfoDisplay m_infoDisp;

public MainForm() // Constructor
{
InitializeComponent();

InfoDisplay m_infoDisp = new InfoDisplay();
m_infoDisp.evtMainInfoShow += new InfoDisplay.ehMainInfoShow(ShowMainInfo);

}

private void btnTest_Click(object sender, EventArgs e)
{
m_infoDisp.ShowMainInfo("Updating file info");
}

private void ShowMainInfo(string s) // Linked to InfoDisplay class for passing data back to Mainform
{
txtBoxInfo.AppendText(s + "\n"); //this puts an annoying square at the end of the line ( ? )
}

</code>
When I click the button which calls the method btnTest_Click, it works fine (outputs the string "Updating file info", to the text box).

However, when another class (all in the same namespace), DataFetcher, below, attempts to create a new InfoDisplay object and call the method ShowMainInfo(), an error results:
<code>
class DataFetcher
{
private InfoDisplay m_infoDisp;

public DataFetcher()
{
m_infoDisp = new InfoDisplay();
}

public void GetData(string fileName)
{
m_infoDisp.ShowMainInfo("Loading file...");
...
// Error occurs on the above line (when the method is called from another class that has created an instance of this one):
// "Object reference not set to an instance of an object."
</code>

If anyone has any help with this problem I'd really appreciate it... Is there a delegate declaration missing somewhere - or perhaps its not possible
to have this arrangement of a general 'proxy' class for passing info to the main form via events..?

Many thanks for any help!

Gerry
C# newbie

Put A Smile On Your Face
http://www.thecrazywebsite.com
AnswerRe: General info passer? Pin
Stefan Troschuetz17-Mar-07 22:58
Stefan Troschuetz17-Mar-07 22:58 
GeneralRe: General info passer? Pin
gvanto17-Mar-07 23:15
gvanto17-Mar-07 23:15 
GeneralRe: General info passer? Pin
Stefan Troschuetz17-Mar-07 23:39
Stefan Troschuetz17-Mar-07 23:39 
QuestionQuestion about office outlook Pin
ThetaClear17-Mar-07 21:56
ThetaClear17-Mar-07 21:56 
AnswerRe: Question about office outlook Pin
ThetaClear18-Mar-07 5:56
ThetaClear18-Mar-07 5:56 
QuestionHow to get textbox (rich or plain) to remain scrolled to the bottom? Pin
sherifffruitfly17-Mar-07 21:06
sherifffruitfly17-Mar-07 21:06 
AnswerRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
Mudsoad17-Mar-07 21:47
Mudsoad17-Mar-07 21:47 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
sherifffruitfly18-Mar-07 6:42
sherifffruitfly18-Mar-07 6:42 
AnswerRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
Stefan Troschuetz17-Mar-07 22:26
Stefan Troschuetz17-Mar-07 22:26 
AnswerRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
Dave Kreskowiak18-Mar-07 6:06
mveDave Kreskowiak18-Mar-07 6:06 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
sherifffruitfly18-Mar-07 6:48
sherifffruitfly18-Mar-07 6:48 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
Dave Kreskowiak18-Mar-07 9:07
mveDave Kreskowiak18-Mar-07 9:07 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
sherifffruitfly18-Mar-07 9:46
sherifffruitfly18-Mar-07 9:46 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
Dave Kreskowiak18-Mar-07 12:19
mveDave Kreskowiak18-Mar-07 12:19 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
sherifffruitfly18-Mar-07 12:45
sherifffruitfly18-Mar-07 12:45 
QuestionGetting pictures from camera Pin
Muammar©17-Mar-07 21:06
Muammar©17-Mar-07 21:06 
AnswerRe: Getting pictures from camera Pin
Christian Graus18-Mar-07 7:40
protectorChristian Graus18-Mar-07 7:40 

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.