A: The following examples should get you started.
function TBizObj.CreateField(Dataset: TDataset; FieldName: string):
TField;
begin
with Dataset do begin
Result := FindField( FieldName ); { First, see if
it exists }
if Result = nil then begin { If so, no need to create
it. }
{ Have the FieldDef object create
its own Field Object }
if Owner <> nil then
Result := FieldDefs.Find(FieldName).CreateField(Owner)
else
Result := FieldDefs.Find(FieldName).CreateField(Dataset);
{ Give the new Field Object a generic
Name so that it appears in the Object Inspector}
Result.Name := Name + FieldName;
end;
end;
end;
function TBizObj.CreateCalcField( Dataset: TDataset; FieldName
: string;
FieldClass : TFieldClass; Size : Word ) : TField;
begin
Result := Dataset.FindField( FieldName );
if Result = nil then begin
if FieldClass = nil then
DBErrorFmt( SUnknownFieldType, [ FieldName
] );
Result := FieldClass.Create( Owner );
try
Result.FieldName := FieldName;
Result.Size := Size;
Result.Calculated := True;
Result.Dataset := Dataset;
Result.Name := Dataset.Name + FieldName;
except
Result.Free;
raise;
end;
end;
end; { TBizObj.CreateCalcField }