Delphi - Unit x was compiled with a different vers

2019-07-05 05:22发布

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?

2条回答
我命由我不由天
2楼-- · 2019-07-05 05:41

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.

查看更多
该账号已被封号
3楼-- · 2019-07-05 05:41

What if Delphi XE6 original System.JSON.dcu wasn't compiled with Delphi XE6 but it was compiled with one of the previous versions of Delphi.

You claim that you managed to implement your fix in Delphi XE2 using same approach by changing source and then recompiling System.JSON. SO I suggest you first make a comparison between original System.JSON files that ship with both Delphi XE2 and Delphi XE6.

If they are the same then the changed System.JSON.dcu that you managed to recompile with Delphi XE2 might also work with Delphi XE6.

查看更多
登录 后发表回答