0

This is a follow on question to the answer posted here:

https://stackoverflow.com/a/55588208/2918172

It has a workaround for a bug in TJsonTextReader code where FChars private field is not flushed when the Rewind method is called. FChars is defined as follows in System.JSON.Readers.hpp:

typedef System::DynamicArray<System::WideChar> _TJsonTextReader__1;

_TJsonTextReader__1 FChars;

My question is how to achieve the same in C++Builder (using clang compiler). I've not used RTTI before. Here's what I have so far:

//workaround for RSP-24517
// Get class RTTI
TRttiContext context;
TRttiInstanceType *cls = dynamic_cast<TRttiInstanceType*>(context.GetType(__delphirtti(TJsonTextReader)));

if (cls)
{
    // Get field RTTI
    TRttiField *field = cls->GetField("FChars");
    if (field)
    {
        TValue val1, val2, val3;
        val1 = field->GetValue(AReader);        

        // 1st attempt: same as original delphi solution:
        val1.SetArrayElement(0, '\0');   // Cases "calling a protected constructor of class 'System::Rtti::TValue' " compiler error        

        // 2nd attempt: create new TValue as WideChar directly
        val2 = System::WideChar(0);      // builds but causes typecast exception when SetArrayElement is called
        val1.SetArrayElement(0, val2);

        // 3rd attempt: create new TValue by capturing type of existing array element and modifying the value
        val2 = val1.GetArrayElement(0);
        int tempVal = 0;
        System::Rtti::TValue::Make(&tempVal, val2.TypeData, val3);    // Causes "no matching function for call to 'Make' " compiler error
        val1.SetArrayElement(0, val3);                    
    }
}

How do I replace the first element of FChars with a null character?

DanAsh
  • 57
  • 2

0 Answers0