Implementing the Property Page Class

DTS Programming

DTS Programming

Implementing the Property Page Class

To implement the property page class in the Data Transformation Services (DTS) custom task user interface example, you need to add code to the header file GVPropPage.h. The ATL dialog template puts all the code for the dialog box in the header file. The corresponding code file TaskGVUpdate.cpp contains only include statements.

Add the following to the property page header file GVPropPage.h:

  • An include statement for the component header file and some define statements

  • Code to initialize controls on the property page with values of custom task properties

  • Code to validate and save the values of the task properties

  • A declaration for the task class interface pointer
Adding an Include and Define Statement

The component header file is generated by Microsoft® Visual C++®from the .idl file and contains definitions of all the interfaces of the project. Here, the definition of the task class interface is needed. The define statements are for a buffer length and MessageBox caption.

Immediately after the line:

#include <atlhost.h>

insert these lines:

#include "DTSTskGVUpdate.h"

#define  MAX_PROP_LEN    2048
#define  GVM_CAPTION _T("Global Variable Monitor Task")
Initializating Controls

The Name, Description and GblVarName properties must be retrieved from the task class and set into controls.

Example

At the head of the OnInitDialog function (after the left curly bracket), insert the following code:

        USES_CONVERSION;
        BSTR            bstrProperty;

        m_pCustTask = (ITaskGVUpdate *)lParam;

        // Fetch values for Description, Name and GblVarName properties.
        m_pCustTask->get_Description( &bstrProperty );
        SetDlgItemText(IDC_TASK_DESCR, OLE2T( (LPOLESTR)bstrProperty ) );
        SysFreeString(bstrProperty);

        m_pCustTask->get_Name( &bstrProperty );
        SetDlgItemText(IDC_TASK_NAME, OLE2T( (LPOLESTR)bstrProperty ) );
        SysFreeString(bstrProperty);

        m_pCustTask->get_GblVarName( &bstrProperty );
        SetDlgItemText(IDC_GV_NAME, OLE2T( (LPOLESTR)bstrProperty ) );
        SysFreeString(bstrProperty);
Validating and Updating Properties

The Description and GblVarName properties must be validated (to verify a value was entered) and saved back to the task class.

Example

At the head of the OnOK function, insert the following code:

        USES_CONVERSION;
        TCHAR           atcProperty[ MAX_PROP_LEN ];

        // Get task description and generate error if empty.    
        if( GetDlgItemText( IDC_TASK_DESCR, atcProperty, MAX_PROP_LEN ) )
            m_pCustTask->put_Description( T2BSTR( atcProperty ) );
        else
        {
            MessageBox( _T("Description must not be blank."), 
                        GVM_CAPTION, MB_ICONEXCLAMATION );
            return 0;
        }


        // Get global variable name and generate error if empty.    
        if( GetDlgItemText( IDC_GV_NAME, atcProperty, MAX_PROP_LEN ) )
            m_pCustTask->put_GblVarName( T2BSTR( atcProperty ) );
        else
        {
            MessageBox( _T("Global variable name must be entered."), 
                        GVM_CAPTION, MB_ICONEXCLAMATION );
            return 0;
        }
Adding an Interface Pointer Statement

The declaration for the task class interface pointer must be added.

Immediately ahead of the lines:

};

#endif //__GVPROPPAGE_H_

insert these lines:

private:
    ITaskGVUpdate      * m_pCustTask;