Board index » delphi » Dynamically Generating Tables at Runtime

Dynamically Generating Tables at Runtime

Hi,

I'm trying to create a table at runtime - ie not pre-specified no of fields.

1st problem : I'm trying to use the same datatype and size TFieldType types
as on another table. To do this I'm using statements : -

datatype := Table1.FieldByName(SelectedField).Datatype;
Size := Table1.FieldByName(SelectedField).Size;

Which seem to be reading the right info - but when I try and use these
variables in the following statement : -

Table2.FieldDefs.Add('VarName',datatype,size,false);

The fields are seemingly created, but data won't write to them. Simply by
substituting :-

Table2.FieldDefs.Add('VarName',ftString,20,false);

Then things work - but this is not really ideal. Can possibly get around
this one by using BatchMove - but it's bugging me why it won't work.

2nd problem : I want to generate the AppendRecord statement at runtime as I
don't know how many variables the table will have - but this isn't working
at all. Any suggestions about how I may get this to work? I don't think
BatchMove will solve this problem.

3rd problem : I'm using ftFloat - but my data is being rounded up to
integers on the output database, although the variables being written to the
fields are Real and definitely aren't integers.

Help - any advice welcome!

Thanks,

Dave

 

Re:Dynamically Generating Tables at Runtime


You have to call TFieldDef.CreateField to create the TField for the
TFieldDef, e.g.:

Table2.FieldDefs.Add('VarName', DataType, Size, False).CreateField(Self);

"Dave Ellis" <dave.el...@tnsofres.com> schreef in bericht
news:8ifoq8$iou$2@soap.pipex.net...

Quote
> Hi,

> I'm trying to create a table at runtime - ie not pre-specified no of
fields.

> 1st problem : I'm trying to use the same datatype and size TFieldType
types
> as on another table. To do this I'm using statements : -

> datatype := Table1.FieldByName(SelectedField).Datatype;
> Size := Table1.FieldByName(SelectedField).Size;

> Which seem to be reading the right info - but when I try and use these
> variables in the following statement : -

> Table2.FieldDefs.Add('VarName',datatype,size,false);

> The fields are seemingly created, but data won't write to them. Simply by
> substituting :-

> Table2.FieldDefs.Add('VarName',ftString,20,false);

> Then things work - but this is not really ideal. Can possibly get around
> this one by using BatchMove - but it's bugging me why it won't work.

> 2nd problem : I want to generate the AppendRecord statement at runtime as
I
> don't know how many variables the table will have - but this isn't working
> at all. Any suggestions about how I may get this to work? I don't think
> BatchMove will solve this problem.

> 3rd problem : I'm using ftFloat - but my data is being rounded up to
> integers on the output database, although the variables being written to
the
> fields are Real and definitely aren't integers.

> Help - any advice welcome!

> Thanks,

> Dave

Other Threads