overriding a component property

Posted by jmls on 10-Sep-2008 11:59

I'm experimenting with inherited controls . I wanted to see if I could stop a property from being set (for example, to force a button to be a certain width for corporate standards).

Is there any way of overriding the property, so that I can check the proposed value of the property rather than the OEA just accepting it ?

All Replies

Posted by jmls on 10-Sep-2008 12:23

a workaround (at least for some properties) is to hook into the appropriate event:

METHOD PRIVATE VOID button1_Resize( INPUT sender AS System.Object, INPUT e AS System.EventArgs ):

CAST(sender,button):Size = NEW System.Drawing.Size(75, 23).

END METHOD.

subscribe the resize event to this method, and you cannot resize the button in the visual designer

That's pretty cool.

However, still looking for a way of overriding a property that does not have an appropriate "changing" event defined

Posted by Admin on 10-Sep-2008 12:29

I don't think that a property setter can get overriden.

Posted by jmls on 10-Sep-2008 12:30

that's a bummer. Any reason why not ?

Posted by Admin on 10-Sep-2008 12:40

Properties are about exposing the knowledge of a class. Methods about what it does.

The internals of a base class may really depend on this knowledge. All what they are and do counts on these property values.

Methods can get overridden. So a property setter provides a much higher encapsulation than a method.

When you'd override the Size setter for a Control, it's really important not to forget to tell the base class about this (SUPER:Size = ...). If you could do that the base class and your derived class would have different knowledge leading into chaos. The ...Changed events or your Resize events allow you to react. But the base class still has received the value first - ensuring everybody talks about the same Size.

Posted by jmls on 10-Sep-2008 12:51

When you'd override the Size setter for a Control,

so, can you override a size setter ?

it's really important not to forget to tell the base

class about this (SUPER:Size = ...). If you could do

that the base class and your derived class would have

different knowledge leading into chaos. The

...Changed events or your Resize events allow you to

react. But the base class still has received the

value first - ensuring everybody talks about the same

Size.

So the demo code above is the right way to do this ?

Posted by Admin on 10-Sep-2008 12:55

When you'd override the Size setter for a Control,

so, can you override a size setter ?

No that I'm aware of. I should have written "if in theory you could override a setter".

So the demo code above is the right way to do this ?

If it works for you... I'd test it together in combination with Dock and Anchor properties as they modify the size as well and see how it behaves.

Posted by jmls on 10-Sep-2008 13:15

If it works for you... I'd test it together in

combination with Dock and Anchor properties as they

modify the size as well and see how it behaves.

Check! Dock and Anchor behave as I hoped (button does not change in size). Remove the method, button behaves as normal with either a resize, dock or anchor

Posted by dlauzon on 28-Jul-2010 10:10

If anyone is interested, I created enhancement request 0000004079 to ask for this feature.

This thread is closed