Get values from DBGrid

Posted in Databases

If you want to get values of all columns of selected row from DBGrid component, then use Fields and FieldCount properties, like in this example.

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  Memo1.Clear;
  with DBGrid1 do
  begin
    for i:=0 to FieldCount-1 do
      Memo1.Lines.Add(Fields[i].AsString);
  end;
end;