473,659 Members | 3,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create a Class at runtime for use with PropertyGrid

I have a legacy application that I need to build a Windows Forms
application to interface with it. The legacy application keeps its
configuration information in INI style files.

I wish to use a PropertyGrid on the form to allow the user to adjust the
configuration of the legacy app. The problem I am facing, however, is that
the legacy app can still be changed and new configuration items can be
added/removed from the configuration files of the legacy app.

I would normally just create a class with all the properties of the INI
file but since the INI file might change, I need to be able to dynamically
change that class without having to rebuild the app each time.

I want to read the INI file and dynamically build a class with a property
for each item. I think I'll have a xml file that contains information
about the parameters in the INI file along with their types (integer,
boolean, etc.). When the INI is updated, then the xml file can be updated
to reflect any changes. The Windows app would not need to change.

I am stuck on creating and instanciating the class at runtime.

Any assistance is appreciated.
--
Chris

dunawayc[AT]sbcglobal_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #1
1 4561
On Thu, 5 Aug 2004 16:11:26 -0500, Chris Dunaway wrote:

I am stuck on creating and instanciating the class at runtime.


In answer to my own question, I offer the following code. The form has a
TextBox, a button, and a PropertyGrid, all with their default names. Run
the program and type the following code in the textbox:

Class Test
Private _MyProp As Integer

Public Property MyProp() As Integer
Get
Return _MyProp
End Get
Set(ByVal Value As Integer)
_MyProp = Value
End Set
End Property
End Class
'*** CODE BEGINS
Private Sub Button1_Click(. ..) Handles Button1.Click

Dim VB As New VBCodeProvider
Dim obj As Object

Dim Compiler As ICodeCompiler = VB.CreateCompil er()
Dim cParams As New CompilerParamet ers

cParams.Generat eExecutable = False
cParams.Generat eInMemory = True
cParams.Include DebugInformatio n = False

Dim cResults As CompilerResults
cResults = Compiler.Compil eAssemblyFromSo urce(cParams, TextBox1.Text)

If cResults.Errors .Count = 0 Then
Dim assyResult As [Assembly] = cResults.Compil edAssembly
Dim aType As Type

aType = assyResult.GetT ype("Test")

obj = assyResult.Crea teInstance(aTyp e.FullName)
PropertyGrid1.S electedObject = obj
PropertyGrid1.R efresh()
End If

VB.Dispose()

End Sub
'*** CODE ENDS
--
Chris

dunawayc[AT]sbcglobal_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
8850
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
2
830
by: Steve Teeples | last post by:
How does one go about creating an enum at runtime from an array of strings? -- Steve
11
2190
by: Özden Irmak | last post by:
Hello, In my VB.Net application I create a new instance of my form like : NewForm = new MyNewForm() But with this line, this new form is automatically shown. I want it to be hidden at the start... Adding a line after this line like :
7
4321
by: MarkoH | last post by:
Wsdl.exe /server creates abstract class derived from WebService. Is there a way to create this class at runtime based on some WSDL file given at runtime ? What would be even better - creating concrete class but with empty method implementation of course since WSDL does not provide any info on implementation. Thanks M.
0
1504
by: Hans Koller | last post by:
Hello group, I design a class to bind it to a property grid for easy modification of some settings. My problem is now that I want to raise an event when a settings has been changed. Thats not a problem with some "normal" properties (see property DisplayGrid). But when I use a subclass and TypeConverter the setter of the property is not called. Set(ByVal value As LineSetting) m_Limit1 = value
2
2134
by: =?Utf-8?B?TWF1cmljZU0=?= | last post by:
Hi all, how can I hide a property in a derived class in a propertygrid. Let's say I have a classX and a derived classY. A property in classX will be visible in the propertygrid but the same property in the derived classY will not be visible in the propertygrid. Does anyone know how to do this ?
2
4852
by: =?Utf-8?B?TWF1cmljZU0=?= | last post by:
Hi there, is it possible to disable a property in the propertygrid at runtime? Normally a property will be enabled but if i.e. the user doesn't have access to change the property this property has to be disabled. Is this possible? Thx in advance.
4
2452
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
Is there any way to create an instance of the control that is used by System.Drawing.Design.ColorEditor (i.e., the control that appears when you click on a color in a PropertyGrid)? I want to allow the user to select a color from within my app (but not from a PropertyGrid). The control that is used by the ColorEditor is perfect but I can't find it anywhere. Thanks for any help! Lance
0
1217
by: ntabb | last post by:
Hello all, I have a class instance that I'm attaching to a propertygrid. I would like to find a way to change the "Browsable" attribute during runtime or programmatically from outside the class definition. I would like the end result to display certain contents of the class based on the "machinetype" variable's value. Any suggestions? public class Equipment {
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.