I am trying to create a dBase Table using TTables CreateTable method.
But it seems to be impossible to create numeric fields with more than 4
decimals.
Does anyone know how to do that.
Even
NewTable.FieldDefs := AlreadyExistingTable.FieldDefs;
where AlreadyExistingTable contains numeric fields with more than 4 decimals
doesn't work.
Why is that?
Thanks in advance.
Oliver
AFIK it is impossible with a TTable.
Use a TQuery and set the sql to something on the order of this:
create Table 'TableName'
(
cFieldName char(25),
nFieldName numeric(5,2),
dFieldName date
)
query.ExecuteSQL
be sure to attach the query to a database with the database set at
driverName := STANDARD
Params.Add('PATH=Drive:\whatever')
Params.Add('DEFAULT DRIVER= FOXPRO') // I like the foxpro driver
Parmas.Add('ENABLE BCD=FALSE')
After you have created it you can open it with a TTable if you like
--
Charles Lam
Asst. DP Manager
The Personal Marketing Company
Charles AT Tpmco Dot Com
Here's how to do it.
procedure TForm1.make_employee_table;
begin
try
table.close;
table.FieldDefs.Clear;
table.TableName := 'EMPLOYEE.DBF';
table.FieldDefs.Add('ID',ftstring,10,FALSE);
table.FieldDefs.Add('NAME',ftstring,32,FALSE);
table.FieldDefs.Add('HOME',ftstring,20,FALSE);
table.FieldDefs.Add('PROFILE',ftstring,16,FALSE);
table.FieldDefs.Add('BADGE',ftinteger,0,FALSE);
table.FieldDefs.Add('TIMEKEEPER',ftstring,15,FALSE);
table.FieldDefs.Add('RESTRICT',ftstring,15,FALSE);
table.FieldDefs.Add('SCHEDULE',ftstring,15,FALSE);
table.FieldDefs.Add('DATE_CHG',ftDATE,0,FALSE);
table.FieldDefs.Add('TIME_CHG',ftstring,5,FALSE);
table.FieldDefs.Add('BASE_WAGE',ftinteger,0,FALSE);
table.FieldDefs.Add('REFERENCE1',ftstring,32,FALSE);
table.FieldDefs.Add('REFERENCE2',ftstring,32,FALSE);
table.FieldDefs.Add('REFERENCE3',ftstring,32,FALSE);
table.FieldDefs.Add('FLAGS',ftinteger,0,FALSE);
table.CreateTable;
table.AddIndex('ID','ID',[ixUnique]);
table.AddIndex('NAME','NAME',[]);
except
messagedlg('Creation of EMPLOYEE.DBF failed',mtError,[mbOk],0);
end;
end;
Charles Lam wrote:
--
--------------------------------------------------------
WIMP (windows, icons, mouse, pointer)
--------------------------------------------------------
Let Microsoft try to destroy Linux.
Let Microsoft gloat over the binaries.
Just don't tell them that we can make
another anytime we wish.
--------------------------------------------------------
sand...@ohiotime.com
--------------------------------------------------------
>I am trying to create a dBase Table using TTables CreateTable method.
>But it seems to be impossible to create numeric fields with more than 4
>decimals.
>Does anyone know how to do that.
Oliver,
The easiest way to create dBase tables in Delphi is to use SQL via the
TQuery component.
However, it is also possible through TTable. You have to use the
ftBCD field type to create the table. Specify the number of decimals
in the TFieldDef.Size property and the field length in the
TFieldDef.Precision property (a bit counter-intuitive IMO).
>Even "NewTable.FieldDefs := AlreadyExistingTable.FieldDefs"
>where AlreadyExistingTable contains numeric fields with more than 4 decimals
>doesn't work.
>Why is that?
When you open a dBase table in Delphi, numeric fields with more than 4
significant digits or with decimal places will be translated to
TFloatField. But as you already noticed, you cannot specify the width
and decimals of floatfields.
Hope this helps,
Jan