Recent

Author Topic: Design-time created FieldDefs for dbf table  (Read 3715 times)

wp

  • Hero Member
  • *****
  • Posts: 11923
Design-time created FieldDefs for dbf table
« on: July 22, 2016, 11:28:35 pm »
Playing with a dbf datastore for TvPlanit I came across this issue:

All the examples for creation of dbf files show how FieldDefs are created at run-time code. See for example http://wiki.freepascal.org/Lazarus_Tdbf_Tutorial#Code_example:_creating_a_table.2FDBF_file.

But TDbf is a component in the Lazarus component palette and has a property FieldDefs with property editor in the Object Inspector. Therefore, it should be possible to add the fielddefs at designtime. However, when the program is run and the table is opened after creation then an error "Invalid dbf file: Invalid field definition" is reported.

Please see attached demo. Button "FieldDefs by code" follows the wiki example and creates the fields at runtime - no issues here. But button "FieldDefs from OI" creates the FieldDefs at design time in the Object Inspector and crashes as described.

Am I missing something?

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Design-time created FieldDefs for dbf table
« Reply #1 on: July 23, 2016, 09:56:20 pm »
Found it... According to documentation, TDbf has a property StoreDefs which must be set to true if FieldDefs are supposed to be stored in the lfm file. In this case, the table is created correctly without any error.

I added a note to the wiki article (http://wiki.freepascal.org/Lazarus_Tdbf_Tutorial#Adding_fields_at_designtime).
« Last Edit: July 23, 2016, 10:06:32 pm by wp »

 

TinyPortal © 2005-2018