Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a dataset of in-memory objects?

Does anyone know of a TDataset descendant that works with Generics and RTTI, so that I can write code like this, and make use of data-aware components in the GUI? :

...
ds:TDataset<TPerson>;
...

procedure DoStuff;
begin    
  ds:=TDataset<TPerson>.create;
  ds.add(TPerson.Create('A.','Hitler',77));
  ds.add(TPerson.Create('O.','Bin Laden',88));
 end; 

This should be possible. The fielddefs can be created via RTTI because the exact type of the data is known. Values can also be automatically marshalled back and forth, so you can both view and edit data that's in a class or a record.

I hate having to write a lot of useless marshalling code, while the required information for that is available via RTTI already.

Or maybe somebody once wrote some sort of TEnumerable <-> TDataset adapter?

Does something like that exist, or should I start writing one?

...

The closest thing that I could find is an (excellent!) example by Marco Cantu, from Mastering Delphi 7, but the code itself doesn't make use of new language features like generics, the new RTTI system, or attributes, and it doesn't work with Unicode delphi. TDataset has changed since D7 too.

like image 549
Wouter van Nifterick Avatar asked Mar 02 '12 13:03

Wouter van Nifterick


People also ask

What is an in-memory object?

In-memory databases are purpose-built databases that rely primarily on memory for data storage, in contrast to databases that store data on disk or SSDs.

What is a DataSet object?

The DataSet object is central to supporting disconnected, distributed data scenarios with ADO.NET. The DataSet is a memory-resident representation of data that provides a consistent relational programming model regardless of the data source.

How do you create a database in-memory?

Use create inmemory database to create an in-memory database, using model or another user database as its template. You can also create temporary databases as in-memory databases that reside entirely in in-memory storage. However, you cannot specify a template database for an in-memory temporary database.


1 Answers

The TAureliusDataSet included in TMS Aurelius comes very close to that.

like image 115
Uwe Raabe Avatar answered Nov 05 '22 22:11

Uwe Raabe