• General

    Author
    Topic
    #352700

    In the book “Access 2000 Developer’s Handbook Vol 1: Desktop Edition”, pages 221 & 222, it states the following:
    “When you create an object variable, Access creates only a ‘pointer’. That is, the variable it creates refers to a real object; it’s not a real object itself. It contains not the value of the object, but its memory address instead.”

    It then gives a number of examples:
    Dim cnn as ADODB.Connection
    Dim rst as ADODB.Recordset
    Dim frm as Form
    Dim ctl as Control
    etc.

    My question is:
    If the variable is strictly a pointer (space for memory address) and since (I am assuming) the memory address is always the same size, why don’t we just code as follows:
    Dim cnn as Object
    Dim rst as Object
    Dim frm as Object
    Dim ctl as Object
    etc?

    I can understand the need for specific Set statements:
    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset
    Set frm = Forms(“frmCustomers”)
    Set ctl = frm.Controls(“txtCompanyName”)

    I can see the need to assign specific addresses. I can’t see the need to be specific when setting aside the neccessary space for an (any) address.

    I am sure there are some who understand the nuts and bolts of this.
    Just curious.

    Viewing 0 reply threads
    Author
    Replies
    • #513797

      You can. However, if you declare your variable as something specific (e.g. form, control, or whatever) and then type the variable followed by a period, Access is nice enough to show you what properties or methods can follow the period in that context. Also, if you goof and use a property or method that doesn’t apply to whatever you’re working with, you’ll get a compile error rather than a run-time error, and it’s a lot easier to find compile errors!

      Declaring things as “object” means you don’t get those features.

      • #513844

        AHA…Thank You Mr. Martin! .
        I think that’s worthwhile information to have.

        • #513851

          It isn’t only that those features don’t show up in intellisense, they aren’t available, period unless you assign the right type of object to that variable.

    Viewing 0 reply threads
    Reply To: General

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: