Thema: Delphi Save record to BLOB

Einzelnen Beitrag anzeigen

Medium

Registriert seit: 23. Jan 2008
3.679 Beiträge
 
Delphi 2007 Enterprise
 
#4

Re: Save record to BLOB

  Alt 5. Dez 2009, 14:47
In that case, you'd have to write every sub-record/array yourself into the stream, and vice versa when loading. Another option would be to use a flat record that cointains all the fields directly, without structuring in sub-types. Of course this would lead to one looong record that won't be so conviniently usable with array indexes anymore.

I recommend writing a method that takes such a record as a parameter, manually writes every record/array in the desired order and returns that stream, ready to be saved. The same has to be done for loading of course. The biggest disadvantage of that is, that these methods have to be manually maintained when the record's structures change.

A more elegant version would involve using classes instead of records. Then you could implement something like a .ToStream() and .FromStream() method, which could use the RTTI to determin what to write/read, but taht would just be a bonus.

In Java there is another way of doing this: If a class implements the Serializable interface, it can easily be converted into a stream. If I recall correctly, there somewhere on these forums is a similar method for Delphi. That also might be a way for you.

In essence: Delphi does not resolve cascaded complex records/types in general by itself, you somehow have to write each yourself. There are multiple ways of doing this.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat