See also

[link:lorgonblog.spaces.live.com]

for a terse description of how the 'implicit' or 'primary' constructor works.

By on 2/17/2009 9:58 AM ()

Thanks! I had figured out that I could access base members via base.x, and that gave me everything I needed except being able to add an event handler to the object during initialization. It was an inherited windows form, and I wanted the form to handle the Activated event, and it wouldn't let me do this through base. Naming the object with "as x" did the trick!

By on 2/17/2009 10:12 AM ()

Hi,
the following sytnax should do the trick:

1
2
3
4
5
 
type MyForm() as x = 
    inherit Form()
    do x.Initialize()
    member this.Initialize() = ()

However, you may also consider making the initialization just a private (local function) in which case you can write:

1
2
3
4
5
6
 
type MyForm() = 
    inherit Form() 
    let initialize() = 
        // configure form using 'base'
    do initialize()

Now you can do most of the initialization using 'base' variable that accesses the inherited form. You may still need the reference to self ('as x') in the intialization if you need to access any member of your class (but this can be tricky during initialization).

By on 2/17/2009 8:10 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper