Will the const and typecasting options work as before in Delphi 64bit?

As a rule, I went around a lot of the classic design traps when using pointers using Const options (untyped), rather than hard-coded types. This gives me an edge in performing advanced graphics functions, leaving the technical details to the compiler. It also simplified the use of the same code in Delphi and Free Pascal with minimal changes. Recently, however, I began to question this because of the remarks of Embarcadero vauge about the evolution of Delphi and its dynamic security model.

For example, consider the following example:

Type TSomeDataProc = procedure (const aInput;var aOutput) of Object; (* Convert 8-bit pixel to 16-bit pixel *) Procedure TMyClass.ProcessSomeData08x565(Const aInput;var aOutput); var r,g,b: Byte; Begin FPalette.ExportTriplets(Byte(aInput),r,g,b); Word(aOutput):=(R SHR 3) SHL 11 or (G SHR 2) SHL 5 or (B SHR 3); End; (* Convert 16-bit pixel to 24-bit pixel *) Procedure TMyClass.ProcessSomeData565x888(Const aInput;var aOutput); Begin With TRGBTriple(aOutput) do Begin rgbtRed:=(((word(aInput) and $F800) shr 11) shl 3); rgbtGreen:= (((word(aInput) and $07E0) shr 5) shl 2); rgbtBlue:= ((word(aInput) and $001f) shl 3); end; End; 

Now we have two procedures with identical declarations, but they handle pixeldata in very different ways. This gives us the advantage of using a lookup table to get the correct converter method. This should be done either in the constructor or where the raster image of the image is selected, for example:

 Private FLookup: Array[pf8bit..pf32bit,pf8bit..pf32bit] of TSomeDataProc; Procedure TMyClass.Create; Begin Inherited; FLookup[pf8bit,pf16bit]:=ProcessSomeData08x565; FLookup[pf16bit,pf24Bit]:=ProcessSomeData565x888; end; 

Whenever we need to convert pixels, we simply scan the correct method and use it. The syntax for all procedures remains unchanged - so we don’t need to worry about how each procedure works. As for our class, they all look the same.

 Procedure TMyClass.ConvertTo(aFormat:TpixelFormat); Begin // Get function for the correct pixel converter FConvertProc:=FLookup[CurrentFormat,aFormat]; //Use the pixel converter FConvertProc(GetSourcePixelAddr(x,y),GetTargetPixelAddr(x,y)); end; 

Question: Will this type of typginging (for example: Const by Byte or any particular type of record) survive up to 64 bits? I personally cannot understand why not, but Embarcadero was a little vague regarding the new security model and the use of pointers, so it's a little difficult for me to protect my code for the future.

+7
source share
2 answers

Since such tricks are used in RTL, I don’t see the var or const parameter becoming obsolete without a value without a big code violation.

Embarcadero is working hard to ensure the highest possible backward compatibility.

They should even include the built-in asm back into the 64-bit compiler, after they first made some notice about using external assembler.

And such a modification will have nothing to do with the 64-bit model, while the x86-64 assembler has become a new piece of code for writing.

So, you should post this question in the official Embarcadero newsgroup, but I think you don't need to worry about that.

+3
source

Note that FPC has already changed the CONST parameter, but not in this case.

In the normal case, CONST is no longer guaranteed to be a reference for all calls, but follows what the corresponding ABI indicates. A new parameter type, CONSTREF, is guaranteed by reference.

Like any compatibility gap, the problem is that TP / Delphi CONST always uses ref, but TP / Delphi is also always x86.

In particular, all STDCALL functions change, for example, IUnknown.Queryinterface:

http://wiki.freepascal.org/User_Changes_Trunk#IInterface.QueryInterface.2C_._AddRef_and_._Release_definitions_have_been_changed

The reason is more or less that in these cases x86 ABI information introduced a common interface, which is not compatible with cross-architecture. Therefore, one must guess whether this is part of the language or part of the implementation of the x86 language.

Note that IUnknown is also used on other platforms, for example. Firefox XPCOM

Delphi can also hit such interferences, but I think that they will primarily affect functions / methods with explicit requirements for conditional calls, because you can change the internal convention according to your needs, but it is almost impossible to change the rest of the world ((XP ) COM or existing C (++)) libraries according to existing code in Delphi

+1
source

All Articles