Porting VSDK 1.x to 3.x (II)

Ruslan Zasukhin sunshine at public.kherson.ua
Wed Aug 29 15:12:06 CDT 2007


On 29/8/07 11:37 AM, "David (work)" <david at inedit.com> wrote:

Hi David,

> Hi again,
> 
> Our Valentina databases contains 'VDK_DescriptionFile' to save passwords. 
> There is no way to read and write this information using Valentina C++ ADK
> Standard Edition?. 
> The 'ConvertDB_1_2' function copy this descriptions into the new database?.
>  
> I need also access to PROTECTED HEADERS?.

In the next letter

------------------------------------
> I use the 'mXtraData' member in VSDK 1.x for custom data.
> What's the new way to add custom data pointer into a database object
> in VSDK 3.x?.

>  I need to add a callback function when I close the database.

Check please 

    VSHARED/FBL/publ/Interfaces/FBL_I_ForeignPlugin.h

All objects as I_Database, I_Table, I_Field, I_Cursor,
    do also implement this interface.

You can switch to it using dynamic_cast<>()
Or even better QueryInterface().
 

---------------------------------------
> How must I use the function 'OnDatabaseDestroy' to call my custom function?.
> There is any sample code?.

You should not call it self.

Internal mechanism will call it if it is not NULL pointer.

This is our sources from V4RB ADK related to usage of FBL_I_ForeignPlugin


/***************************************************************************
*******************/
REALobject MakeREALInstance( VSQL::I_Cursor_Ptr inCursor );
void Cursor_Finalize( I_ForeignPlugin* inPlugin );

                
/***************************************************************************
*******************/
inline REALobject GetREALInstance( VSQL::I_Cursor_Ptr inCursor )
{
    if( inCursor == NULL )
        return NULL;

    I_ForeignPlugin_Ptr pPlugin = fbl_dynamic_cast<I_ForeignPlugin>(
inCursor );

    REALobject object = (REALobject) pPlugin->get_Xtra();

    if( object )
        REALLockObject( object );
    else
        object = MakeREALInstance( inCursor );
    
    return object;
}



/***************************************************************************
*******************/
REALobject MakeREALInstance( I_Cursor_Ptr inCursor )
{
    if( inCursor == NULL )
        return NULL;

    REALobject instance = REALnewInstance("VCursor");

    if( instance )
    {
        ClassData( CursorClass, instance, CursorData, data );
        data->mpCursor = inCursor;

        I_ForeignPlugin_Ptr pPlugin = fbl_dynamic_cast<I_ForeignPlugin>(
inCursor );
            
//        pPlugin->put_BackRef( (void**) &(data->mpCursor) );
        pPlugin->put_Xtra( instance );
        pPlugin->put_Finalize( (I_ForeignPlugin::FINALAIZE_PTR)
Cursor_Finalize );
    }
    
    return instance;
} 


/***************************************************************************
*******************/
void Cursor_Finalize( I_ForeignPlugin* inPlugin )
{
    REALobject instance = (REALobject) inPlugin->get_Xtra();

    if( instance )
    {
        ClassData( CursorClass, instance, CursorData, data );
        data->mpCursor = NULL;
    }
}



#pragma mark -


/***************************************************************************
*******************/
void Cursor_Ctor_Param(
    REALobject     instance,
    REALobject     inDB,
    REALstring     inSQLstr,
    int         inCursorLocation,
    int            inCursorType,
    int            inDirection )
{
    START( "Cursor_Ctor" );
    LOG_PARAM( instance );
    LOG_PARAM( inDB );
    LOG_PARAM( inSQLstr );
    LOG_PARAM( inCursorLocation );
    LOG_PARAM( inCursorType );
    LOG_PARAM( inDirection );

    // only if we will execute SQL here.
    ClassData( CursorClass, instance, CursorData, data );
    ClassData( DatabaseClass, inDB, DatabaseData, DBdata );
    
    if( DBdata->mpSqlDatabase )
    {
        I_Cursor_Ptr pCursor = NULL;
    
        try
        {
            Str_Unicode u_query( inSQLstr );
        
            pCursor = DBdata->mpSqlDatabase->SqlSelect(
                                    u_query.c_str(),
                                    (ECursorLocation) inCursorLocation,
                                    (ELockType) inCursorType,
                                    (ECursorDirection) inDirection,
                                    NULL );
        }MY_END_TRY

        data->mpCursor = pCursor;

        if( pCursor )
        {
            I_ForeignPlugin_Ptr pPlugin = fbl_dynamic_cast<I_ForeignPlugin>(
pCursor );

            pPlugin->put_Xtra( instance );
            pPlugin->put_Finalize( Cursor_Finalize );
        }
    }
        
    RETURN_VOID;
} 


/***************************************************************************
*******************/
void Cursor_Destructor( REALobject instance, void* )
{
    START( "Cursor_Destructor" );
    LOG_PARAM( instance );

    ClassData( CursorClass, instance, CursorData, data );

    // Destructor of REALbasic object VCursor MUST destroy C++ object also.
    if( data->mpCursor )
    {
        I_ForeignPlugin_Ptr pPlugin = fbl_dynamic_cast<I_ForeignPlugin>(
data->mpCursor );
    
        // Now clear pointers.
        pPlugin->put_BackRef( NULL );
        pPlugin->put_Xtra( NULL );

        data->mpCursor = NULL;
    }

    RETURN_VOID;
} 




-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the Valentina mailing list