Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compiler can't find method

Status
Not open for further replies.

seanbo

Programmer
Jun 6, 2003
407
GB
i have a method which is receiving an object of type 'object'. i want to call a method within that object, which exists because the object i'm sending it was written by me, but the compiler won't have it. it says' that 'object' doesn't contain such a method, which is true, but my extension of object does.

how can i get the code to compile and catch any exception that might be thrown should the method not be there? note - i don't want to parse my 'object' as what i'm actually sending it, i want my code to remain versatile and durable.
 
update: i now have the same error again under a slightly different situation. i have used the activemdichild property so that i can call a method within one of my child forms. the method i've written is called createBarGraph, but because the compiler thinks i have a generic form it tells me that i don't have that method - but i do. this is beginning to be a real pain. i just want to call methods that exists, is that too much to ask?

help please
 
simple solution: conversion.
example:
if you use the queue class and the objects in your queue are some struct, and you want to pop an instance of the struct from the queue:
struct A
{
...
}
A a;
a = (A)q.pop();

If it doesn't work with you problem, try to make an instance of your class in the method and copy the object to it, and then call the class function.
 
You can also inline your casting like so:

((A) q.pop()).somethingInA();

or you can use Reflection like so:

object obj = q.pop();
obj.getType().InvokeMember("somethingInA", BindingFlags.InvokeMethod, null, obj, null);

but it is slower to use Reflection than casting.

"Programming is like sex, one mistake and you have to support it forever."

John

johnmc@mvmills.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top