Re:Creating a lookup/calculated field at runtime on a runtime TTable
I think you need to create all of your persitant fields first
following this model:
var intfld : TField;
i : integer;
begin
Table1.FieldDefs.Update;
Table1.Close;
for i := 0 to Table1.FieldDefs.Count -1 do
Table1.FieldDefs[i].CreateField(Table1);
intfld := TIntegerField.Create(Table1);
with intfld do begin
FieldName := '...';
FieldType := fkLookup;
DataSet := Table1;
Name := '...';
Calculated := True;
LookupDataSet := Table2;
Keyfields := '...';
Lookupfields := '...';
LookupResultField := '...'
end
end;
Quote
"Paul Gonella" <pa...@estimation.co.uk> wrote in message
news:3b5851ca$1_1@dnews...
Quote
> Delphi 6
> Win 2000
> BDE
> Help! I have a TTable created at runtime and it is hooked up to a Paradox
table with 3 fields. I have created a TStringField (calculated) and hooked
it up to the TTable. For some reason when opened my TTable only has the one
field - the calculated one! It works okay without the calculated field. I
create the field with the following code:
Quote
> flCompanyName := TStringField.Create(tbTable);
> with flCompanyName do
> begin
> file://Set new calculated field's properties
> FieldKind := fkCalculated;
> FieldName := FLD_VID_COMPNAME;
> Name := 'tbTable' + FieldName;
> Index := FLD_VID_COUNT;
> DataSet := tbTable;
> ReadOnly := True;
> file://Add to table
> file://tbTable.FieldDefs.Update;
> end;
> file://Set auto calc
> tbTable.AutoCalcFields := True;
> tbTable.OnCalcFields := CalcFields;
> It originally wanted to have a lookup field instead of a calculated one
and tried it but had the same problem.
Quote
> Please help!
> Thanks,
> Paul.