Save private variable of class



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/07/2008 at 15:26, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   10.5 
    Platform:      Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    Hi!

    I have a class and would like to save a variable of the class..

    class MyClass : public TagData
    {
         private:
              String check;
    [..]

    When I save the file and load it again, its empty. How can I save it?
    Thanks :)



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/07/2008 at 15:54, xxxxxxxx wrote:

    You need to implement CopyTo/Read/Write and save/load the data 'manually' in these methods. So, when the document is saved, Write() is called and you write out your variable. When the document is loaded, Read() is called and you read the value into the variable. CopyTo() should be implemented as well so that copies of your tag perpetuate the same values.

    That said, why not add the 'String check' as a resource to your tag. Anything (and I really mean EVERYTHING) that can be stored as a resource will mitigate this type of issue as the BaseContainer (data instance) is automatically written and read with the document save/load. The only type of data that BaseContainer cannot handle well is arrays.

    So, instead of "String check" in your class definition, add an resource description ID to your .h file and something like this to your .res file:

    STATICTEXT MYPLUGIN_CHECK { HIDDEN; }

    Note that I use STATICTEXT and not STRING as the latter represents an editable field. Why do that for an internal data variable?

    Now you have a String data which is not displayed but automatically saved/loaded with the document when your tag is present.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 10/07/2008 at 02:28, xxxxxxxx wrote:

    That's really nice, I would never have thought of that!
    Thanks,

    Jan



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 10/07/2008 at 05:58, xxxxxxxx wrote:

    Hi!

    After careful consideration I had to it on myself. Yes, you're right. Thats the best way to do it. I forgot the existence of a HIDDEN FIELD.

    Now it works. All right, thanks :)


Log in to reply