Click here to Skip to main content
15,889,900 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to discard invalid (ASCII 0-32) user input in editbox? Pin
kubben10-Apr-07 12:15
kubben10-Apr-07 12:15 
GeneralRe: How to discard invalid (ASCII 0-32) user input in editbox? [modified] Pin
SandeepN10-Apr-07 12:39
SandeepN10-Apr-07 12:39 
QuestionXslCompiledTransform.Transform() to a string Pin
eggie510-Apr-07 8:56
eggie510-Apr-07 8:56 
AnswerRe: XslCompiledTransform.Transform() to a string Pin
eggie510-Apr-07 9:24
eggie510-Apr-07 9:24 
QuestionStoring references in a class Pin
Ephoy10-Apr-07 8:39
Ephoy10-Apr-07 8:39 
AnswerRe: Storing references in a class Pin
Martin#10-Apr-07 9:11
Martin#10-Apr-07 9:11 
GeneralRe: Storing references in a class Pin
Ephoy10-Apr-07 10:09
Ephoy10-Apr-07 10:09 
GeneralRe: Storing references in a class [modified] Pin
Martin#11-Apr-07 3:11
Martin#11-Apr-07 3:11 
Hello Lothver,

I think I understand what you want todo!
But I also think it's not possible in the way you are triing to implement.
Cause you will only give the reference of the actual value to the other modul.

I modified your test project that a notification is done if a value changed.
Therefore the input and output has to be a seperate class, which is a base IO class.
This class implements a ValueChanged event.

But I stop the explination write now and post the code.

class IO
{
    private object value1 = new object();

    public IO(object _value1)
    {
        value1 = _value1;
    }
    public IO()
    {
    }

    public object Value1
    {
        get
        {
            return value1;
        }
        set
        {
            if(value !=value1)
            {
                value1 = value;
                if(ValueChanged!=null)
                {
                    ValueChanged(this, EventArgs.Empty);
                }
            }
        }
    }

    public event EventHandler ValueChanged;
}

class module
{
    private IO input; // use objects for reference
    public IO output; // needs to be public to set up the reference in later modules. (I know its ugly/bad)

    public module(object source)
    {
        IO io = source as IO;
        if(io!=null)
        {
            this.input = io;
            io.ValueChanged+=new EventHandler(io_ValueChanged);
        }
        else
        {
            this.input = new IO(source); // save the reference to the source
        }
        this.output = new IO(); // create new instance for next module to reference
    }

    public void compute(int i)
    {
        this.output.Value1 = (int)this.input.Value1 + i;
    }

    public int getOutput()
    {
        return (int)this.output.Value1;
    }

    private void io_ValueChanged(object sender, EventArgs e)
    {
        IO io = sender as IO;
        if(io!=null)
        {
            this.input = io;
        }
    }
}

class TestClass
{
    public static int test()
    {
        Object firstInput = (int)1;
        module mod1 = new module(firstInput);
        module mod2 = new module(mod1.output);
        mod1.compute(2);
        mod2.compute(3);
        int result = mod2.getOutput();
        return result; // result is 6 now
    }
}


Please tell me if it is working for your needs, although it's not what you wanted!

All the best,

Martin


-- modified at 9:18 Wednesday 11th April, 2007
AnswerRe: Storing references in a class Pin
Scott Dorman10-Apr-07 17:48
professionalScott Dorman10-Apr-07 17:48 
GeneralRe: Storing references in a class Pin
Ephoy11-Apr-07 0:11
Ephoy11-Apr-07 0:11 
GeneralRe: Storing references in a class Pin
Scott Dorman12-Apr-07 2:53
professionalScott Dorman12-Apr-07 2:53 
Questionconvert grayscale array to Image Pin
aei_totten10-Apr-07 7:17
aei_totten10-Apr-07 7:17 
QuestionMDI application childform maximize Pin
sinosoidal10-Apr-07 6:33
sinosoidal10-Apr-07 6:33 
AnswerRe: MDI application childform maximize Pin
il_masacratore11-Apr-07 21:29
il_masacratore11-Apr-07 21:29 
QuestionString Manipulation Question Pin
JMOdom10-Apr-07 6:20
JMOdom10-Apr-07 6:20 
AnswerRe: String Manipulation Question Pin
Are Jay10-Apr-07 8:47
Are Jay10-Apr-07 8:47 
QuestionC# accessing Excel Pin
shamidi10-Apr-07 5:55
shamidi10-Apr-07 5:55 
AnswerRe: C# accessing Excel Pin
led mike10-Apr-07 7:39
led mike10-Apr-07 7:39 
QuestionFileWatcher Pin
LCI10-Apr-07 5:32
LCI10-Apr-07 5:32 
AnswerRe: FileWatcher Pin
vineas10-Apr-07 5:48
vineas10-Apr-07 5:48 
QuestionUser Control - comments for public properties in form designer Pin
peterchen10-Apr-07 5:13
peterchen10-Apr-07 5:13 
AnswerRe: User Control - comments for public properties in form designer Pin
Martin#10-Apr-07 5:40
Martin#10-Apr-07 5:40 
QuestionListview and remove or disallow duplicates Pin
Saamir10-Apr-07 5:07
Saamir10-Apr-07 5:07 
AnswerRe: Listview and remove or disallow duplicates Pin
Saamir10-Apr-07 6:51
Saamir10-Apr-07 6:51 
QuestionReference type or not Pin
hamidkhan10-Apr-07 4:38
hamidkhan10-Apr-07 4:38 

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.