d:\program files\borland\delphi7\source\vcl\DBClient.pas
clientDataSet控件open后天就fields的源码
procedure TCustomClientDataSet.AddFieldDesc(FieldDescs: TFieldDescList;
var DescNo: Integer; var FieldID: Integer; FieldDefs: TFieldDefs);
var
FPrecision, I: Integer;
FType: TFieldType;
FSize: Integer;
FName: string;
FieldDesc: DSFLDDesc;
begin
FieldDesc := FieldDescs[DescNo];
Inc(DescNo);
with FieldDesc do
begin
if ((fldAttrLINK and iFldAttr) <> 0) then
begin
Inc(FieldID);
Exit;
end;
FName := szName;
I := 0;
while FieldDefs.IndexOf(FName) >= 0 do
begin
Inc(I);
FName := Format('%s_%d', [szName, I]);
end;
if iFldType < MAXLOGFLDTYPES then
FType := DataTypeMap[iFldType] else
if iFldType = fldUNICODE then
FType := ftWideString else
FType := ftUnknown;
FSize := 0;
FPrecision := 0;
case iFldType of
fldZSTRING, fldBYTES, fldVARBYTES, fldADT, fldArray:
begin
FSize := iUnits1;
if iFldSubType = fldstGuid then
FType := ftGuid;
end;
fldUNICODE:
FSize := iUnits1 div 2;
fldINT16, fldUINT16:
if iFldLen <> 2 then FType := ftUnknown;
fldINT32:
if iFldSubType = fldstAUTOINC then FType := ftAutoInc;
fldFLOAT:
if iFldSubType = fldstMONEY then FType := ftCurrency;
fldFMTBCD, fldBCD:
begin
FSize := Abs(iUnits2);
FPrecision := iUnits1;
if iFldType = fldFMTBCD then
FType := ftFMTBcd;
end;
fldBLOB:
begin
FSize := iUnits1;
if ( (iFldSubType >= fldstMEMO) and (iFldSubType <= fldstTYPEDBINARY))
or (iFldSubType = fldstHMEMO ) or ( iFldSubType = fldstHBINARY) then
FType := BlobTypeMap[iFldSubType];
end;
fldTABLE:
if iFldSubType = fldstREFERENCE then FType := ftReference;
end;
if FType <> ftUnknown then
with FieldDefs.AddFieldDef do
begin
FieldNo := FieldID;
Inc(FieldID);
Name := FName;
DataType := FType;
Size := FSize;
Precision := FPrecision;
Attributes := TFieldAttributes(Byte(iFldAttr));
if iFldSubType = fldstFIXED then
Attributes := Attributes + [faFixed];
InternalCalcField := bCalculated;
case FType of
ftADT:
for I := 0 to iUnits1 - 1 do
AddFieldDesc(FieldDescs, DescNo, FieldID, ChildDefs);
ftArray:
begin
I := FieldID;
AddFieldDesc(FieldDescs, DescNo, I, ChildDefs);
Inc(FieldID, iUnits2);
end;
end; { case }
end;
end;
end;