CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    938

    Hash Map and Delegates

    Hey,
    I ran into the following problem. I created a hash map, and i am populating it with delegates.
    Code:
    Commands.Add("ANS", new CommandDelegate(ANS));
    Now, this goes fine, but when i attempt to call the function i get an error.;
    Code:
    Commands[ServCom.CommandName](ServCom);
    The error is:
    Code:
    Error	1	Method name expected
    Any ideas on why this fails?

    Thx in advance.

  2. #2
    Join Date
    Jan 2007
    Posts
    491

    Re: Hash Map and Delegates

    Try to reconvert it to Delegate (or CommandDelegate) first.

  3. #3
    Join Date
    Aug 2003
    Posts
    938

    Re: Hash Map and Delegates

    Found a solution:
    Code:
     CommandDelegate cmd = (CommandDelegate)Commands[ServCom.CommandName];
                        cmd(ServCom);

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Hash Map and Delegates

    Why are you using .NET 1.1 collections instead of the generics that are available for the last three years with .Net 2.0?????
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured