[fpc-pascal] Proper way to assign data to fields & documentation

Reinier Olislagers reinierolislagers at gmail.com
Mon Aug 1 08:06:10 CEST 2011


(Reposted from the forum; I think I might actually get a response here ;)

While writing a test program with TBufDataset, I'm trying to create a
dataset with as many field types as possible. The following code compiles:

  FTestDataset.Fieldbyname('ftBCD').Asfloat := Testextended;
  FTestDataset.Fieldbyname('ftBlob_4096').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftBoolean').Asboolean := Testboolean;
  FTestDataset.Fieldbyname('ftBytes').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftCurrency').Ascurrency := Testextended;
  FTestDataset.Fieldbyname('ftDate').Asdatetime :=Testdatetime;
  FTestDataset.Fieldbyname('ftDateTime').Asdatetime :=Testdatetime;
  FTestDataset.Fieldbyname('ftDBaseOle').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftFixedChar_2').Asstring :=Teststring;
  FTestDataset.Fieldbyname('ftFixedWideChar_2').Asstring :=Teststring;
  FTestDataset.Fieldbyname('ftFloat').Asfloat := Testextended;
  FTestDataset.Fieldbyname('ftFMTBcd').Asfloat := Testextended;
  FTestDataset.Fieldbyname('ftFmtMemo').Asstring :=Teststring;
  FTestDataset.Fieldbyname('ftGraphic').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftGuid').Asinteger :=Testinteger;
  FTestDataset.Fieldbyname('ftInteger').Asinteger :=Testinteger;
  FTestDataset.Fieldbyname('ftLargeint').Asinteger :=Testinteger;
  FTestDataset.Fieldbyname('ftMemo').Asstring :=Teststring;
  FTestDataset.Fieldbyname('ftOraBlob').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftOraClob').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftParadoxOle').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftSmallInt').Asinteger :=Testinteger;
  FTestDataset.Fieldbyname('ftString_1').Asstring :=Teststring;
  FTestDataset.Fieldbyname('ftString_256').Asstring :=Teststring;
  FTestDataset.Fieldbyname('ftTime').Asdatetime :=Testdatetime;
  FTestDataset.Fieldbyname('ftTypedBinary').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftVarBytes').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftVariant').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftWideMemo').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftWideString').Asstring := Teststring;
  FTestDataset.Fieldbyname('ftWord').Asinteger := Abs(Testinteger);

... but I'm sure I'm doing something wrong in some cases. Running this
code gives an access violation when printing the output from ftBytes:
  for Fieldcounter:= 0 to FTestDataset.Fields.Count-1 do
  begin
    writeln('Field: ' + FTestDataset.Fields[FieldCounter].FieldName + '
has value ' + FTestDataset.Fields[FieldCounter].AsString);
  end;

Questions: what is the proper way to assign values to these data fields
and is there some documentation/reference for that?

Thanks,

Reinier



More information about the fpc-pascal mailing list