Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Re: problem using netcdf and Borland Delphi


> I am trying to read some cdf data files using Borland Delphi v 5.0 on a
> Windows NT machine.  I downloaded netcdf.dll from the unidata ftp site
>
(ftp://ftp.unidata.ucar.edu/pub/netcdf/contrib/win32/netcdf-3.5-beta5.win32b
> in.ZIP) and put the following definitions in my Delphi code:
>
> function nc_inq_libvers : pchar; external 'netcdf.DLL';
> function nc_strerror (ncerr : integer) : pchar; external 'netcdf.DLL';
> function nc_open (path : pchar; omode : integer; var ncidp : integer) :
> integer; external 'netcdf.DLL';
> function nc_close (ncidp : integer) : integer; external 'netcdf.DLL';
>
> When I call nc_inq_libvers I get what appears (?) to be a reasonable
answer:
>
> 3.5-beta5 of Oct 17 2000 10:28:35 $
>
> but when I call nc_strerror with any integer (I tried a lot of them), I
> always get back

  I think the problem can be in the calling convention and perhaps with the
type of the parameter.

  I have been mixing Delphi with DLLs made in Visual C++, and here is an
examples of external function declaration, perhaps it may help you.

  Delphi Declaration:

function SetValue(Variable: PChar; VariableLength: Cardinal;
                  Value: PChar; ValueLength: Cardinal;
                  var Index, ValueType: Cardinal): Integer; cdecl;
                  external 'Intermed.dll';


  DLL C++ declaration:

#define DllExport extern "C" __declspec( dllexport )

enum TValueType {vtNone=0, vtReal, vtInteger, vtString, vtRealVector};

DllExport int   SetValue(char *Variable, unsigned int VariableLength,
                         char *Value, unsigned int ValueLength, int *Index,
                         TValueType *ValueType);

  As you can see, C++'s ints have been replaced by Delphi's Cardinal, and
the calling convention have been set to "cdecl".

  The only way I know to determine which calling convention you have to use
and which are the types that match C++ (or other languages) types is test
and error (and sometimes a little of inspection of the CPU window).

  By the way, I am very interested in use NetCDF from Delphi in the future,
but now I don´t have the time to do the porting. I'll like very much if you
keep me informed of your progress.

  Of course, if I can help you just write me.

José María González Ondina.

jmg@xxxxxxxxxxxxxx



 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690