![]() ![]() ![]() ![]() ![]() ![]() ![]() |
||
BDE API Examples (DbiOpenVChkList)Creates an in-memory table containing records with information about validity checks for fields within the specified table.Return all validity check information for a specific fieldThis example uses the following input:HasVChk(Table1, Table1.Fields[0], VChk); TChk is defind as follows: TVChk = record Required, HasDefault, HasMin, HasMax: boolean; DefValue, MinValue, MaxValue: string; end;If a validity check exists on the specified field, the function returns TRUE. If the function returns TRUE then the information in TVChk will return specific validity check information. The function is defined as follows: function HasVChk(Table: TTable; Field: TField; var VChk: TVChk): boolean;
function ValToStr(VCHK: DBIVCHK; FldType: word): string;
var
L: longint;
I: Integer;
D: Double;
MyDate: BDE.DBIDATE;
MyTime: BDE.Time;
Hour, Minute, MSecond: Word;
MyTS: BDE.TimeStamp;
W1: word;
Month, Day: word;
Year: Smallint;
begin
case FldType of
fldZSTRING: Result := PChar(@VCHK);
fldFLOAT:
begin
Move(VCHK, D, sizeof(D));
Result := FloatToStr(D);
end;
fldINT32, fldUINT32:
begin
Move(VCHK, L, sizeof(L));
Result := IntToStr(L);
end;
fldINT16:
begin
Move(VCHK, I, sizeof(I));
Result := IntToStr(I);
end;
fldUINT16:
begin
Move(VCHK, W1, sizeof(W1));
Result := IntToStr(W1);
end;
fldDATE:
begin
Move(VCHK, MyDate, sizeof(MyDate));
if MyDate < 0 then
Result := 'TODAY'
else
begin
Check(DbiDateDecode(MyDate, Month, Day, Year));
Result := Format('%d/%d/%d', [Month, Day, Year]);
end;
end;
fldTIME:
begin
Move(VCHK, MyTime, sizeof(MyTime));
if MyTime < 0 then
Result := 'NOW'
else
begin
Check(DbiTimeDecode(MyTime, Hour, Minute, MSecond));
if Hour < 12 then
Result := Format('%d:%d:%d AM', [Hour, Minute, MSecond div 1000])
else
Result := Format('%d:%d:%d PM', [Hour - 12, Minute, MSecond div 1000]);
end;
end;
fldTIMESTAMP:
begin
Move(VCHK, MyTS, sizeof(MyTS));
if MyTS = 0 then
Result := 'NOW'
else
begin
Check(DbiTimeStampDecode(MyTS, MyDate, MyTime));
Check(DbiDateDecode(MyDate, Month, Day, Year));
Check(DbiTimeDecode(MyTime, Hour, Minute, MSecond));
if Hour < 12 then
Result := Format('%d/%d/%d @ %d:%d:%d AM',
[Month, Day, Year, Hour, Minute, MSecond div 1000])
else
Result := Format('%d/%d/%d @ %d:%d:%d PM',
[Month, Day, Year, Hour - 12, Minute, MSecond div 1000]);
end;
end;
end;
end;
var
Props: CURProps;
V: VCHKDesc;
hCur: hDBICur;
pField: pFLDDesc;
begin
Result := False;
Check(DbiGetCursorProps(Table.Handle, Props));
if Props.iValChecks > 0 then
begin
Check(DbiOpenVChkList(Table.DBHandle, PChar(Table.TableName),
Props.szTableType, hCur));
pField := AllocMem(Props.iFields * sizeof(FLDDesc));
try
while DbiGetNextRecord(hCur, dbiNOLOCK, @V, nil) = DBIERR_NONE do
begin
if V.iFldNum = Field.Index + 1 then
begin
Result := true;
VChk.Required := V.bRequired;
VChk.HasDefault := V.bHasDefVal;
VChk.HasMin := V.bHasMinVal;
VChk.HasMax := V.bHasMaxVal;
Check(DbiGetFieldDescs(Table.Handle, pField));
Inc(pField, Field.Index);
if VChk.HasDefault = TRUE then
VChk.DefValue := ValToStr(V.aDefVal, pField^.iFldType);
if VChk.HasMin = TRUE then
VChk.MinValue := ValToStr(V.aMinVal, pField^.iFldType);
if VChk.HasMax = TRUE then
VChk.MaxValue := ValToStr(V.aMaxVal, pField^.iFldType);
Dec(pField, Field.Index);
end;
end;
finally
FreeMem(pField);
Check(DbiCloseCursor(hCur));
end;
end;
end;
| ||
|
DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains. |
||
| Trademarks & Copyright © 1998 Borland International, Inc. | ||