[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing proxy properties



On 25/9/24 5:32 am, Fabien Bodard wrote:


Le dim. 22 sept. 2024 à 12:55, Bruce Steers <bsteers4@xxxxxxxxx <mailto:bsteers4@xxxxxxxxx>> a écrit :



    On Sun, 22 Sept 2024 at 11:43, Bruce Steers <bsteers4@xxxxxxxxx
    <mailto:bsteers4@xxxxxxxxx>> wrote:



        On Sun, 22 Sept 2024 at 09:28, BB <adamnt42@xxxxxxxxx
        <mailto:adamnt42@xxxxxxxxx>> wrote:


            On 22/9/24 4:20 pm, BB wrote:

            Maybe I'm being overly ambitious here.

            If $control.Proxy.Row < 0 Then Return

            $control is a custom control with a gridview in it, which
            is the proxy.

            That line above stops the IDE with the error "Unknown
            symbol 'row' in class 'Control' "

            but in the IDE I can see (i.e. debug) the $control Proxy
            property and see the actual Proxy as per the picture
            attached.

            Is the $control.Proxy.Row construct wrong?

            tia

            b


            AH nevermind.

            I can see now what I was trying cant work, because Proxy
            is a Control, not the actual object's class. The IDE must
            do some magic to see it as it is.

            Damn! I thought I'd found a neat way to get at the proxy's
            properties.

            I know the Proxy's job is only to duplicate mouse and
            keyboard events but I just thought, maybe....

            Oh well, back to work.

        It's not magic, it's just a trick ;)

        Just access it assigning the gridview class or use
        Object.class to use any property.
        Ie.

        Dim hGrid As GridView = $control.Proxy
        Print hGrid.Row

        Or..

        Dim hObject As Object = $control.Proxy
        Print hObject.Row

        If the type could vary you could use
        Object.Type($control.Proxy) to see exactly what it is.

        Respects
        BruceS



    I must say although technically incorrect there are many
    properties in gambas that are Control.class but Object.class would
    be much more useful.

    Window.Controls , Control.Proxy , etc

    if it was Window.Controls As Object[]  and Control.Proxy As Object
    then it would make for some much simpler programming.

    But then again i guess it don't take much of a command to get over
    this.

    Public Sub ControlObject(Ctrl As Control) As Object
      Return Ctrl
    End

    Print ControlObject($control.Proxy).Row


Or just
Dim o as Object = Control.Proxy
Print o.Row


--
Fabien Bodard

or the simple answer that I could not see for the trees was just define the property in the custom control (I think that was what BruceS was alluding to.)

To expand on this, I have a lot of custom controls based on UserContainer with a label and a basic control e.g. a "labelled TextBox". The contained textbox is the proxy, which is a handy way to make all the Events visible at the client form level. However, in order to expose the TextBox properties in the custom controlI I have to code the property, add it to the _Properties constant and _code the accessors_.

Now here's the rub. All these accessors just return or set the basic control property. For example:

Private Function Text_Read() As String
	Return $basecontrol.Text
End

Private Sub Text_Write(Value as String)
	$basecontrol.Text=Value
End

Private Function Font_Read() As Font
	Return $basecontrol.Font
End

Private Sub Text_Write(Value as Font
	$basecontrol.Font=Value
End

etc etc

These are a bit of a pain as I have to code each one and invariably miss one or two.

It would be much nicer, I think, if the proxy would just expose it's properties (that appear in the _Properties List and have a local declaration) thus making these accessors either automagically or just invisible like Properties that Use. With, of course, the ability to override the accessor if I want/need to, just like Properties that Use.

Or maybe? there is some other way to do this. What I'd love to see is the ability to declare these properties like

Property Text as String Use $control.Text

b


References:
Accessing proxy propertiesBB <adamnt42@xxxxxxxxx>
Re: Accessing proxy propertiesBB <adamnt42@xxxxxxxxx>
Re: Accessing proxy propertiesBruce Steers <bsteers4@xxxxxxxxx>
Re: Accessing proxy propertiesBruce Steers <bsteers4@xxxxxxxxx>
Re: Accessing proxy propertiesFabien Bodard <gambas.fr@xxxxxxxxx>