Article ID: 123975
Article Last Modified on 10/15/2003
ReadDb(<expN>,<expC>)
= ReadDb(1,"flda")
#include <pro_ext.h>
void FAR ReadDb(ParamBlk FAR *parm)
{
char FAR * fldname ; // name of field
char FAR * fldtxt ; // contents of field
NTI nti; // for _NameTableIndex
Locator loc; // a locator structure
Value val ; // a value structure
// Increase the size of the handle to the character string
// containing the field name so it can be null terminated.
if (!_SetHandSize(parm->p[1].val.ev_handle, parm->p[1].val.ev_length +
1))
{
_Error(182); // "Insufficient memory"
}
// Lock the handle to the character string containing
// the name of the field.
_HLock(parm->p[1].val.ev_handle) ;
// Establish a pointer to the character string containing
// the name of the field.
fldname = (char FAR *) _HandToPtr(parm->p[1].val.ev_handle) ;
// Null terminate the character string containing the
// name of the field.
fldname[parm->p[1].val.ev_length] = '\0' ;
// Get nti value for the field.
nti = _NameTableIndex(fldname) ;
// Unlock the handle to the character string containing
// the name of the field.
_HUnLock(parm->p[1].val.ev_handle) ;
if (nti == -1)
{
// This should not happen if a valid field name was passed.
_PutStr("\nNameTableIndex Failure") ;
}
else
{
// Fill locator structure with information about the field:
// Note that the second parameter to the _FindVar() function
// is the first parameter that was passed to this function.
// The first parameter to this function is a numeric value
// specified the work area in which the field is located.
if (! _FindVar(nti, (int) parm->p[0].val.ev_long, &loc))
{
// This should not happen if a valid field name was passed.
_PutStr("\nFindVar Failure") ;
}
else
{
// Fill a value structure with field values.
_Load(&loc,&val) ;
// This code is written to support fields that are of
// type character only.
if (val.ev_type == 'C')
{
// Create a null-terminated string which contains the
// text in the specified field.
if (!_SetHandSize(val.ev_handle, val.ev_length + 1))
{
_Error(182); // "Insufficient memory"
}
_HLock(val.ev_handle) ;
fldtxt = (char FAR *) _HandToPtr(val.ev_handle) ;
fldtxt[val.ev_length] = '\0' ;
// Display the values on the screen.
_PutStr("\n") ;
_PutStr(fldtxt) ;
// Unlock the handle to the text.
_HUnLock(val.ev_handle) ;
}
else
{
_PutStr("\nThe specified field is not of type Character.") ;
}
}
}
}
FoxInfo myFoxInfo[] =
{
{"READDB", (FPFI) ReadDb, 2, "I,C"},
};
FoxTable _FoxTable =
{
(FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};
Additional query words: VFoxWin 3.00 FoxWin 2.60a
Keywords: kbcode KB123975