Delphi and NULL pointers

Top  Previous  Next

Many DTWAIN functions that process strings allows the string parameter to be NULL.  For example, the DTWAIN_GetErrorString function has the option to set the string parameter to NULL if the caller only desires to have the length of the error string returned.

 

For Delphi applications, you must use the nil keyword for sending NULL pointers to DTWAIN:

 

For example, to call DTWAIN_GetErrorString with a NULL pointer

 

  var

      ErrSize : Integer;

      MsgBuf:  Array of AnsiChar;

 

  begin

           { Get Size of error string }

            ErrSize := DTWAIN_GetErrorString( DTWAIN_ERR_BAD_SOURCE, nil, 0 );

 

           { Set the size and get the string }

            SetSize( MsgBuf, ErrSize );

            DTWAIN_GetErrorString( DTWAIN_ERR_BAD_SOURCE, PAnsiChar(MsgBuf), ErrSize );