Fog Creek Software
Discussion Board




Entity Classes again (sort of)

Hi all

This is my 2nd post.  I read Joel's post re entity classes, and was pleased to see that Joel had used the same word that I had used to name the tables in my database (ENTITY_ADDRESS, ENTITY_PHONE, ENTITY_EMAIL etc)

Anyway, I've been working on an application framework that helps me create new applications quickly (VB6 Enterprise SP4) and that accepts plug-in "applets" that get shown within an MDI form.

Here's some example code - basically, it creates one object that gets all the details of a Debtor from the database, and then gets all the details of a data entry form from the database, and then creates a new object that takes all of that data and combines the two to create a data entry / display form at runtime.

The ObjectXML method returns an XML stream containing all the needed information.

    Dim oDataValues As OptimusObject
    Dim oFormValues As OptimusObject
    Dim oForm As cFormHandler
   
    Set oDataValues = New OptimusObject
    Set oDataValues.DBConnection = cn
    oDataValues.IdentityCode = "ASTEC"
    oDataValues.ObjectTypeCode = "DBTROBJ"
    oDataValues.GetChildren = False      'we just want the main details
    oDataValues.Fill
    If oDataValues.Status = OO_Success Then
        'Open "e:\temp\dataobject.xml" For Output As 1
        '    Print #1, oDataValues.ObjectXML
        'Close 1
        Set oFormValues = New OptimusObject
        oFormValues.IdentityCode = "PTH_DM_FORM"
        oFormValues.ObjectTypeCode = "BW_APP"
        oFormValues.GetChildren = True      'we want all the controls of this form
        Set oFormValues.DBConnection = cn
        oFormValues.Fill
        If oFormValues.Status = OO_Success Then
            'Open "e:\temp\formobject.xml" For Output As 1
            '    Print #1, oFormValues.ObjectXML
            'Close 1
            Set oForm = New cFormHandler
            oForm.ControlValues = oFormValues.ObjectXML
            oForm.DataValues = oDataValues.ObjectXML
            If oForm.Build = FH_Success Then
                oForm.Display
            End If
            Set oForm = Nothing
        End If
        Set oFormValues = Nothing
    End If
    Set oDataValues = Nothing

This works completely fine. In the VB6 IDE, Debug.Print GetTickCount() shows an elapsed time of 3806 (3.8 seconds) on a Cyrix 300mhz with 256mb Ram getting the data from a separate machine on the local area network (a Celeron 633 or something with 64mb Ram)

I know that's slow to generate a form for a user to start working with, but perhaps a different internal design could speed it up. I use MSXML to do XPath queries on the XML finding the relevant XML nodes needed to generate the textbox (for example) and set its properties. All at runtime.

Essentially, the ControlValues property of the oForm object holds all the XML that describes how the data should be displayed on the screen, and the oForm object then renders it to a Windows form.

What's nice about this is that I can say:

            Set oForm = New cWebPage
            oForm.ControlValues = oFormValues.ObjectXML
            oForm.DataValues = oDataValues.ObjectXML
            If oForm.Build = WP_Success Then
                Response.Write oForm.Webpage
            End If
            Set oForm = Nothing

Here, the same ControlValues XML data is passed to the cWebPage class, and it takes care of rendering the textboxes etc to an HTML stream.

I haven't yet gotten to the stage of coding what happens when the user clicks the Save button (on either the screen form or the webpage) but this is a good start I feel.

Does anyone have any comments? I'm a single developer, and hoping to open this framework up so that you can do the same as I've done as above. The framework accepts plug-in applets (that are really ActiveX DLL's) that can be constructed just like in the example code. As developers, would that make it easier for you to develop applets that could be plugged in?

I realise you don't have a complete understanding of how the whole thing works, but I'd be interested in getting any feedback. This is just to tweak the thinking process.

Thanks everyone - looking forward to reading any replies.

Bradzo
Friday, January 31, 2003

*  Recent Topics

*  Fog Creek Home