Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Delphi 10.2 Tokyo #1

Open
IgitBuh opened this issue Jun 4, 2018 · 4 comments
Open

Update for Delphi 10.2 Tokyo #1

IgitBuh opened this issue Jun 4, 2018 · 4 comments

Comments

@IgitBuh
Copy link

IgitBuh commented Jun 4, 2018

To use this library with Delphi 10.2 and later, three procedures in SBUtils.pas need to be modified. I've chosen to overload them for not touching the original code.

// Addition for DX 10.2
// "Given that dynamic arrays are managed types, involving reference counting 
// and associated helper function generation, casting array elements using 
// the @ operator is disallowed as it leads to memory corruption. Performing a 
// similar operation is still allowed using an explicit cast operation, under the 
// developer responsibility."
// http://docwiki.embarcadero.com/RADStudio/Tokyo/en/What%27s_New
procedure PointerToLInt(var B : PLInt; const P : Pointer; Size : integer);
begin
  PointerToLInt(B, ByteArray(P), Size);
end;

procedure LIntToPointer(B: PLInt; P: Pointer; var Size: LongInt);
begin
  LIntToPointer(B, ByteArray(P), Size);
end;

procedure SBMove(Src: ByteArray; SrcOffset: Integer; Dst: Pointer; DstOffset: Integer; Size: Integer);
begin
  SBMove(Src, SrcOffset, ByteArray(Dst), DstOffset, Size);
end;

And of course:

procedure PointerToLInt(var B : PLInt; const P : Pointer; Size : integer); overload;
procedure LIntToPointer(B: PLInt; P: Pointer; var Size: LongInt); overload;
procedure SBMove(Src: ByteArray; SrcOffset: Integer; Dst: Pointer; DstOffset: Integer; Size: Integer); overload;

For not having to modify the project compiler settings in every project where you use this library, I would recommend to add these three lines at the top of SecBbox.inc:

{$define SB_UNICODE_VCL}
{$define SB_NO_BYTEARRAY_CONST_ARRAYS}
{$define SB_PASCAL_STRINGS}
@aldwado
Copy link

aldwado commented Feb 11, 2019

Hi,
That was very useful information.
You mentioned the PointerToLint procedure twice.
Did you mean the LIntToPointer requires a similar change, eg,
procedure LIntToPointer(B: PLInt; P: Pointer; var Size: Integer); Overload;

procedure LIntToPointer(B: PLInt; P: Pointer; var Size: Integer);
begin
LInttoPointer(B, ByteArray(P), Size);
end;
I know this post is 6 months old, but I hope you can reply back so I know I did the right thing.

Also in the defines for SecBBox.inc, you have {$define SB_NO_BYTEARRAY_CONST_ARRAYS} twice.
Was that a typo or am I missing another Define I should put in?
Thanks
AL

@IgitBuh
Copy link
Author

IgitBuh commented Feb 11, 2019

Thank you. I had to copy it from different locations and apparently copied it incorrectly. Sorry for my carelessness. It should be correct now.

@aldwado
Copy link

aldwado commented Feb 11, 2019

Hi IgitBuh,
Thank you very much for the quick response.
My code now compiles correctly.
I can't believe I found your post after endless searching, but am glad I did.

AL.

@aldwado
Copy link

aldwado commented Feb 20, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants