[fpc-pascal] Re: Using TSdfDataset

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Sat Sep 6 14:18:58 CEST 2008


Now I got it a bit further. It seams that it doesn't crash if I set
FirstLineAsSchema to true, but it also shows wrong value.

Here is my database file:

ID,NAMEEN,NAMEPT,HEIGHT,WIDTH,PINS,DRAWINGCODE
1,resistor,resistor,1,1,1,LINE
2,capacitor,capacitor,1,1,1,LINE

When listing the value of the NAMEEN field it will show: NAMEEN,
resistor, resistor (yes, resistor again!)

The correct should be: resistor, capacitor

Any ideas? Every time I work with databases it's really frustrating =/

constructor TComponentsDatabase.Create;
begin
  inherited Create;

  FDataset := TSdfDataset.Create(nil);
  FDataset.FileName := vConfigurations.ComponentsDBFile;
//  FDataset.TableName := STR_DB_COMPONENTS_TABLE;
//  FDataset.PrimaryKey := STR_DB_COMPONENTS_ID;

  // Adds field definitions
{  FDataset.FieldDefs.Add('ID', ftString);
  FDataset.FieldDefs.Add('NAMEEN', ftString);
  FDataset.FieldDefs.Add('NAMEPT', ftString);
  FDataset.FieldDefs.Add('HEIGHT', ftString);
  FDataset.FieldDefs.Add('WIDTH', ftString);
  FDataset.FieldDefs.Add('PINS', ftString);
  FDataset.FieldDefs.Add('DRAWINGCODE', ftString);}

  FDataset.Delimiter := ',';
  FDataset.FirstLineAsSchema := True;

  FDataset.Active := True;
end;

destructor TComponentsDatabase.Destroy;
begin
  FDataset.Free;

  inherited Destroy;
end;

procedure TComponentsDatabase.FillStringListWithNames(AStringList: TStrings);
var
  i: Integer;
  CurField: TField;
begin
  AStringList.Clear;

  for i := 1 to FDataset.RecordCount do
  begin
    FDataset.RecNo := i;
    CurField := FDataset.FieldByName(STR_DB_COMPONENTS_NAMEEN);
    AStringList.Add(CurField.Value);
  end;
end;



More information about the fpc-pascal mailing list