Click here to Skip to main content
15,911,785 members
Home / Discussions / C#
   

C#

 
GeneralRe: Serialization problem Pin
AB777131-Aug-06 1:29
AB777131-Aug-06 1:29 
GeneralRe: Serialization problem Pin
-Yoyosh-31-Aug-06 7:40
-Yoyosh-31-Aug-06 7:40 
Question.netmodule Pin
waheed awan28-Aug-06 10:03
waheed awan28-Aug-06 10:03 
AnswerRe: .netmodule Pin
Judah Gabriel Himango28-Aug-06 12:37
sponsorJudah Gabriel Himango28-Aug-06 12:37 
Questionhow to access a non-static method from another object? Pin
michal.kreslik28-Aug-06 9:44
michal.kreslik28-Aug-06 9:44 
AnswerRe: how to access a non-static method from another object? Pin
numbers1thru928-Aug-06 9:52
numbers1thru928-Aug-06 9:52 
AnswerRe: how to access a non-static method from another object? Pin
likefood28-Aug-06 10:01
likefood28-Aug-06 10:01 
AnswerRe: how to access a non-static method from another object? [modified] Pin
michal.kreslik28-Aug-06 10:16
michal.kreslik28-Aug-06 10:16 
Thanks much both!

Passing the object itself to the other object to be able to invoke the first object's non-static method does really work.

Anyway, I was thinking about something more universal, like subscribing the AddOne() method as a client of the events of button clicks on the other forms. Would such a subscription be feasible between instantiated classes WITHOUT passing the entire object as a reference?

Something like this:

using System;

namespace ObjectCommunication
{
    public delegate void MyEventHandler(string EventParams);

    public class EntryClass
    {
        public event MyEventHandler MyEvent;

        static void Main()
        {
            EntryClass MyEntryClass = new EntryClass();
            EventDemoClass MyEventDemoClass = new EventDemoClass();
            MyEntryClass.DoWork();
        }

        private void DoWork()
        {
            MyEvent += new MyEventHandler(EventClientMethod_1);
            MyEvent += new MyEventHandler(EventClientMethod_2);

            MyEvent("_event_parameters_");
        }

        private void EventClientMethod_1(string EventParams)
        {
            Console.WriteLine("MyEvent client 1 triggered with these params: " + EventParams);
        }

        private void EventClientMethod_2(string EventParams)
        {
            Console.WriteLine("MyEvent client 2 triggered with these params: " + EventParams);
        }
    }

    public class EventDemoClass
    {
        // how to subscribe EventClientMethod_3 to MyEvent in EntryClass?
        // EventDemoClass is instantiated before MyEvent occurs
        // EventClientMethod_3 cannot be made static since it works with object-specific data
        public void EventClientMethod_3(string EventParams)
        {
            this.DoSomething(EventParams);
        }

        private void DoSomething(string Params)
        {
            Console.WriteLine("MyEvent client 3 triggered with these params: " + Params);
        }
    }
}


Here we would like to subscribe the EventClientMethod_3 method to MyEvent event in EntryClass. That would be more secure than passing the entire object as a reference in a constructor I think.

Thanks,
Michal


-- modified at 19:11 Monday 28th August, 2006
GeneralRe: how to access a non-static method from another object? Pin
Judah Gabriel Himango28-Aug-06 12:50
sponsorJudah Gabriel Himango28-Aug-06 12:50 
QuestionRegarding Final Year Project Pin
Muhammad Chitrali28-Aug-06 9:12
Muhammad Chitrali28-Aug-06 9:12 
AnswerRe: Regarding Final Year Project Pin
Eric Dahlvang28-Aug-06 11:26
Eric Dahlvang28-Aug-06 11:26 
AnswerRe: Regarding Final Year Project Pin
Professor Sharada Ulhas28-Aug-06 12:55
Professor Sharada Ulhas28-Aug-06 12:55 
GeneralRe: Regarding Final Year Project Pin
Muhammad Chitrali29-Aug-06 22:54
Muhammad Chitrali29-Aug-06 22:54 
QuestionHow to extract Image metadata Pin
pasha2k28-Aug-06 8:49
pasha2k28-Aug-06 8:49 
AnswerRe: How to extract Image metadata Pin
Eric Dahlvang28-Aug-06 11:33
Eric Dahlvang28-Aug-06 11:33 
QuestionParse a text file into an object Pin
AndyHug28-Aug-06 8:41
AndyHug28-Aug-06 8:41 
AnswerRe: Parse a text file into an object Pin
Ed.Poore28-Aug-06 9:14
Ed.Poore28-Aug-06 9:14 
AnswerRe: Parse a text file into an object Pin
Not Active28-Aug-06 9:15
mentorNot Active28-Aug-06 9:15 
AnswerRe: Parse a text file into an object Pin
SomeGuyThatIsMe28-Aug-06 9:16
SomeGuyThatIsMe28-Aug-06 9:16 
GeneralRe: Parse a text file into an object Pin
Guffa28-Aug-06 9:35
Guffa28-Aug-06 9:35 
GeneralRe: Parse a text file into an object Pin
SomeGuyThatIsMe28-Aug-06 9:42
SomeGuyThatIsMe28-Aug-06 9:42 
GeneralRe: Parse a text file into an object Pin
AndyHug28-Aug-06 9:41
AndyHug28-Aug-06 9:41 
GeneralRe: Parse a text file into an object Pin
SomeGuyThatIsMe28-Aug-06 10:09
SomeGuyThatIsMe28-Aug-06 10:09 
GeneralRe: Parse a text file into an object Pin
AndyHug30-Aug-06 4:31
AndyHug30-Aug-06 4:31 
GeneralRe: Parse a text file into an object Pin
SomeGuyThatIsMe30-Aug-06 5:02
SomeGuyThatIsMe30-Aug-06 5:02 

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.