Inserting a record via CFront

Hi all! I have problem with subj. :frowning: After DBL_Init making following code (from example): #define DATABASENAME “c:\…\ernan.fdb” #define CACHESIZE 1000 #define USECOMMITCACHE 0 DBL_OpenDatabase((DBL_U8*) DATABASENAME, CACHESIZE, USECOMMITCACHE); DBL_U8 CompanyNamePtr[10] = “comp”; // CompanyNamePtr = DBL_NextCompany(CompanyNamePtr); if(NULL != CompanyNamePtr) { DBL_OpenCompany(CompanyNamePtr); } DBL_HTABLE hTable; DBL_S32 TableNo = 50000; DBL_OpenTable(&hTable, TableNo); // insert into navision DBL_HREC hRec = DBL_AllocRec(hTable); DBL_BWT(); DBL_InitRec(hTable,hRec); char s[20] = “hello!”; DBL_AssignField(hTable,hRec,1,DBL_FieldType(hTable,1),s,sizeof(s)); DBL_Allow(DBL_Err_RecordExists); if (!DBL_InsertRec(hTable,hRec)) { DBL_AWT(); DBL_FreeRec(hRec); } DBL_EWT(); DBL_FreeRec(hRec); // close all DBL_CloseTable(hTable); and on DBL_InsertRec NF error me, that I must select company before using the table… What I can do? TNX

It isn’t nice:


DBL_Allow(DBL_Err_RecordExists);
if (!DBL_InsertRec(hTable,hRec)) {
DBL_AWT();
DBL_FreeRec(hRec);
}
DBL_EWT();

DBL_FreeRec(hRec);

it can couse errors. DBL_EWT() is called in any case and DBL_FreeRec can be called twice. So, use:


DBL_Allow(DBL_Err_RecordExists);
if (!DBL_InsertRec(hTable,hRec)) {
DBL_AWT();
DBL_FreeRec(hRec);
} 
  else 
{
  DBL_EWT();
  DBL_FreeRec(hRec);
}

Try add to database users and after DBL_OpenDatabase insert DBL_Login. And check do you receive this error. Edited by - db on 2001 Jul 30 16:40:27

Dalius thank you! It’s great!