Solve "File x was compiled with a different version of y" when recompiling VCL (TStringGrid) file
Asked Answered
K

1

0

I need to change the TStringGrid (change some private fields/methods). So I made a copy of the pas file. I also deleted the DCU file from Delphi, but I have to see if this is a good idea. Then I put the Vcl.Grids.pas file into my DPR file.

However, my program uses the TMS library, which also needs the Vcl.Grids which leads to this problem: How to recompile a specific unit from the VCL? enter image description here

So I want to rename the modified Vcl.Grids.pas to Vcl_Grids.pas and TStringGrid -> TStringGrid2.

What is wiser?

  1. To have TMS use my new component (TStringGrid2 in Vcl_Grids.pas)
  2. Leave TMS use the original component (TStringGrid in Vcl.Grids.dcu)
Km answered 13/3 at 8:47 Comment(6)
3. Create a class helper for TStringGrid or a so called "class hack". The later is like redeclaring the TStringGrid class in another unit with the same class name and inheriting from the original one: TStringGrid = class(Vcl.GridsTStringGrid). Now you should be able to at least access protected fields and methods of the original TStringGrid class.Actinology
@DelphiCoder. Does it still work? blogs.embarcadero.com/…Km
This depends on the Delphi version you are using. But with current versions rather no. I also explicitly stated, that you can only access protected methods and fields. It would be more helpful, if you could explain what you want to change in the TStringGrid class. Maybe there is a better way to achieve your goals!?Actinology
@Actinology - There are many changes - but I haven't done them. Personally, I would avoid doing such modifications whenever possible. From what I understand, some are there to fix some bugs, others are simply customizations to fit our needs. One example: some extra items have been added to the TGridOption enumeration.Km
You would need to rebuild all packages (including TMS) that reference the TStringGrid. That means you would need the full source for TMS too. Rebuilding the VCL is possible, but not recommended. Another option is to rename TStringGrid, but depending on your use case that might not work, and with the TStringGrid it would be rather complicated. Worth a shot though.Catechize
Related: #10471443Km
K
0

I decided to go on with renaming the TStringGrid and to have TMS use the "new" grid (TStringGrid2).
It worked.

Km answered 14/3 at 16:1 Comment(2)
If your version is heavily customized, it is worth to create a better name, at least TExtStringGrid. This way it will be easier to work with your code in the future.Finitude
@Finitude - I agree 102% with you. It was only an attempt to see if my change will work (and it worked). Now I can do a batch replace to a better name.Km

© 2022 - 2024 — McMap. All rights reserved.