Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Serialization - startup failure

Hi, I cleaned up some of my code that I had been working on before integrating it into my main application.

All of a sudden and out of the blue, an error started popping up before the first line in the project source was executed. It was generated in the System.InitUnits method. The exception reads:

  Cannot seralize values of type pointer

I have traced all the way throgh the NG.Serialization unit, the call stack mentions one of my classes:-

uZzyGridDragDrop.{NG.Serialization}TMetadata.TTemplateEntry.Data<uZzyGridDragDrop.TZzyContactViewRecords,NG.Serialization.TMetadata.TTemplateEntry.TRead>.Create@

Firstly, although all class instances are really pointers there are no Pointer variables in my project. I have changes this class time and again but I cannot avoid the exception. 

Can you please help. I am out of time.
Thanks,
Robert.



Comments

  • 7 Comments sorted by Votes Date Added
  • There are some pointer fields or properties in your serializing classes or their ancestor classes.

    Can you create a small isolated demo project and send it to our support email along with information which IDE and NG Packs versions you use.
  • Hi Eugene,
    I finally found the problem. The class in question contained a property:

    property RecordList: TMoSortedList read FRecordList write FRecordList

    TMoSortedList is an internal created object list. I am not sure why this generated the error as it is a class. Way up in the inheritence chain it does handle pointers. Is this the reason? 

    Once I found this property was causing the issue I was able to easily change access to it by converting it to a function. The class had the [SkipAll] attribute on it and no data existed in the json string to access the record list. I tried just about all of the attributes that made sense to skip over this property but I could not find anything.

    Is there a recommended way of get
  • I meant to say, is there a recommended attribute that I should use in future to get around this issue?
  • Also, I looked at the  TMoSortedList class, it has a method:

    function Add(pKey: string, pData: Pointer): Pointer;


  • [SkipAll] attribute is for skipping values while reading from data source. In your case you need to use [Transient] attribute. Either on a class which contains pointer properties or on a pointer property itself.
  • So can I set this on the the property of my class

    [Transient]
    property RecordList: TMoSortedList read FRecordList write FRecordList

    or do I have to edit the TMoSortedList class and add the attribute to the method?

    [Transient]
    TMoSortedList.Add

    ??

  • Methods are not participate in serializing, so, no need to mark them in any way. Use the attribute to mark properties or whole classes.
Sign In or Register to comment.