Custom Control Width

  1. last week

    Dave S

    Jan 12 San Diego, California USA

    I created a custom control in a "ContainerControl"
    the base control is set to 100px wide (so when it is dragged to the Window that is the size it shows initially)

    Then at design time I adjust the width to be 450px...

    However when I run the app, in the Open Event of the control placed on the window, it still says it is 100px wide

    here is what is REALLY strange

    W=self.width // reports 100 px [me.width gives same answer]

    but if I put a breakpoint there and examine the control.... is says it is 450px wide

    OH! sh*t!

    I figured it out... stupid me...
    The container control also had a METHOD called WIDTH... which returns the width of the default control

    I only noticed, when I let Autocomplete show me the properties. width was lowercase, where the real width is "Width"

    So I can rename the method to solve the issue... but why didn't the compiler complain?

  2. Jeff T

    Jan 12 Midlands of England, Europe

    is the control the first member of a control set, and it is a newly created clone that was resized?
    self.width should be the container

  3. Dave S

    Jan 12 San Diego, California USA

    it is the container that I need the width of....
    It contains one template control

    as a test I set the template control to be 98px wide.... and THAT is what Self if returning. even though the IDE tells me that Self is actually the container

  4. Bob K

    Jan 12 Pre-Release Testers, Xojo Pro Kansas City

    Where exactly are you putting w = self.width?

  5. Dave S

    Jan 12 San Diego, California USA

    CONTAINER1 starts out with a CONTROL1(0)

    that code is in a Method of the CONTAINER.... when I put the mouse over SELF, it says Self=Container, yet it is returning the Width of CONTROL1(0) not CONTAINER1

    The method is used to add new members to to CONTROL1 controlset ... and W is to set the width of each control

    It all works perfectly , except it is using the wrong width value to calculate from

  6. Dave S

    Jan 12 Answer San Diego, California USA

    OH! sh*t!

    I figured it out... stupid me...
    The container control also had a METHOD called WIDTH... which returns the width of the default control

    I only noticed, when I let Autocomplete show me the properties. width was lowercase, where the real width is "Width"

    So I can rename the method to solve the issue... but why didn't the compiler complain?

  7. Jean-Yves P

    Jan 12 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    I recently called an enumeration the same as a property.
    compiler didn't complain, but it didnt work !

  8. Jason P

    Jan 13 Xojo Inc Texas

    @Dave S OH! sh*t!

    I figured it out... stupid me...
    The container control also had a METHOD called WIDTH... which returns the width of the default control

    I only noticed, when I let Autocomplete show me the properties. width was lowercase, where the real width is "Width"

    So I can rename the method to solve the issue... but why didn't the compiler complain?

    Because it's not an error to do so - sometimes you want to be able to shadow a property by doing exactly this. However, analyze project would probably have given you a warning about this.

or Sign Up to reply!