yktoo / dklang

DKLang Localization Package
56 stars 14 forks source link

Delphi 11: "Range check error" when using constants editor #29

Open AndrewKED opened 2 years ago

AndrewKED commented 2 years ago

I have just updated to Delphi 11 and find that opening the "DKLang - Edit project constants..." menu item is now causing a "Range check error".

I'm not sure that I have the skill set to fix this. I did try to create a separate project that just ran the editor. It starts OK but gave an AV on FConsts.Clear; in bOKClick().

Any help would be much appreciated!

bjmillerpa commented 2 years ago

Hi Andrew,

I've not maintained my subscription to Delphi, so I can't try to replicate your issue on Delphi 11. But, given that the error appears to be happening in a method that is provided with the Delphi 11 RTL (TDictionary<>.Clear) and not in DKLang and you upgraded, I'd start with a full Clean & Build instead of Compile so that any stray previous object code is overwritten.

Best regards, Bruce.

Bruce J. Miller

1-814-725-2312

On Fri, Jul 15, 2022 at 5:15 AM Andrew Spencer @.***> wrote:

I have just updated to Delphi 11 and find that opening the "DKLang - Edit project constants..." menu item is now causing a "Range check error".

I'm not sure that I have the skill set to fix this. I did try to create a separate project that just ran the editor. It starts OK but gave an AV on FConsts.Clear; in bOKClick().

Any help would be much appreciated!

— Reply to this email directly, view it on GitHub https://github.com/yktoo/dklang/issues/29, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFO24IDYYUZ7XJNB43E6XLVUET3ZANCNFSM53U6EOBA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

bagualing commented 1 year ago

I have the same problem.

AndrewKED commented 1 year ago

I backed off to 10.4.2 (because I had to get projects out), but will try again, now that 11.3 is out, and see what happens.

zystudios commented 1 year ago

Me too https://github.com/yktoo/dklang/issues/31

AndrewKED commented 1 year ago

Sorry - I did not get back to this issue. The problems that appeared with the "Project / DKLang - Edit project constants..." in Delphi 11 seem to have been sorted out in Delphi 11.3, without any work needing to be done on the DKLang source.

For reference, my notes to self for DKLang installation are: "Download the latest dklang-master.zip from github. Copy “dcldklang???.dpk” to “dcldklang280.dpk” and edit the file to change the header line to “package dklang280; “ and the “requires” line to “dklang280”. Copy “dklang???.dpk” to “dklang280.dpk” and edit the file to change the header line to “package dklang280;“. File | Open Project “dklang280.dpk” and Build. File | Open Project “dcldklang280.dpk” and Install.

zystudios commented 1 year ago

Sorry - I did not get back to this issue. The problems that appeared with the "Project / DKLang - Edit project constants..." in Delphi 11 seem to have been sorted out in Delphi 11.3, without any work needing to be done on the DKLang source.

For reference, my notes to self for DKLang installation are: "Download the latest dklang-master.zip from github. Copy “dcldklang???.dpk” to “dcldklang280.dpk” and edit the file to change the header line to “package dklang280; “ and the “requires” line to “dklang280”. Copy “dklang???.dpk” to “dklang280.dpk” and edit the file to change the header line to “package dklang280;“. File | Open Project “dklang280.dpk” and Build. File | Open Project “dcldklang280.dpk” and Install.

Thanks, that will solve the problem, it needs to be recompiled, although I don't know why, but it can be solved

AndrewKED commented 2 months ago

And now this "Range check error" issue has appeared again in Delphi 12.1, when closing the Constants editor. Maybe Delphi 12 has automatically enabled Range checking?

With some investigation, I think that I am seeing the cause, and would like confirmation that I am on the right track:

In DKL_ResFile.pas: TDKLang_ResFile.SaveToStream writes a "dummy 32-bit resource indicator" (of type TDKLang_ResEntry). This has .ResType and .Name defined, but no .RawData. The property therefore has a length of zero, and when RawData[0] in the TDKLang_ResEntry.SaveToStream procedure, a "Range check error" is flagged.

My simple solution is to either 1) Encase the line Stream.WriteBuffer(RawData[0], Length(RawData)); in {$R-} / {$R+} or 2) Insert an if statement, which skips this line if the RawData length is 0.

Any comments/suggestions on this?

bjmillerpa commented 2 months ago

Hi Andrew,

I am currently traveling without computer. I’ll look into it when I get home next week.

Thanks, Bruce

Sent from iPhone

On Wed, Sep 4, 2024 at 9:14 AM Andrew Spencer @.***> wrote:

And now this "Range check error" issue has appeared again in Delphi 12.1, when closing the Constants editor. Maybe Delphi 12 has automatically enabled Range checking?

With some investigation, I think that I am seeing the cause, and would like confirmation that I am on the right track:

In DKL_ResFile.pas: TDKLang_ResFile.SaveToStream writes a "dummy 32-bit resource indicator" (of type TDKLang_ResEntry). This has .ResType and .Name defined, but no .RawData. The property therefore has a length of zero, and when RawData[0] in the TDKLang_ResEntry.SaveToStream procedure, a "Range check error" is flagged.

My simple solution is to either

  1. Encase the line Stream.WriteBuffer(RawData[0], Length(RawData)); in {$R-} / {$R+} or
  2. Insert an if statement, which skips this line if the RawData length is 0.

Any comments/suggestions on this?

— Reply to this email directly, view it on GitHub https://github.com/yktoo/dklang/issues/29#issuecomment-2328092679, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFO24JFJSHIG6TIUFVZVH3ZU2XNBAVCNFSM6AAAAABNTUWIW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRYGA4TENRXHE . You are receiving this because you commented.Message ID: @.***>

bjmillerpa commented 2 months ago

Hi Andrew,

My guess is that TDKLang_ResEntry.FRawData gets initialized to an empty array in some compiler versions and not in others. So I think the safest work around would be to make sure it has a valid value. As I am not set up to test for your situation, please try the following and let me know how it works out. If it works for you, I'll commit it.

In DKL_ResFile.pas near line 338 edit:

  REIndicator.ResType := '0';
  REIndicator.Name    := '0';
  REIndicator.SaveToStream(Stream);

to add the RawData initialization:

  REIndicator.ResType := '0';
  REIndicator.Name    := '0';
  REIndicator.RawData := [];
  REIndicator.SaveToStream(Stream);

Cheers, Bruce.

Bruce J. Miller

1-814-725-2312

On Wed, Sep 4, 2024 at 10:51 AM Bruce J. Miller @.***> wrote:

Hi Andrew,

I am currently traveling without computer. I’ll look into it when I get home next week.

Thanks, Bruce

Sent from iPhone

On Wed, Sep 4, 2024 at 9:14 AM Andrew Spencer @.***> wrote:

And now this "Range check error" issue has appeared again in Delphi 12.1, when closing the Constants editor. Maybe Delphi 12 has automatically enabled Range checking?

With some investigation, I think that I am seeing the cause, and would like confirmation that I am on the right track:

In DKL_ResFile.pas: TDKLang_ResFile.SaveToStream writes a "dummy 32-bit resource indicator" (of type TDKLang_ResEntry). This has .ResType and .Name defined, but no .RawData. The property therefore has a length of zero, and when RawData[0] in the TDKLang_ResEntry.SaveToStream procedure, a "Range check error" is flagged.

My simple solution is to either

  1. Encase the line Stream.WriteBuffer(RawData[0], Length(RawData)); in {$R-} / {$R+} or
  2. Insert an if statement, which skips this line if the RawData length is 0.

Any comments/suggestions on this?

— Reply to this email directly, view it on GitHub https://github.com/yktoo/dklang/issues/29#issuecomment-2328092679, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFO24JFJSHIG6TIUFVZVH3ZU2XNBAVCNFSM6AAAAABNTUWIW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRYGA4TENRXHE . You are receiving this because you commented.Message ID: @.***>