|
Hi Waldermort
By default nothing is visible to COM from .net.
But it is easy to make it the default. This can be done at three different levels:
- the Assembly (basically the codepackage, or in many cases, the DLL)
- a class
- a method
So if you declare the Assembly ComVisible, then all the classes inside, and their methods are by default visible.
Declaring something visible to COM is done using attributes in .net (a form of metadata).
You set this in the AssemblyInfo.cs file by:
- importing the namespace System.Runtime.InteropServices by declaring
using System.Runtime.InteropServices at the top of the file.
- somewhere add the line
[assembly: ComVisible(true)]
Hope this helps
Kind regards - Jakob
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!
10 kinds of people in the world:
- Those who understand binary
- Those who don't
|
|
|
|
|
Hi All,
Could any of you kind folk give me some tips on this quandry?
I'm designing an application that will need to access a database. Having learnt about the benefits of OOP I've decided to manage the database with a DataAccess class, rather than have each object access the database independently. However, I'd only want to have one DataAccess object instantiated within the application - so my question is "how can I make the DataAccess object visible to each object within the application".
Any advice appreciated!
-- modified at 13:28 Thursday 13th April, 2006
|
|
|
|
|
This design pattern is commonly called the Singleton, so you can look up some more information if you want. The easiest way is to make the class Public Static. That way all the functions inside the class can be called without creating an instance of the class, emulating one global, Application-wide instance.
|
|
|
|
|
|
In VB6 we have app.path which returns the path of the application, how do we do this in c#????
|
|
|
|
|
In C# 2.0 you can use:
Application.StartupPath
And this will work in 1.1 and 2.0
private void button1_Click(object sender, System.EventArgs e)
{
string path;
path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );
MessageBox.Show( path );
}
Cheers,
Martin
-- modified at 13:45 Thursday 13th April, 2006
|
|
|
|
|
|
hi i need to call
doPostback(...).
how to do that
|
|
|
|
|
call the function like any other function.
What is the problem?
--------------------------------------------------------
My development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
I have created a new tool that uses reflection to find some subcontrols. When loading the new tool into a window in designer mode, I get errors from the control that I think are related to finding the subcontrols.
Is there a good way to debug code being used in designer mode? The control functions correctly when I run it directly. Also, when a control is added to the tool box, what is a good way to refresh it without closing and reopening the project.
gsquared
|
|
|
|
|
Try to separate code for design and code fore runtime.
You can use constuction:
if (this.DesignMode)
{
// Design actions
}
else
{
// Runtime actions
}
You can save info to logfile.
Also you can see callstack, when you see error - analize this info.
Best regards, Alexey.
|
|
|
|
|
How can I write in the fields of a form outside of its class? For example, I have a Form1 and a DoWork class. I want the DoWork class write something in a text field in Form1. I can't access the fields directly, so there should be another way.
|
|
|
|
|
This question is asked so many times in the forum....you really ought to search the forum before asking.
Basically, create a property in your form that exposes the variable:
string myVar;
...
public string MyVar
{
get
{
return myVar;
}
}
And your DoWork class just needs an instance of Form1 to access its public members:
class DoWork
{
private Form1 form;
public DoWork(Form1 formInstance)
{
this.form = formInstance;
string theVar = this.form.MyVar;
}
}
|
|
|
|
|
adol_w wrote: I can't access the fields directly, so there should be another way.
What exactly do you mean with that?
Some first guesses:
Change their visibility to public or better declare a public property with get- and/or set-body (as needed) to access them.
Hand over an instance of your Form1 class when you construct the DoWork class instance, store it in a private field and use it to access the fields when needed.
www.troschuetz.de
|
|
|
|
|
The quick and proper way:
Create public properties for the fields in DoWork and access them that way.
The slow and sneaky way: Use Reflection, like this:
FieldInfo fi = myDoWork.GetType().GetField("someFieldInDoWork", BindingFlags.NonPublic | BindingFlags.Instance);<br />
fi.SetValue(myDoWork, someValue);
Regards,
Alvaro
The bible was written when people were even more stupid than they are today. Can you imagine that? - David Cross
|
|
|
|
|
This has been asked so many times I wrote an article about it: See Passing values to forms[^]
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Sorry, I can't believe I didn't see that article. Thanks for the answers. I just hope nothing significant has changed in .net 2.0.
|
|
|
|
|
Hi
I am doing a division and the result gives me an answer with decimal places. How do I remove all the characters after the decimal place?
|
|
|
|
|
double d = 13/7;
int i = Convert.ToInt32(d);
|
|
|
|
|
|
That depends.
Do you want to truncate or round the value?
Are you going to process the value further, or is it only to be displayed?
If you want to truncate the value (remove decimal part), cast the value to int or use Math.Truncate.
If you want to round the value (to nearest integer), use Math.Round.
If you want to round it only for displaying it, do the rounding when you convert it to a string, using ToString("n0").
---
b { font-weight: normal; }
|
|
|
|
|
hi
How to invoke post back.I need some function like invalidRect in win app.
thank you for help
best regards
|
|
|
|
|
Form.Invalidate(Rectangle)
|
|
|
|
|
Hi All,
A Text Box on a Form of mine is bound to a Numeric SQL Server field. Is there any easy way to Format the contents to : '9.00', and Not '9.0000' as it is at the moment?
[I Bind in code so was thinking I could include formatting there]
Thanks
Jonny
|
|
|
|
|
Take a look at this MSDN topic covering Numeric Format Strings[^].
There may also be a way doing the formatting during data binding. I remember doing something like that on my website. But to help you specifically with that some code would be helpful.
www.troschuetz.de
|
|
|
|