Readonly at runtime

E

elziko

How do I make a property of a class Readonly but only at RUNTIME?

I want to be able to edit the value in a property browser after dragging my
component on a form but then not allow any code to change this property when
the code is running.

TIA
 
H

Herfried K. Wagner [MVP]

elziko said:
How do I make a property of a class Readonly but only at RUNTIME?

Untested:

\\\
Public Property...
...
Set(ByVal Value As Foo)
If Me.DesignMode Then
m_Foo = Value
End If
End Set
End Property
///
 
B

Bob Powell [MVP]

B

Bob Powell [MVP]

J

Jay B. Harlow [MVP - Outlook]

Elziko,
I would modify Herfried's slightly:

Public Property...
...
Set(ByVal Value As Foo)
If Me.DesignMode Then
m_Foo = Value
Else
Throw New NotSupportedException
End If
End Set
End Property

Which will give a glaring runtime error if you attempt to set the property.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top