|
-
Oct 24th, 2005, 10:56 AM
#1
Thread Starter
Frenzied Member
need help with CreateObject equivalent in C#
I've tried CreateObject and it does not work in C#. So i tried:
Type t = Type.GetTypeFromProgID("MyObject.Class1");
Object o = Activator.CreateInstance(t);
This works to the point where it compiles and runs. However, when I try to use one of MyObject's methods, it gives me an error:
'object' does not contain a definition for 'MyFunction'
Any ideas on how to do this correctly?
-
Oct 24th, 2005, 11:19 AM
#2
Re: need help with CreateObject equivalent in C#
This is off the top of my head and I'm not at a machine where I can test it but:
Create an Interface which your class implements
then instead of using an object use the interface
Type t = Type.GetTypeFromProgID("MyObject.Class1");
interface1 o = (interface1)Activator.CreateInstance(t);
-
Oct 24th, 2005, 11:51 AM
#3
Thread Starter
Frenzied Member
Re: need help with CreateObject equivalent in C#
-
Oct 24th, 2005, 12:01 PM
#4
Thread Starter
Frenzied Member
Re: need help with CreateObject equivalent in C#
By the way, do you know how to SET and GET public properties of the "MyObject"?
-
Oct 24th, 2005, 02:41 PM
#5
Re: need help with CreateObject equivalent in C#
 Originally Posted by benmartin101
By the way, do you know how to SET and GET public properties of the "MyObject"?
I'm not sure what you mean? If you use an interface you'll know what methods are available. To enumerate all the methods you can use the MethodInfo,MemberInfo and ParamaterInfo classes in conjunction with the Type class which has a number of get methods GetMethod, get Memeber etc.
hmm, how many times can I fit the word "method" into a paragraph.
-
Oct 24th, 2005, 06:20 PM
#6
Thread Starter
Frenzied Member
Re: need help with CreateObject equivalent in C#
No, i mean like...my class has a name property. In vb, the code would be:
dim obj as new MyObject
obj.name = "john"
how do I do that in c#?
-
Oct 26th, 2005, 09:02 AM
#7
Hyperactive Member
Re: need help with CreateObject equivalent in C#
Do it just like the vb (obj.property) , with the dot property. If it's not working, then that property is declared as private, either declare the property as public or create a getmethod for the private property so (obj.getProperty()).
-
Oct 26th, 2005, 10:47 AM
#8
Fanatic Member
Re: need help with CreateObject equivalent in C#
Hi,
best way in c# to do this is to overload it, then assign the contents upon the object instantiation
class clsClass
{
private string me;
private stirng you;
public clsClass(string me, string you)
{
this.me = me;
this.you = you;
}
public virtual void DecalreValues()
{
// define any mothodology here such as declaring obvjects blah blah
}
}
public static void Main()
{
clsClass youandme = new clsClass("kaihirst", "benmartin101")
or you could do it like ...
youandme.me = "kaihirst";
youandme.you = "benmartin101";
//decalring a method is still the same throughout, in case you dont know
youandme.DeclareValues()
}
hope this helps.
ta
kai
As the information I give is useful in its nature, consider using the RATE POST feature located on the bottom left of this post please..
A few things that make a good Developer a Great One.
Methodical and a thorough approach to research and design inevitably leads to success.
Forward thinking is the key to Flow of control.
Never test in the design environment, always test in real time, you get the REAL results.
CBSE & OOSE are the same animal, they just require different techniques, and thinking.
SEO is a globe of objectives, SE rankings is an end to a means for these objectives, not part of them.
The key to good design is explicit attention to both detail and response.
Think Freely out of the "Box" you're in..... You will soar to better heights.
Kai Hirst - MSCE, MCDBA, MCSD, MCP, MCAP, MSCT
-
Oct 26th, 2005, 02:52 PM
#9
Thread Starter
Frenzied Member
Re: need help with CreateObject equivalent in C#
I can't make changes to it. It's a COM dll. I just wanted to know how I would access their properties and functions if I was to do "late binding" instead of "early binding"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|