Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - dyncheckbuffer() return the size of the dynamic alias buffer http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 dyncheckbuffer()    Return the size of the dynamic alias buffer
------------------------------------------------------------------------------
 Declaration
   database.hdr

 Syntax
   func uint dyncheckbuffer extern
   param const char cFileName

 Arguments
   cFileName is the name of the database to analyze.

 Return
   The size of the alias buffer necessary to allocate for dynamically
   accessing the database. The value does not contain the size of the
   alias structure itself.

 Description
   The dyncheckbuffer() function analyzes the field structure of a
   database, and returns the size of the required alias buffer.

   Dynamic aliases allocated in the data or stack segment need a proper
   amount of additional space for additional alias data not reserved by
   the Force compiler. The support buffer is normally a byte array that
   must be declared in association with the alias declaration.

   At runtime, when the name of a database to be opened dynamically
   becomes known, an application can call dyncheckbuffer() to
   verify if a statically allocated alias buffer is sufficient for
   opening that particular database, or to determine the necessary
   buffer size when allocating the alias at runtime. Using a too small
   buffer will result in overwriting other memory objects, and is likely
   to lead to program misbehavior or system crash.

 Example
   #define EXAMPLE_DATABASE
   #define _DYNALIAS_
   #define _ALIASPTR_
   #include example.hdr

   #define BUFFER_SIZE 300                     // alias buffer size
   
   proc Test_dyncheckbuffer
   vardef
      byte  aBuffer[ BUFFER_SIZE ]             // alias buffer
      alias sAlias                             // dynamic alias
      uint  nBufSize                           // necessary buffer size
   enddef
   nBufSize := dyncheckbuffer( "stest.dbf" )   // query necessary buffer size
   if nBufSize <= BUFFER_SIZE                  // if allocation is big enough
      if dynopen( &sAlias, "stest.dbf", DO_SHARED ) // open database
         ? reccount()
         append blank                          // add a record
         ? reccount()
         close sAlias                          // close database
      endif
   else                                        // if allocation too small
      ? "Field structure too complex:", ;      // message
         istr( nBufSize ), "bytes are necessary"
   endif
   endproc

   proc main
   Test_dyncheckbuffer()
   endproc

See Also: dynopen()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson