[fpc-pascal] Re: Using TSdfDataset

Howard Page-Clark hdpc at talktalk.net
Sat Sep 6 21:14:34 CEST 2008


Felipe Monteiro de Carvalho wrote:
> 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

> 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;

Try this:

procedure TComponentsDatabase.FillStringListWithNames(AStringList: 
TStrings);
var
  i : Integer;
  CurField: TField;
begin
  AStringList.Clear;
  CurField := FDataset.FieldByName(STR_DB_COMPONENTS_NAMEEN);
  FDataset.First;
  while not FDataset.EOF do
   begin
    AStringList.Add(CurField.Value);
    FDataset.CursorPosChanged;
    FDataset.Next;
   end;
end;

Yours

Howard 




More information about the fpc-pascal mailing list