Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: How to make this code Tokyo compatible



Permlink Replies: 4 - Last Post: Mar 29, 2018 10:38 AM Last Post By: Remy Lebeau (Te...
Christian Kaufm...

Posts: 68
Registered: 7/26/98
How to make this code Tokyo compatible
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 28, 2018 2:05 AM
I have an old library which works fine in Berlin, but doesn't compile
in Tokyo. Here is the extract:

type
TgtWordArray = array of Word;

TgtScriptRunCallback =
procedure(AText: WideString;
ARunIndex, ARunCount: Integer;
var AGlyphInfoList: TgtGlyphInfoList;
AGlyphDetail: TgtRunInfo;
ALogClust: TgtWordArray) of object;

var
AScriptRunCallback: TgtScriptRunCallback;
LLogClust: array of Word;
begin
....
SetLength(LLogClust, LScriptItemLength);
....
AScriptRunCallback(LSubText, LI, LScriptItemCount, LRunInfoList,
LRunInfo, @LLogClust[0]); <<<<<<< This call fails

I just wonder, if there is a simple way to change that code, so it
works in Tokyo just like it did in Berlin.

cu ck

Olivier Sannier

Posts: 424
Registered: 8/26/01
Re: How to make this code Tokyo compatible
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 28, 2018 7:33 AM   in response to: Christian Kaufm... in response to: Christian Kaufm...
Christian Kaufmann wrote:
I have an old library which works fine in Berlin, but doesn't compile
in Tokyo. Here is the extract:

type
TgtWordArray = array of Word;

TgtScriptRunCallback =
procedure(AText: WideString;
ARunIndex, ARunCount: Integer;
var AGlyphInfoList: TgtGlyphInfoList;
AGlyphDetail: TgtRunInfo;
ALogClust: TgtWordArray) of object;

var
AScriptRunCallback: TgtScriptRunCallback;
LLogClust: array of Word;
begin
....
SetLength(LLogClust, LScriptItemLength);
....
AScriptRunCallback(LSubText, LI, LScriptItemCount, LRunInfoList,
LRunInfo, @LLogClust[0]); <<<<<<< This call fails

I just wonder, if there is a simple way to change that code, so it
works in Tokyo just like it did in Berlin.


Instinctively, I would say use this:

AScriptRunCallback(LSubText, LI, LScriptItemCount, LRunInfoList,
LRunInfo, LLogClust);

after having typed LLogLust as TgtWordArray

But I don't see why there was ever a need for the @ operator to begin
with...
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to make this code Tokyo compatible
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 28, 2018 11:25 AM   in response to: Christian Kaufm... in response to: Christian Kaufm...
Christian Kaufmann wrote:

I have an old library which works fine in Berlin, but doesn't compile
in Tokyo.

The code you have shown should not compile in ANY version of Delphi.
You are passing a pointer to a single Word where a TgtWordArray dynamic
array is expected. They are NOT the same thing!

You need to change your LLogClust variable from "array of Word" to
"TgtWordArray", and then pass that variable to AScriptRunCallback as
just "LLogClust" and not as "@LLogClust[0]":

var
  AScriptRunCallback: TgtScriptRunCallback;
  LLogClust: TgtWordArray;
begin
  ...
  AScriptRunCallback(..., LLogClust);
  ...
end;


That will then work in every Delphi version.

--
Remy Lebeau (TeamB)
Christian Kaufm...

Posts: 68
Registered: 7/26/98
Re: How to make this code Tokyo compatible
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2018 6:19 AM   in response to: Christian Kaufm... in response to: Christian Kaufm...
Thanks for all replies. Seems to work.

I have one more:

type
TGIS_FileTIFFSItem = record
Data : TBytes ;
Dim : Integer;
PreAlloc : array of Byte; // preallocated bytes
end;

var
STable : array of TGIS_FileTIFFSItem

begin
STable[STableSize].Data := Pointer(STable[STableSize].PreAlloc) ;

If I remove the Pointer type cast I still get an error. Probably a
similar problem. Again, is there an a easy solution?

cu ck

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to make this code Tokyo compatible
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2018 10:38 AM   in response to: Christian Kaufm... in response to: Christian Kaufm...
Christian Kaufmann wrote:

var
STable : array of TGIS_FileTIFFSItem

begin
STable[STableSize].Data := Pointer(STable[STableSize].PreAlloc) ;

Make sure you are allocating memory for STable before you access its
elements:

SetLength(STable, ...); // desired element count


And also allocate memory for the PreAlloc field:

SetLength(STable[SomeIndex].PreAlloc, ...); // desired byte count


Unless PreAlloc is being assigned to point at an external preallocated
array instead:

STable[index].PreAlloc := SomeArray;


If I remove the Pointer type cast I still get an error.

Yes, because you are assigning one array type to a different
incompatible array type. Every time you use "array of ...", you are
declaring a new array type. If you have two separate "array of Byte"
declarations, they are separate types, even though they use the same
underlying Byte type. This is covered in the Delphi documentation

http://docwiki.embarcadero.com/RADStudio/en/Structured_Types_(Delphi)#Dynamic_Arrays

If you want to assign the PreAlloc field to the Data field, You need to
change the PreAlloc field to TBytes so it matches the Data field:

type
  TGIS_FileTIFFSItem = record
    Data     : TBytes ;
    Dim      : Integer;
    PreAlloc : TBytes;
  end;


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02