Replacing array of records with dataset |
|
Originally posted to public.datasnap but this is better forum...
I have a class that provides an indexed property that returns a record.
The caller accesses the data by providing an integer index to obtain an
array reference and then accesses the fields in the array by directly
referencing their field names.
I want to convert this class to use a TClientDataset and need to
simulate this property.
Question 1: What is the easiest/fastest/best way to simulate an array,
using an integer index, with a TClientDataset? My first inclination
would be to create an integer field, populate it with sequential
values, and use an index on this field to find each record. But I
thought a better way might be included in TClientDataset.
What do you think?
Question 2: What should the property return in my new class? Before it
returned an instance of a record. I could fill a whole record from
fields in the TCLientDataset and return that. I could also create a
class and have properties that match the old record fields. The getters
would then retrieve the field values directly from the dataset's fields.
Any ideas on what would work best here?
|
Re: Replacing array of records with dataset |
|
Dmitry Arefiev wrote:
> > Any ideas on what would work best here?
>
> 1) If you has XE5 or FireDAC AddOn pack, dont need CDS remote
> capabilities, then you can use TFDMemTable. Something like that:
>
> FDMemTable1.Table.Rows[].GetData()
>
> 2) Otherwise most simple wil be to use RecNo property:
>
> function GetItem(ARow, ACol: Integer): Variant;
> begin
> ClientDataSet1.RecNo := ARow + 1;
> Result := ClientDataSet.Fields[ACol].Value;
> end;
Thanks, Dmitry!
Could not have hoped for a better answer!
|
Re: Replacing array of records with dataset |
|
> Any ideas on what would work best here?
1) If you has XE5 or FireDAC AddOn pack, dont need CDS remote capabilities,
then you can use TFDMemTable. Something like that:
FDMemTable1.Table.Rows[].GetData()
2) Otherwise most simple wil be to use RecNo property:
function GetItem(ARow, ACol: Integer): Variant;
begin
ClientDataSet1.RecNo := ARow + 1;
Result := ClientDataSet.Fields[ACol].Value;
end;
--
With best regards,
Dmitry Arefiev / FireDAC Architect
|