Problems linking statically Delphi2010 with db2api

Giganews Newsgroups
Subject:Problems linking statically Delphi2010 with db2api
Posted by: Adolfo López Escribano
Date:Fri, 29 Jan 2010

Hello,
I've found problems in my first migrated project from D6 to D2010.
This application use db2api (9.7 version). In D6 runs correctly but not in  D2010.
I've ported C includes files into db2ApiDf.pas, and this simple code always returns sqlca.sqlcode <> 0

D2010 builds correctly without any link error.
any suggestion about link with external DLL?

Thanks in advance and best regards,

procedure TDBSettingsForm.FormCreate(Sender: TObject);
var
  currentLocalInstanceName : Array[0..SQL_INSTNAME_SZ] of Char;
  sqlca_ : SQLCA;
  dbDirOpen : db2DbDirOpenScanStruct;
  dbDirClose : db2DbDirCloseScanStruct;
  entry : db2DbDirNextEntryStructV9;
  i : Word;
  o : Tdb2DbDirInfoV9;
begin
  self.LastIndex := -1;
  sqlegins( currentLocalInstanceName, sqlca_ );
  if sqlca_.sqlcode <> 0 then
>>>>>    Exit;

  dbDirOpen.pipath := nil;
  db2DbDirOpenScan(SQL_REL9700, dbDirOpen, sqlca_ );
  if sqlca_.sqlcode = 0 then begin
    entry.dirEntry := nil;
    entry.iHandle := dbDirOpen.oHandle;
    for i:= 0 to dbDirOpen.onumEntries-1 do begin
      db2DbDirGetNextEntry(SQL_REL9700, entry, sqlca_ );
      if sqlca_.sqlcode = 0 then begin
        o := Tdb2DbDirInfoV9.Create(entry.dirEntry^);
        self.db2EntriesComboBox.AddItem(o.Alias, o );
      end;
    end;
    dbDirClose.iHandle := dbDirOpen.oHandle;
    db2DbDirCloseScan(SQL_REL9700, dbDirClose, sqlca_ );
  end;
end;

A portion of db2ApiDf.pas are:

unit db2ApiDf;

{$WEAKPACKAGEUNIT ON}

interface
  uses Windows;

type
  {$EXTERNALSYM SQLCA}
  SQLCA = record
    sqlcaid: Array[0..8-1] of Char;    // Eyecatcher = 'SQLCA '
    sqlcabc: Integer;                  // SQLCA size in bytes = 136
    sqlcode: Integer;                  // SQL return code
    sqlerrml: SmallInt;                // Length for SQLERRMC
    sqlerrmc: Array[0..70-1] of Char;  // Error message tokens
    sqlerrp: Array[0..8-1] of Char;    // Diagnostic information
    sqlerrd: Array[0..6-1] of Integer;  // Diagnostic information
    sqlwarn: Array[0..11-1] of Char;    // Warning flags
    sqlstate: Array[0..5-1] of Char;    // State corresponding to SQLCODE
  end;

{$EXTERNALSYM sqlegins}
function sqlegins(pInstance: PChar; var pSqlca: SQLCA): Integer; stdcall;

....

const
  db2app = 'db2app.dll';

implementation
  uses Sysutils;

function sqlegins; external db2app name 'sqlegins_api';

Replies