Subject PACKAGE sample
Author Enrico Cima
Dear Everybody,
I'm trying to create a component package in CBUILDER5 using a database connection done from the MAIN program. So I've seen the sample of IBC_SEACHGRID that do the same, but using DATASET from MAIN program.

Attached there is the code I've written for doing such a thing, but, unfortunately, sometimes works, sometimes not. In any case, when i put in the package the IB_NAVIGATION_BAR i obtain an error.

There is somebody who can give me some datails on how operate?
Many thanks to all.


----------


#include <vcl.h>
#pragma hdrstop

#include "U_Ins.h"
#include "DAT_GEN.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//

static inline void ValidCtrCheck(DAT_GEN *)
{
new DAT_GEN(NULL);
}
//---------------------------------------------------------------------------
__fastcall DAT_GEN::DAT_GEN(TComponent* Owner)
: TWinControl(Owner)
{
FDataConn = new TList();
// FDataTrans = new TList();
SetConnection(0);
// SetTransaction(0);

}


//---------------------------------------------------------------------------
TIB_Connection *__fastcall DAT_GEN::GetConnection( void )
{
if (FDataConn->Count<=0) return(0);
else return(((TIB_ConnectionSource *) FDataConn->Items[0])->IB_Connection);
}
//---------------------------------------------------------------------------
void __fastcall DAT_GEN::SetConnection( TIB_Connection *DB )
{
if (FDataConn->Count<=0) AddDataBase(DB);
else
{
if( ((TIB_ConnectionSource *) FDataConn->Items[0])->IB_Connection != DB)
((TIB_ConnectionSource *) FDataConn->Items[0])->IB_Connection=DB;
RemoveDataBase(DB);
}

}
//---------------------------------------------------------------------------
TIB_ConnectionSource * __fastcall DAT_GEN::AddDataBase( TIB_Connection *DB )
{
int i;
TIB_ConnectionSource *DS=0;
bool AlreadyGotIt = false;
for (i=0; i< FDataConn->Count; i++)
{
DS= (TIB_ConnectionSource*) FDataConn->Items[i];
if (DS->IB_Connection==DB)
{
AlreadyGotIt=true;
break;
}
}
if (!AlreadyGotIt)
{
DS=new TIB_ConnectionSource(this);
DS->IB_Connection=DB;
FDataConn->Add(DS);
TIB_DataLink
}
return(DS);
}
//---------------------------------------------------------------------------
void __fastcall DAT_GEN::RemoveDataBase( TIB_Connection *DB )
{
int i;
TIB_ConnectionSource *DS;
for (i=1; i<FDataConn->Count; i++)
{
DS =(TIB_ConnectionSource *) FDataConn->Items[i];
if (DS->IB_Connection == DB)
{
DS->IB_Connection =0;
FDataConn->Remove(DS);
delete DS;
break;
}
}
}

//---------------------------------------------------------------------------
TIB_Transaction *__fastcall DAT_GEN::GetTransaction( void )
{
if (FDataTrans->Count<=0) return(0);
else return(((TIB_TransactionSource *) FDataTrans->Items[0])->IB_Transaction);
}
//---------------------------------------------------------------------------
void __fastcall DAT_GEN::SetTransaction( TIB_Transaction *DB )
{
if (FDataTrans->Count<=0) AddTran(DB);
else
{
if( ((TIB_TransactionSource *) FDataTrans->Items[0])->IB_Transaction != DB)
((TIB_TransactionSource *) FDataTrans->Items[0])->IB_Transaction=DB;
RemoveTran(DB);
}

}
//---------------------------------------------------------------------------
TIB_TransactionSource * __fastcall DAT_GEN::AddTran( TIB_Transaction *DB )
{
int i;
TIB_TransactionSource *DS=0;
bool AlreadyGotIt = false;
for (i=0; i< FDataTrans->Count; i++)
{
DS= (TIB_TransactionSource*) FDataTrans->Items[i];
if (DS->IB_Transaction==DB)
{
AlreadyGotIt=true;
break;
}
}
if (!AlreadyGotIt)
{
DS=new TIB_TransactionSource(this);
DS->IB_Transaction=DB;
FDataTrans->Add(DS);
}
return(DS);
}
//---------------------------------------------------------------------------
void __fastcall DAT_GEN::RemoveTran( TIB_Transaction *DB )
{
int i;
TIB_TransactionSource *DS;
for (i=1; i<FDataTrans->Count; i++)
{
DS =(TIB_TransactionSource *) FDataTrans->Items[i];
if (DS->IB_Transaction == DB)
{
DS->IB_Transaction =0;
FDataTrans->Remove(DS);
delete DS;
break;
}
}
}

//---------------------------------------------------------------------------

void __fastcall DAT_GEN::START(TComponent* Owner)
{
TTF_Ins *fin=new TTF_Ins(Owner);
// fin->IB_Query1->IB_Connection=DataBase;
// fin->IB_Query1->IB_Transaction=Transaction;
fin->ShowModal();
delete fin;
}
//---------------------------------------------------------------------------
namespace Dat_gen
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(DAT_GEN)};
RegisterComponents("ENTERPRISE", classes, 0);
}
}
//---------------------------------------------------------------------------



[Non-text portions of this message have been removed]