|
Hello Community,
I'm trying to write a dll that contains a abstract UserControl (Name: StepBase). I wrote two UserControls that inherits the abstract one and now when I open one of the inherited I got the following message:
The designer must create an instance of type 'StepBase' but it cannot
because the type is declared as abstract.
On the internet I found a website with a solution but it do't work. On the website the author wrotes that I have to add a custom TypeDescriptor like this:
<TypeDescriptionProvider(GetType(ConcreteClassProvider))> _<br />
Public MustInherit Class StepBase
Additional I have to add a ConctreteUserControl-Class:
Public Class ConcreteStepBase<br />
Inherits StepBase<br />
End Class
Here is the custom TypeDescriptor:
Public Class ConcreteClassProvider<br />
Inherits TypeDescriptionProvider<br />
<br />
Public Sub New()<br />
MyBase.New(TypeDescriptor.GetProvider(GetType(StepBase)))<br />
End Sub<br />
<br />
Public Overrides Function GetReflectionType(ByVal objectType As Type,<br />
ByVal instance As Object) As Type<br />
If objectType Is GetType(StepBase) Then<br />
Return GetType(ConcreteStepBase)<br />
End If<br />
Return MyBase.GetReflectionType(objectType, instance)<br />
End Function<br />
<br />
Public Overrides Function CreateInstance(ByVal provider As<br />
IServiceProvider, ByVal objectType As Type, ByVal argTypes() As Type, ByVal<br />
args() As Object) As Object<br />
If objectType Is GetType(StepBase) Then<br />
objectType = GetType(ConcreteStepBase)<br />
End If<br />
Return MyBase.CreateInstance(provider, objectType, argTypes, args)<br />
End Function<br />
End Class
I get this solution from the following website:
http://www.urbanpotato.net/default.aspx/document/2001
The provided solution does not work; I added a throw new Exception to the constructor of my custom TypeDescriptor and this Exception is not thrown, so that I think, the TypeDescriptor will not be used.
What is my fault?
Manfred
modified on Tuesday, April 1, 2008 5:08 PM
|
|
|
|
|
You did notice that you have to use Visual Studio 2005 and .NET 2.0, correct?? Also, the solution provided was developed under the beta versions of these two products, so any results you get may or may not apply to the final release versions.
Visual Studio, to this day, still does not provide support for designing abstract forms and controls. And, if you read the very bottom of the article:
Summary
While it is a bit of a drag that the Windows Forms designer doesn’t support abstract classes, by using this simple technique you can trick it into doing so. This requires at least Beta 1 of Visual Studio Whidbey. As I found when trying to use the inheritance picking dialog, there may still be pitfalls here, so before going hog wild with your own projects you should make sure this technique works for you in all the scenarios you care about. Microsoft doesn’t officially support designing abstract base classes, so as I said above, you will be on your own if something doesn't work for you.
|
|
|
|
|
Hi all,
Is there a way to force TextFieldParser to also read special characters like those used in French (ex é ç è à) . Now is all I get for those is ascii 63. I guess that it has something to do with encoding or localisation...
Thx !
Vinny
|
|
|
|
|
I suggest you have a look at TextFieldParser(Stream, Encoding) Constructor then.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Indeed !!!
Sorry for my stupid question, I'm a bit new to all this ... !
Vincent.
Vinny
|
|
|
|
|
No Problem.
Try to make friends with documentation and Google...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I am trying to save values to a text file using the VB editor embedded in to the Microsoft Office suite, more specifically using excel. I am fluent in C#, however I am new to VB and I can't seem to get the anything declared or working.
I've searched through MSDN and google, and everything i try doesn't work.
That said; Does anyone know how to create a new txt file, and write into it? (I think most of my problem is that I don't know where to declare the streamwriter).
Thanks in advance
Adam
--Its not broken if it never worked.
|
|
|
|
|
I'm not sure what version of Visual Basic Microsoft Office comes with, but in .Net you declare the streamwriter inside of your method (Sub , Function , etc).
<br />
Dim sW As IO.StreamWriter = New IO.StreamWriter(pathtToFile)<br />
sW.Write(Data)<br />
sW.Close()<br />
sW.Dispose()<br />
I hope this helps.
|
|
|
|
|
I'll try it again, but last time I tried that it threw an error at the '=' and said it expected an end of statement.As for what version I am using I am not 100% sure, its the built in editor to Microsoft Office 2003.
I'll try this in the morning and pop back on here if i still can't get it working.
Thanks a bunch for the response!
--Its not broken if it never worked.
|
|
|
|
|
You're welcome. If that doesn't work, you could also try,
Dim sW As New IO.StreamWriter(pathToFile)
or
<br />
Dim sW As IO.StreamWriter <br />
sW = New IO.StreamWriter(pathToFile)<br />
I hope this helps; I haven't used the programming tools included with Office for a couple of years.
modified on Tuesday, April 1, 2008 8:47 PM
|
|
|
|
|
Hey,
I tried what you posted there and got the following error.
--Compile error:
--Expected end of statement
It happened at the first bracket of this line.
sW = New IO.StreamWriter(pathToFile)
If this were C# I would assume I hadn't included the right system file, but i can't seem to declare a system file, ie:
using System.IO
Do you know if that is the case with VB, and if so do you know the syntax for including it?
--Its not broken if it never worked.
|
|
|
|
|
Adam.m.Nelson wrote: I'll try it again, but last time I tried that it threw an error at the '=' and said it expected an end of statement.As for what version I am using I am not 100% sure, its the built in editor to Microsoft Office 2003.
AFAIK, Office 2003 uses VBA for the scripting - it probably doesn't recognise StreamWriter.
|
|
|
|
|
Oh, I didn't know that, thanks!.
Do you know of any way to write to a file while 'scripting'?
--Its not broken if it never worked.
|
|
|
|
|
You will need to use the "Basic" methods for file handling.
For example:
FileHandle = FreeFile()
Open [FilePath] for Output as FileHandle
Print #FileHandle,"This is a test string"
Close FileHandle
HTH
[Edit]Had to change since < was intepreted differently[/Edit]
|
|
|
|
|
That did it! thank you very much
--Its not broken if it never worked.
|
|
|
|
|
Adam.m.Nelson wrote: That did it! thank you very much
You are welcome.
|
|
|
|
|
Do you know if it is possible to bring up the 'Save As' window to allow the user to select the save location and file name? I got it working allowing the user to enter the location and file name in a seperate cell, but it would be handy to bring up the dialog they are use to seeing any other time they save a windows file.
--Its not broken if it never worked.
|
|
|
|
|
This dialog is implemented in the CommonDialog Windows control. You can add reference to the ComDlg32.OCX object in your script and use the methods in this object to Open / Save files. This will bring up the familiar Windows file dialog.
HTH
|
|
|
|
|
Beautiful, I will try that tonight. If its not too much to ask, I have another quick question:
This way of doing it leaves an extra cariage return at the end of the file, i tried writing a \b to the file once it is all done, but it literally writes a \b in the file.
Print #FileHandle, "\b"
Print #FileHandle, '\b' isn't a command as the ' starts a comment.
Is there a way to kill that last cariage return?
--Its not broken if it never worked.
|
|
|
|
|
The Print statements appends a CR+LF to the text... I don't know of a way you could suppress this.
|
|
|
|
|
hmm, ok, thanks anyways!!
I'll play around with it and if I figure something out I will post it here.
--Its not broken if it never worked.
|
|
|
|
|
Put a semi-colon on the end of the Print statement.
Print #FileHandle, "something...";
This will avoid adding a CRLF to the end of the line it just printed to the file.
|
|
|
|
|
Hey hey that did it!, however because i am writing to the file inside of a loop there are no line breaks now. Is there a command I can put at the beginning of the string being written to the file to tell it to create a new line?
--Its not broken if it never worked.
|
|
|
|
|
Actually, never mind, i re-worked the loop to work around it.
Thanks a bunch everyone!!
--Its not broken if it never worked.
|
|
|
|
|
Hello Friend!
I've built a windows application.
now I want to show any gif image while system is busy to save data in data base. after completing save operation the image will be invisible. again it will be visible during saving data.
How can I do this?
Please, help me.
Thanks!!!!!!!!!!
|
|
|
|