1

I'm trying to do a framework using RTTI. But I can't figure out how to do the load from a master-detail.

For example, like this:

[HasMany('ID_CLIENTE')]
property Endereco: TObjectList<TEndereco> read FEndereco write FEndereco;

screenshot

I have a class that feeds the property directly from a DB, but I don't know how I can feed the property's master-detail.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Abucarub
  • 19
  • 3
  • 1
    This is a weird question, because you're trying to do something Advanced but it doesn't explain enough for anyone to know why you are stuck. It's terrible to put a screenshot of code, for one thing. For another, something as large a subject as one to many relationships, we can not guess what your framework does or how it works. Writing your framework for you is not on topic here. – Warren P Mar 01 '16 at 13:06
  • Sorry, It's my first topic here. – Abucarub Mar 01 '16 at 20:02
  • I have a generic class responsible to set a value on runtime to the propertys class, directly from DB, using attributes. With primitive types its ok, but when the property is TObjectList (master-detail) I can't, case in runtime i dont know how figure out what kind is that object, to do a cast. Sorry for my english. – Abucarub Mar 01 '16 at 20:19
  • I think your problem is you actually have even more problems than that. I suggest you should study existing ORMs, and you might learn techniques. I suspect your entire design is broken, and unworkable. Go study MORMOT for a while. http://synopse.info/fossil/wiki/Synopse+OpenSource – Warren P Mar 01 '16 at 21:23
  • I will. But why u suspect my entire design is broken, and unworkable? – Abucarub Mar 01 '16 at 22:54
  • Because designing an ORM is hard. It's cute that you're trying. Good luck. – Warren P Mar 02 '16 at 01:37
  • Thank you. But now, I have a only question. It's possible create a Object Generic List, of the type of the current class, in runtime (using RTTI)? If someone can answer it, it's a great start. – Abucarub Mar 02 '16 at 03:17
  • It is really simple, you walk the objectlist, treat each list object as TObject and hydrate it recursively? – whosrdaddy Mar 02 '16 at 08:22
  • Thanks for the answer whosrdaddy, I will try to be clearer. I have a class that has a property TObjectList, for example. Now I want a function, using RTTI, that returns a TObjectList, but in this return, should be of the type "TAddress" in this case. function TClient.GetAddress: TObjectList; begin if not assigned(result) then result := functionGenericRTTIthatReturnListCreate(codeFK); end; – Abucarub Mar 02 '16 at 14:21
  • You can create any class instance at runtime, look [here](http://stackoverflow.com/questions/3068775/how-to-create-an-instance-of-object-with-rtti-in-delphi-2010) for more info. The point is that your ORM object hydration logic should be as generic as possible. – whosrdaddy Mar 02 '16 at 21:22
  • Thanks a lot whosrdaddy ! The link you passed me is exactly what i was looking for. – Abucarub Mar 03 '16 at 03:01

0 Answers0