[fpc-pascal] How to detect supported data types in dataset?

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Thu Sep 8 09:16:16 CEST 2011



On Thu, 8 Sep 2011, Reinier Olislagers wrote:

> Hi list,
>
> Possible newbie question so feel free to educate me ;)
> (Away for some days, so may not read response until back)
>
> A patch by Ludo Brands on bufdataset (mantis 19930) got me thinking:
>
> const
>  ftSupported = [ftString,ftGuid,... and so on];
>
> procedure TCustomBufDataset.CreateDataset;
> var i:integer;
> begin
> ...
> // check if all types are supported
>  For i:=0 to FieldDefs.Count-1 do
>    if not (Fielddefs.items[i].DataType in ftSupported) then
>
> DatabaseErrorFmt(SUnsupportedFieldType,[Fieldtypenames[Fielddefs.items[i].DataType]]);
>   CreateFields;
> end;
>
> Suppose I want to write a dataset data copier or importer/exporter, how
> do I detect supported datatypes in a dataset?
>
> For example, in my dbfexport test code, I make a bufdataset with all
> possible fields, then strip each field away when strange errors/AVs
> occur when assigning values to them.
> For other datasets (with similar checks as proposed in Ludo's patch),
> the runtime library is nice enough to warn me on field creation that it
> doesn't work.
>
> Am I missing something obvious or does it make sense to expose something
> like a SupportedFieldTypes property for datasets?
> How does Delphi do this?

It does not.

>
> Besides that, I think it's an excellent idea to check for invalid
> datatypes when creating fields, rather than failing later on when
> assigning values to them.

It is up to the implementation of the datasets to give a decent error when
an unsupported data type is being created.

Michael.



More information about the fpc-pascal mailing list