I'm trying to copy fields from one dataset to another at runtime. When
creating calculated fields I have the following:
with targetDS.FieldDefs do
begin
newField := field.newInstance as TField;
with newField do
begin
// need to set owner somewhere
FieldName := field.Name;
Calculated := True;
if newField is TFloatField then
TFloatField(newField).Currency := TFloatField(field).Currency;
DataSet := targetDS;
Name := targetDS.Name + FieldName;
targetDS.FieldDefs.Add(Name, field.dataType, 0, false);
end;
end;
I'm using newInstance because I don't want a giant case statement for
each different TField subClass. This works great but I'm concerned that
the owner is not getting set for the new field. Therefore, I'm worrried
that I've introduced a memory leak.
Any suggestions?
Preston