I update this page periodically, based on new things I learn, or interesting and unusual questions from the Delphi classes I teach. Suggestions and/or comments are more than welcome!
Last updated: 12/08/04.
![]()
TTable.FieldCount reports the number of INSTANTIATED fields or fields you have used in the table, not the number in its underlying structure. Here's a little function I wrote that you can use to find out the ACTUAL number of fields.
I've only tested this on Paradox tables. If you find it doesn't work for other file formats and/or you have a solution for other file formats, please let me know, and I'll update this information.
function GetFieldCount(T: TTable): Integer;
var
curProp: CURProps;
bWasOpen: Boolean;
begin
Result := 0; {Just in case something goes wrong.}
bWasOpen := T.Active;
try
if not bWasOpen then
T.Open;
Check(DbiGetCursorProps(T.Handle, curProp));
Result := curProp.iFields;
finally
if not bWasOpen then
T.Close;
end;
end;
You need to include DbiErrs, DbiTypes and DbiProcs (Delphi 1.0) or BDE (Delphi 2.0) in your uses for this to work. It would probably be somewhat more efficient if I used DBIOpenTable to open the table; this is just a "quick" example!
©1997 Maggie Owens.