|
|
I am trying to create a class that is NOT abstract but is inherited from an abstract class. When trying to create this class using Activator.CreateInstance, I get an error saying: "Cannot create an abstract class". However, I am not tyring to create an instance of an abstract class rather a class that can be instanciated and is not abstract. See code below...
Any ideas?
Thanks in advance.
<pre>
namespace Test
{
[Serializable]
public abstract class Cls1
{
...
public static Cls1 Open()
{
Cls1 provider = null;
string typeName = "Test.Cls3";
Type t = Type.GetType(typeName);
provider = Activator.CreateInstance(t) as Cls1; // <----------- Error Here
}
}
[Serializable]
public abstract class Cls2 : Cls1
{
...
}
[Serializable]
public sealed class Cls3 : Cls2
{
...
}
}
</pre>
-- Modified Wednesday, April 7, 2010 3:08 PM
|
|
|
|
|
Seems to be a bug in VS2008 or could be my crappy Lenovo Laptop. Restarted computer and problem is gone.
|
|
|
|
|
Is it me or is there very little or no information with developing\calling the
Microsoft.Office.Interop particually Microsoft.Office.Interop.MSProject?
Ive googled, msdn etc..
Does anyone know of any really good links\resources or how to work with this?
Im looking, at how to assign uniqueIds to resources, tasks etc and general info
thanks
|
|
|
|
|
|
I am using a folderbrowserdialog to have the user browse for the location of a folder. Once it is located it is copied to a text box. Can I change the text properties of the text box so that path remains there?
Thanks for any help.
Darrall
|
|
|
|
|
I am not sure what you are trying to achieve, but if you want to put the path in a text box so teh user can't then change it, the set the ReadOnly property of the text box to true.
The still leave the question: why put it in a text box if you don;t want the user to change it? Why not use something the user isn't used to changing - a label?
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
It's not a matter of the user changing it - it's that I want it to still be there when the application is closed and reopened. The reason for this is there are text files that are in the program. When you create the text files they are assigned the full path of the application. To access those files I have to hard code the paths in the program. Now some other user stores it in his computer someplace different than me and the paths are all wrong. This way I use a folderbrowserdialog to find the path. I chose a textbox for convenience but the idea is to only have to do this once...not every time you open the application. If after doing it the first time if the properties of the textbox text are that path it is loaded right into the program. Hopes this makes sense.
|
|
|
|
|
1) Right click your project, and select "Add...New Item...Application Configuration File"
2) Add a reference to "System.Configuration.dll", and import the System.Configuration namespace to your .CS file.
3) Double Click your app.config file, and make it look like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="MyFieldName" value="MyField"/>
</appSettings>
</configuration>
4) Load existing path with:
string s = ConfigurationManager.AppSettings["MyFieldName"];
5) Save new path with:
ConfigurationManager.AppSettings["MyFieldName"] = "MyFieldValue";
There are other ways to use application config in .NET, but that one is easy to explain!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Thanks very much for all your time
I'll try what you just sent me.
|
|
|
|
|
Please ignore the previous post - I was in a hurry, and cocked it up completely!
Don't use App.Config, use Settings.Settings instead (App.config will work, but it is harder to save new values, the way I described does not work!)
1) Open your projects Properties in the solution explorer, and double click on "Settings.settings"
2) In the resulting grid, change the Name to "MySetting", and set the Value to "Defaulted value". Leave Type and Scope as sting and User respectively.
3) Save and close the settings window.
4) To read your setting:
string s = Properties.Settings.Default.MySetting;
5) To write your setting:
Properties.Settings.Default.MySetting = "My new setting value";
Properties.Settings.Default.Save();
Sorry about that - in my defence I was in hurry!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Thanks. Where do I write that code? I assume the information in quotes would be my information?
|
|
|
|
|
Anywhere you like!
I would suggest loading the path into the TextBox on form load (and put it into the SelectedPath property of the FolderBrowserDialog as well).
Then when the user presses the OK button in the FolderBrowserDialog, load up the TextBox, and save the new path.
You can replace "MySetting" with your own name(s), and the same for "Defaulted value" and "My new setting value". So if you want a setting called "ThisIsThePathTheIdiotUserWantsMeToUse", you can, and access it via
string s = Properties.Settings.Default.ThisIsThePathTheIdiotUserWantsMeToUse;
However, I wouldn't recommend it as the settings file is in XML and is thus human readable...
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Ok Great! Thanks for all your help
|
|
|
|
|
i have an assembly delayed signed using "key.snk". i extracted the public key from this and it is stored in "pubkey.snk".this assembly is running well in local pc , but when deploy in other pc with pubkey.snk , get the exception , and doesn't run, when it is not signed it works well on other pcs.can anyone help me with this...
|
|
|
|
|
while (WebBrowser.IsBusy == true)
{
Application.DoEvents();
}
Im using the code above in a documentcompleted method (a html form has to be submitted) to wait until the WebBrowser is finished loading the document which works but its sucking up all the processor's cycles. Is there any to limit checking to once a second without splitting the method up or using events ?
|
|
|
|
|
BuggingMe wrote: I...without splitting the method up or using events ?
Basically no and why would would you not want to use proper techniques? You should have a background thread or use an AutoResetEvent or ManualResetEvent
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Well no navigation is taking place so i cant use the navigated event, After the submit button is clicked there is a delay of an unknown length and text is injected into the HTML page via PHP. Here is the code im using to detect this, It works but is very CPU intensive
<pre>while (WebBrowser.IsBusy == true)
{
Application.DoEvents();
}
string InitalPage = WebBrowser.DocumentText;
while (WebBrowser.DocumentText == InitalPage)
{
Application.DoEvents();
}
while (WebBrowser.IsBusy == true)
{
Application.DoEvents();
}</pre>
I haven't learned threading yet (something i definitly want to avoid if at all possible for this project), There's no documenttextchanged event to use so im not sure what to do now
IS there any non CPU intensive/Non threading alternitive to the above code?
|
|
|
|
|
BuggingMe wrote: I haven't learned threading yet
Time to start
BuggingMe wrote: something i definitly want to avoid if at all possible for this project
And why would that be? Use the proper tools for the job.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
BuggingMe wrote: avoid if at all possible
Perhaps you're unaware that your code is using one? You need to understand what you are doing to the application's main thread at least.
|
|
|
|
|
While the proper way would be to use events or a background thread, you can hack it up with crappy code and do this.
while (WebBrowser.IsBusy)
{
Application.DoEvents();
System.Threading.Thread.Sleep(500);
}
|
|
|
|
|
This is the perfect time to start learning Threading....
|
|
|
|
|
Ok so I posted this a while ago and I need to reiterate the question:
In panelMasterlist I have a delete event:
public void contextDeleteMasterList_Click(object sender, EventArgs e)
{
frmGenericProgress F = sender as frmGenericProgress;
List<MasterListItem> deletedObjects = new List<MasterListItem>(); .............}
It populates a list then validates it... etc.
In frmMain
I have a button event from a 3rd component that when triggered need to do the exact same thing done in contextDeleteMasterList_Click.
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{
So I made the contextDeleteMasterList_Click public, and in the buttonDeleteMasterlist_Activate tried calling
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{
panelMasterlist.contextDeleteMasterList_Click();
}
got Error 1 No overload for method 'contextDeleteMasterList_Click' takes '0' arguments
tried:
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{
panelMasterlist.contextDeleteMasterList_Click(sender, e);
}
got Error 1 An object reference is required for the nonstatic field, method, or property 'Freepour.Studio.Forms.Panels.panelMasterlist.contextDeleteMasterList_Click(object, System.EventArgs)
Any help is greatly appreciated
|
|
|
|
|
try:
panelMasterlist.contextDeleteMasterList_Click(null, null);
[Added]
My bad. Wasn't reading carefully.
You need to either create a new instance of PanelMasterList and then call the method
such as
....MasterPanelList mpl = new MasterPanleList();
mpl.contextDeleteMasterList_Click(null, null);
or create and use a delegate to call that method.
Or make the method/event handler static. But this really is a bad practice.
[/Added]
|
|
|
|
|
Thank you first method worked!
|
|
|
|