Warm tip: This article is reproduced from stackoverflow.com, please click
delphi json vcl datasnap

Delphi

发布于 2020-03-27 15:44:41

I am using Delphi XE6 and using Datasnap and JSON in my project. There is a bug I want to correct in the VCL unit System.JSON.pas (in the TJSONString.ToString function) where it should be escaping backslash characters as well as quotes. In order to fix this I carried out the following :

  1. Copied System.JSON.pas from the standard VCL source folder to my project source folder
  2. Added System.JSON.pas to my project (using the newly copied file)
  3. Fixed the bug and attempted to compile

I get the error 'Unit Data.DBXCommon was compiled with a different version of System.JSON.TJSONObject'

I can see that the Data.DBXCommon unit references System.JSON, so I guess the compiler is now seeing 2 versions - my fixed version and the standard VCL version.

What is the correct way to implement VCL changes to avoid this problem?

Questioner
Jonathan Wareham
Viewed
60
2017-05-23 20:20

There are two common reasons for this issue:

  1. You made changes to the interface section of the unit. You cannot do this without also re-compiling all units that use the unit you are modifying.
  2. You re-compile the unit with different compiler options from those used to build it originally. Deal with that by ensuring the compiler options used to compile the unit you modify are the same as used by Embarcadero. Typically Embarcadero compiles with default options. Impose these directly in the source file being modified, right at the very top of the file.

Having said this, a recent question here on a similar topic could not be resolved using option 2 above. In that question, under XE6 only, the unmodified Classes unit could not be re-compiled and linked at all. Which makes me wonder if this particular technique has had its day. Perhaps it's not even possible. Before you give up, see if you can compile and link the unmodified unit.

More broadly, using a detour is generally an easier way to solve such problems as you face. Using a detour rather than re-compiling makes the management of the fix cleaner and simpler.

Update 1

I cannot get the unmodified System.JSON unit to re-compile and link. Which I think means that the issue raised in that other question is broader than just the Classes unit. I think you will find this a tricky hurdle to overcome and recommend the use of a detour.

Update 2

The problem that appears to have been introduced in XE6, seems to have been resolved by the release of XE7. The unmodified System.JSON unit will compile and link in XE7.