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

5

8

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.

Granddaughter answered 2/3, 2012 at 13:2 Comment(2)
I used a component based on Marco Cantus ObjectDataSet code, and it became the Object of much hate and scorn, once it was deeply embedded in an application being developed by a team of delphi devs. So if it's going to become an important part of your architecture in a large app, please please think again. It seemed like such a good idea at the time and now lives on in my memory as one of the most horrendous elements of any delphi app ever. I sunk 500 hours finding the weird glitches deep inside it, so I'll never recommend the approach to anyone again ever.Give
It's mostly for debugging.. to quickly view the status of a collection of objects. The Delphi debugger is a bit useless if you want to quickly scan large amounts of in-memory objects. I now use SuperObject to serialize to a tmemo in json format. Having a DB-grid would be easier to read.Granddaughter
S
4

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

Shelley answered 2/3, 2012 at 13:56 Comment(0)
M
2

Take a look at EverClassy Dataset from Inovativa at www.inovativa.com.br/public.

Mechanist answered 8/3, 2013 at 18:35 Comment(0)
S
1

DotNet4Delphi by A-Dato Scheduling Technology from the Netherlands is good for you.

enter image description here

Quotes:

From Torry's Delphi

Hook up any collection to your data aware controls.

DotNet4Delphi implements many .Net collection classes, including generic types like List<> and Dictionary<>. Different from their Delphi counterpart is that our generic collections also implement the non-generic interfaces (IList, IDictionary) allowing you to access your collections in multiple ways. This opens the door to use any collection as a data source for data aware controls which is exactly what the (also included) TListDataset component provides.

It targets Delphi XE and XE2.

It's an open source initiative, Delphi rocks !!!

Summons answered 9/4, 2012 at 11:3 Comment(0)
C
1

another one is Snap Object Dataset http://digilander.libero.it/snapobject/

Contemplative answered 1/11, 2013 at 8:24 Comment(0)
S
1

I have found a more relevant resource and can't help sharing it! So relevant that I think it deserves a separate post rather than a mere update in my first answer.


The Dduce library for Delphi XE2-XE6 makes use of TListDataSet<...> a generic dataset component that can be used to expose a generic list as a TDataSet.

The most relevant units pertaining to the implementation of the generic dataset are:

Class hierarchy:

TDataSet <= TCustomVirtualDataset <= TListDataset <= TListDataset<T>

Yes, it inherits lots of features... my only wish is to have at my disposal a version working with a lessen requirement (Delphi XE without most of the other bells and whistles).

Look and feel:

enter image description here

Summons answered 24/1, 2015 at 13:5 Comment(1)
Thanks, this looks useful. I'm checking it our right now. Nice one!Granddaughter

© 2022 - 2024 — McMap. All rights reserved.