Recent

Author Topic: ObjectBinaryToText error with a TReader/TWriter helper class  (Read 2997 times)

Basile B.

  • Guest
ObjectBinaryToText error with a TReader/TWriter helper class
« on: August 22, 2014, 02:37:41 am »
Hi, I've created two simple helpers to turn TReader and TWriter writeProperties(a: TPersistent) and readProperty(a: TPersistent) public. It's based on this it looks like that:
Code: [Select]
  TReaderEx = class helper for TReader
    procedure ReadPersistent(aValue: TPersistent);
  end;

  TWriterEx = class helper for TWriter
    procedure WritePersistent(aValue: TPersistent);
  end;

  procedure TReaderEx.ReadPersistent(aValue: TPersistent);
  begin
    ReadListBegin;
    while not EndOfList do ReadProperty(aValue);
    ReadListEnd;
  end;

  procedure TWriterEx.WritePersistent(aValue: TPersistent);
  begin
    WriteListBegin;
    WriteProperties(aValue);
    WriteListEnd;
  end;

It works fine when saving the persistent things in binary object format but fails when converting to text. Any idea about how to make this working (text format)? I don't want to rewrite the conversion routines just for this. A console example is attached.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: ObjectBinaryToText error with a TReader/TWriter helper class
« Reply #1 on: August 22, 2014, 10:20:14 am »
If the helper is NOT in the uses clause where the *persistent methods are used, then it won't do anything.

Basile B.

  • Guest
Re: ObjectBinaryToText error with a TReader/TWriter helper class
« Reply #2 on: August 22, 2014, 11:25:58 am »
It "uses", as you could see (if you've tested my example) the test is monolithic. The problem is really in the "marshalling" (bin to text).
BTW I've posted the same Q on SO, and according to one of the numerous disillusioned Delphi guru hanging over there, it seems that it's not possible without rewriting the bin to text method. I was trying to see if I forgot something in the code...but no. so far it cant work (with the text representation, in bin it's ok).

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: ObjectBinaryToText error with a TReader/TWriter helper class
« Reply #3 on: August 22, 2014, 11:46:26 am »
It "uses", as you could see (if you've tested my example) the test is monolithic.

I didn't test indeed, since I have to manage my time at work. Still the base premise, that your helper construct looks dodgy remains. It doesn't make the example clearer.

Quote
The problem is really in the "marshalling" (bin to text).

I've read the SO post, but Remy already answered.

Quote
numerous disillusioned Delphi guru hanging over there,

(that's your own baggage. I don't think Remy's post looks disillusioned at all in that or other posts)

Quote
it seems that it's not possible without rewriting the bin to text method. I was trying to see if I forgot something in the code...but no. so far it cant work (with the text representation, in bin it's ok).

It seems so yes. Probably because object* are meant for the IDE, and the IDE shows only published items, and the defined properties are not.

Basile B.

  • Guest
Re: ObjectBinaryToText error with a TReader/TWriter helper class
« Reply #4 on: August 22, 2014, 09:47:16 pm »
he he...dont bother. It was just a  very specific question. In the real world application I've finally decided to declare the members of the TPeristent one by one... even if it's not elegant at all...I like the build-in serialization system but it has its limits... :D >:(

A love/hate affair...

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: ObjectBinaryToText error with a TReader/TWriter helper class
« Reply #5 on: August 23, 2014, 01:03:10 pm »
I like the build-in serialization system but it has its limits... :D >:(

No doubt about that. I rarely use it anyway (or any build in serialization in any language for that matter), unless it is temporary state.

For real datafiles, versioning demands of the format makes things difficult sooner or later.

 

TinyPortal © 2005-2018