I am a Delphi developer and a C# Developer. C# has the DataTable class that supports random access to Rows. Is there a third-party TDataSet (Delphi) component that is like DataTable (C#)?
There's TClientDataSet
class in Delphi, which functionality is similar to DataSet
in .NET.
You can use TADODataSet
for a disconnected in-memory dataset as suggested by Ian. It is very powerful as opposed to TClientDataSet
IMO.
But all the low level ADO
stuff is not needed. it is simple as:
var
ds: TADODataSet;
ds := TADODataSet.Create(nil);
//add our fields
ds.FieldDefs.Add('InvoiceNumber', ftInteger);
ds.FieldDefs.Add('CustomerName', ftWideString, 200);
ds.FieldDefs.Add('CreatedDate', ftDateTime);
ds.FieldDefs.Add('Comments', ftWideMemo);
ds.FieldDefs.Add('Quantity', ftFloat);
ds.FieldDefs.Add('InvoiceTotal', ftCurrency);
ds.CreateDataSet;
//Add a row of values - the easy way
ds.Append;
ds.FieldByName('InvoiceNumber').AsInteger := 1783;
ds.FieldByName('CustomerName').AsString := 'Hubert Farnsworth';
ds.FieldByName('CreatedDate').AsDateTime := Now;
ds.FieldByName('Comments').AsString := 'The quick brown fox jumped over the lazy dog';
ds.FieldByName('Quantity').AsFloat := 19809.32; //imperial gallons
ds.FieldByName('InvoiceTotal').AsCurrency := 99.95; //GBP
ds.Post;
//Add another row of values - with an array of values all at once
ds.AppendRecord([1784, 'Steven Gates', Now, '//no comment', 1292, 19.25]);
You can also edit existing data:
ds.First;
ds.Edit;
ds.FieldByName('InvoiceNumber').AsInteger := 1786;
You can then use TDataSource
to bind it to the TADODataSet
and use data aware controls if needed linked to the TDataSource
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With