Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two form, form one called IDE and form two called CodeEditor.
This is my code in the constructor :

C#
private CodeEditor FCodeEditor;
public IDE()
        {
InitializeComponent();
FCodeEditor = new CodeEditor(this);
}

//this is method to get string from form CodeEditor

string ILPcodes;
        public string ILPCodes(string codes)
        {
            ILPcodes = codes;
            return ILPcodes;
        }

//then i try to call method signalActiveTheLexer from form code editor to return the string to ILPcodes variable.

public void lex()
{
            FCodeEditor.signalActiveTheLexer();

            //Lexing
            adaptiveILPLexer(ILPcodes);
}


This is constructor for form CodeEditor :

C#
private IDE SendToIDE;
        public CodeEditor(IDE MainForm)
        {
            SendToIDE = MainForm;
        }

//this is the method that i wish can return the code from codeeditor control
public void signalActiveTheLexer()
        {
            SendToIDE.ILPCodes(CodeEditorControl.Text);
        }


the problem i always get null result? why? i change codeeditorcontrol with textbox1.text the result still null. if i using this trick from form to class for interaction the result always success, but form to form i get problem

What I have tried:

i was read this article but i cant see how to solve my problem..
tried to learn about delegate, constructor, properties..

Passing Data Between Forms[^]
Posted
Updated 21-Jul-16 1:00am
v2

1 solution

You have the following method:
C#
public string ILPCodes(string codes)
{
    ILPcodes = codes;
    return ILPcodes;
}

which returns a string.

However when you call it in signalActiveTheLexer
C#
public void signalActiveTheLexer()
{
    SendToIDE.ILPCodes(CodeEditorControl.Text);
}

you do not capture the return value, and even if you did, that method does not return anything. You should change it as follows:
C#
public string signalActiveTheLexer()
{
    return SendToIDE.ILPCodes(CodeEditorControl.Text);
}
 
Share this answer
 
Comments
Gun Gun Febrianza 21-Jul-16 7:33am    
still i get null reference :(

i was using this awesome library (y)
using WeifenLuo.WinFormsUI.Docking;
Gun Gun Febrianza 21-Jul-16 7:59am    
problem solved ! i am forget to add

InitializeComponent();

inside the constructor of codeeditor XD

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900