Files
TeslaRel410/BORLAND/BDE/EXAMPLES/PASCAL/OPTPARAM.PAS
T
CydandClaude Fable 5 63312e07f9 source410: literal 4.10 source reconstruction + BC++ 4.52 fleet toolchain archived
- BORLAND/: Borland C++ 4.52 (chosen over 4.5 by byte-match: CODE/RP/CW32.LIB
  is identical to 4.52's install lib). BCC32/TLINK32/TLIB/MAKE run natively on
  Win11; CODE/BT/OPT.MAK is the shipped BTL4OPT.EXE's exact flag recipe
  (extender = Borland PowerPack DPMI32, not Phar Lap TNT).
- restoration/source410/: the literal 1995-form reconstruction of the missing
  BT game source (never mixed into CODE/). Round 1-3 state:
  * 6 of 10 surviving original TUs COMPILE CLEAN under the period toolchain
    (BTMSSN, BTCNSL, BTSCNRL, BTTEAM, BTL4MODE, BTL4ARND) - first builds
    since 1996.
  * BT_L4/BTL4APP.CPP pilot reconstruction: 12/12 functions, Fail() lands on
    its binary-recorded line 400 exactly.
  * BT/BTCNSL.HPP: console wire IDs recovered from the binary's ctors
    (Killed=9, Damaged=10, ScoreUpdate=13, DeathWithoutHonor=15 [T1];
    TeamScore=12 flagged [T4]).
  * MUNGA/: 8 engine-header backfills back-dated from the BT412 WinTesla tree
    (VDATA numbering decomp-verified; AUDREND's OpenAL-era virtual removed -
    the period compiler is the drift detector).
  * Tooling: backdate.py (WinTesla->1995 header transform), compile410.sh
    (per-TU verification sweep under authentic OPT.MAK flags).
  * README: corrected roadmap - MECH.HPP is the capstone grown with the mech
    TU reconstructions; BTREG.CPP green = the header-family milestone.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 07:33:26 -05:00

323 lines
12 KiB
ObjectPascal

{ optparam.pas }
program OptParam;
{$IfDef VER80}
uses SnipTool, SnipData, SysUtils, WinTypes, WinProcs,
DbiProcs, DbiTypes, DbiErrs;
{$Else}
uses WinTypes, WinCrt, Strings, DbiProcs, DbiTypes, DbiErrs,
SnipTool, SnipData;
{$EndIf}
const
szTblName = 'OPTPARAM'; { Name of table to be created. }
szTblType = szPARADOX; { Table type to use. }
NAMELEN = 10; { Set the length of the name fields }
PLACELEN = 20; { Set the length of the POB field }
DATELEN = 11; { Length that a date will be displayed: mm\dd\yyyy }
{ Field Descriptor used in creating a table. }
fldDes: array[0..1] of FLDDesc = (
( { Field 1 - AUTOINC }
iFldNum: 1; { Field Number }
szName: 'NUMBER'; { Field Name }
iFldType: fldFLOAT; { Field Type }
iSubType: fldUNKNOWN; { Field Subtype }
iUnits1: 0; { Field Size ( 1 or 0 )}
iUnits2: 0; { Decimal places ( 0 ) }
iOffset: 0; { Offset in record ( 0 ) }
iLen: 0; { Length in Bytes ( 0 ) }
iNullOffset: 0; { For Null Bits ( 0 ) }
efldvVchk: fldvNOCHECKS; { Validiy checks ( 0 ) }
efldrRights: fldrREADWRITE { Rights }
),
( { Field 2 - ALPHA }
iFldNum: 2; szName: 'ALPHA';
iFldType: fldZSTRING; iSubType: fldUNKNOWN;
iUnits1: NAMELEN; iUnits2: 0;
iOffset: 0; iLen: 0;
iNullOffset: 0; efldvVchk: fldvNOCHECKS;
efldrRights: fldrREADWRITE
)
); { Array of field descriptors }
{=====================================================================
Function:
GetOptionalParams( szDriver: pCHAR; *iFields: UINT16;
pfldDesc: pFLDDesc; szData : pCHAR);
Input: szDriver - Name of the driver
iFields - Used to return the number of fields
pfldDesc - Returns the descriptors of the fields.
Memory for this variable must be allocated by
the calling calling.
szData - Contains the values of the fields. Memory for
this variable must be allocated by the calling
function.
Return: DBIResult - success of the function
Description:
This function is used to return the available optional
parameters when creating a table of the given type. This
information includes the number of optional parameters
(iFields), an array of field descriptors describing those
parameters, and the default values for the parameters.
===================================================================== }
function GetOptionalParams(szDriver: pCHAR; var iFields: UINT16;
pfldDes: pFLDDesc; szData: pCHAR): DBIResult;
var
rslt: DBIResult; { Return value from IDAPI functions }
hCur: hDBICur; { Handle to the Cursor }
szNode: pCHAR; { String which contains the name of the node }
CfgDesc: pCFGDesc; { Configuration Descriptor }
szCfgPath: array[0..DBIMAXPATHLEN+1] of CHAR; { Maximum length of the path
in the configuration file. }
const
iOffset: UINT16 = 0;
piFields = nil;
begin
iFields := 0;
{ Set up the option to get from the Configuration File }
StrCopy(szCfgPath, '\DRIVERS\');
StrCat(szCfgPath, szDriver);
StrCat(szCfgPath, '\TABLE CREATE\');
rslt := DbiOpenCfgInfoList(nil, dbiREADONLY, cfgPersistent,
szCfgPath, hCur);
ChkRslt(rslt, DBIERR_NONE,' Error - OpenCfgInfoList.');
if (rslt <> DBIERR_NONE) then
begin
GetOptionalParams := rslt;
exit;
end;
{ Allocate resources }
GetMem(szNode, DBIMAXNAMELEN * sizeof(CHAR) + 1);
GetMem(CfgDesc, sizeof(CFGDesc));
{ Process all nodes
Get the next record in the table - contains the next option
of the given level in the tree. }
while (DbiGetNextRecord(hCur, dbiNOLOCK, pBYTE(CfgDesc), nil)
= DBIERR_NONE) do
begin
pfldDes^.iFldNum := iFields + 1;
pfldDes^.iFldType := CfgDesc^.iDataType;
pfldDes^.iUnits1 := DBIMAXSCFLDLEN - 1;
pfldDes^.iLen := DBIMAXSCFLDLEN;
StrCopy(pfldDes^.szName, CfgDesc^.szNodeName);
{ Display the remaining information
Display the Description of the node }
StrCopy(szNode, CfgDesc^.szValue);
StrCopy(szData+iOffset, szNode);
Inc(iOffSet, pfldDes^.iLen);
Inc(iFields);
Inc(pfldDes);
end;
Dec(pfldDes, iFields);
FreeMem(szNode, DBIMAXNAMELEN * sizeof(CHAR) + 1);
FreeMem(CfgDesc, sizeof(CFGDesc));
ChkRslt(DbiCloseCursor(hCur), DBIERR_NONE,
' Error - CloseCursor.');
GetOptionalParams := rslt;
end;
{=====================================================================
Function:
OptParam();
Description:
This function shows how to use the optional parameters
on some of the BDE functions.
===================================================================== }
var
hDb: hDBIDb; { Handle to the database }
hCur: hDBICur; { Handle to the table }
TblDesc: CRTblDesc; { Create table descriptor }
crProps: CURProps; { Cursor Properties }
pfldDes: pFLDDesc; { Field Descriptor for Opt Params }
iFields: UINT16; { Number of fields (Opt params) }
i: UINT16; { Loop counter }
iOffset: UINT16; { Offset in the default values buffer }
szFieldName: array[0..DBIMAXSCRECSIZE] of CHAR; { Field name }
szDefault: array[0..DBIMAXSCRECSIZE] of CHAR;
{ Default values for Opt params }
szTemp: array[0..DBIMAXSCFLDLEN] of CHAR; { Temporary Buffer }
szData: array[0..DBIMAXSCRECSIZE] of CHAR; { Data to display }
uNumFields: INT16;
const
uDispNumRecs: UINT16 = 10; { Number of records to add and display }
begin
Screen('*** Using Optional Parameters ***');
Screen(' Initializing IDAPI...');
if (InitAndConnect(hDb) <> DBIERR_NONE) then { Terminate example if }
begin { Initialization fails }
Screen('');
Screen('*** End of Example ***');
exit;
end;
Screen(' Setting the default Database directory...');
ChkRslt(DbiSetDirectory(hDb, pCHAR(szTblDirectory)), DBIERR_NONE,
' Error - SetDirectory.');
{ The number of fields in the table - note that fldDesc is defined
globally }
uNumFields := trunc(sizeof(fldDes) / sizeof (fldDes[0]));
{ Initialize the pFldDesc variable to all zero's }
GetMem(pfldDes, DBIMAXSCFIELDS * sizeof(FLDDesc));
FillChar(pfldDes^, SizeOf(FLDDesc) * DBIMAXSCFIELDS, #0);
{ Initialize the TblDesc variable to all zero's }
FillChar(TblDesc , SizeOf(CRTblDesc), #0);
{ Get the field types and default values of the optional
parameters available when creating a Paradox Table }
ChkRslt(GetOptionalParams('PARADOX', iFields, pfldDes, szData),
DBIERR_NONE, ' Error - GetOptionalParams.');
Screen('');
Screen(' Default values for Optional Parameters...');
Screen('');
StrCopy(szFieldName, ' ');
StrCopy(szDefault, ' ');
iOffset := 0;
for i := 1 to iFields do
begin
{ Note: Fields are formatted to be 20 characters wide
in order to better fit on the screen (Field width's
default to 128). }
RightPad(szTemp, pfldDes^.szName, 20);
StrCat(szFieldName, szTemp);
RightPad(szTemp, szData+iOffset, 20);
StrCat(szDefault, szTemp);
{ Create the table as a 3.5 table. }
if (StrComp(pfldDes^.szName, 'LEVEL') = 0) then
StrCopy(szData+iOffset, '3');
{ Set the maximum size of the table to 256MB }
if (StrComp(pfldDes^.szName, 'BLOCK SIZE') = 0) then
StrCopy(szData+iOffset, '4096');
{ Increment to point to the next field within the
array of default values. }
iOffset := iOffSet + pfldDes^.iLen;
Inc(pfldDes);
end;
Dec(pfldDes, iFields);
Screen(StrPas(szFieldName));
Screen(StrPas(szDefault));
Screen('');
Screen(' Change Optional Parameters to...');
Screen('');
StrCopy(szFieldName, ' ');
StrCopy(szDefault, ' ');
iOffset := 0;
for i := 1 to iFields do
begin
{ Note: Fields are formatted to be 20 characters wide
in order to better fit on the screen (Field width's
default to 128). }
RightPad(szTemp, pfldDes^.szName, 20);
StrCat(szFieldName, szTemp);
RightPad(szTemp, szData+iOffset, 20);
StrCat(szDefault, szTemp);
{ Increment to point to the next field within the
array of default values. }
iOffset := iOffSet + pfldDes^.iLen;
Inc(pfldDes);
end;
Dec(pfldDes, iFields);
Screen(StrPas(szFieldName));
Screen(StrPas(szDefault));
Screen('');
Screen(' Initializing the table descriptor...');
StrCopy(TblDesc.szTblName, szTblName);
StrCopy(TblDesc.szTblType, szTblType);
TblDesc.iFldCount := uNumFields;
TblDesc.pfldDesc := @fldDes;
TblDesc.iOptParams := iFields;
TblDesc.pfldOptParams := pfldDes;
TblDesc.pOptData := @szData;
Screen('');
Screen(' Creating the Paradox table...');
if (ChkRslt(DbiCreateTable(hDb, TRUE, TblDesc), DBIERR_NONE,
' Error - CreateTable.') <> DBIERR_NONE) then
begin
FreeMem(pfldDes, DBIMAXSCFIELDS * sizeof(FLDDesc));
Screen(' Close the Database and exit IDAPI...');
CloseDbAndExit(hDb);
Screen('');
Screen('*** End of Example ***');
exit;
end;
FreeMem(pfldDes, DBIMAXSCFIELDS * sizeof(FLDDesc));
Screen(' Fill the table with Random Data...');
FillTable(hDb, pCHAR(szTblName), pCHAR(szTblType), uDispNumRecs);
Screen(' Open the '+szTblName+' table...');
if (ChkRslt(DbiOpenTable(hDb, pCHAR(szTblName), pCHAR(szTblType),
nil, nil, 0, dbiREADWRITE, dbiOPENSHARED,
xltFIELD, FALSE, nil, hCur),
DBIERR_NONE, ' Error - OpenTable.') <> DBIERR_NONE) then
begin
ChkRslt(DbiDeleteTable(hDb, pCHAR(szTblName), pCHAR(szTblType)),
DBIERR_NONE, ' Error - DeleteTable.');
CloseDbAndExit(hDb);
Screen('');
Screen('*** End of Example ***');
exit;
end;
Screen('');
Screen(' Determine the properties of the table:');
ChkRslt(DbiGetCursorProps(hCur, crProps), DBIERR_NONE,
' Error - SetDirectory.');
Screen(' Table Level: '+IntToStr(crProps.iTblLevel));
Screen(' Table block size: '+IntToStr(crProps.iBlockSize*1024));
Screen('');
Screen(' Display the '+szTblName+' table which we just created...');
DisplayTable(hCur, uDispNumRecs);
Screen('');
Screen(' Close the Table...');
ChkRslt(DbiCloseCursor(hCur), DBIERR_NONE,
' Error - CloseCursor.');
Screen(' Deleting the table...');
ChkRslt(DbiDeleteTable(hDb, pCHAR(szTblName), pCHAR(szTblType)),
DBIERR_NONE, ' Error - DeleteTable.');
Screen('');
Screen(' Close the Database and exit IDAPI...');
CloseDbAndExit(hDb);
Screen('*** End of Example ***');
end.