Reputation: 69
I'm not much of a Delphi programmer, I'm happy to do C++Builder programming, delphi is not my language. I have some components written in Delphi and they compile fine in 10.3 but I do get errors in 10.4, and I can see the problem why, but I have no clue how to fix it. Please help me fix it.
procedure CopyInterlacedRGB8(const Pass: Byte; Src, Dest, Trans, Extra: pChar)
Dest^ := Char(fOwner.GammaTable[pByte(Longint(Src) + 2)^]); inc(Dest); // changed these two, but I have no clue what I'm doing lul
Dest^ := Char(fOwner.GammaTable[pByte(Longint(Src) + 1)^]); inc(Dest);
Byte(Dest^) := fOwner.GammaTable[pByte(Longint(Src) )^]; inc(Dest); // ERROR here
The way I see here, as I understand in C++, there is a byte being initialized, and it is being assigned. Similar to char('a') = 5; But I can see what the code originally wants to do, assign something to address of Dest.
How should I change this stuff around so it works??
Upvotes: 1
Views: 264
Reputation: 12292
You didn't give the declaration of GammaTable
. I created one which seems suitable. I have not initialized it here, but it should be in your code. If your declaration is different, maybe my code has to be modified.
var
GammaTable : array [Byte] of Byte;
procedure CopyInterlacedRGB8(const Pass: Byte; Src, Dest, Trans, Extra: pChar);
var
BDest : PByte;
begin
BDest := PByte(Dest);
BDest^ := GammaTable[PByte(UIntPtr(Src) + 2)^]; Inc(BDest);
BDest^ := GammaTable[PByte(UIntPtr(Src) + 1)^]; Inc(BDest);
BDest^ := GammaTable[PByte(UIntPtr(Src) )^]; Inc(BDest);
end;
I have not changed the arguments type on the function, but for sure Src
and Dst
should be PByte
not PChar
. Anyway, the code I wrote will work equally well whatever it is provided it contain the desired source and destination table.
I introduced the BDest
variable to make the code more readable.
Note that if Src
is declared as PByte
and {$POINTERMATH ON}
then the code can be simplified:
PByte(UIntPtr(Src) + 2)^
becomes
Src[2];
So the procedure can be rewritten like this:
{$POINTERMATH ON}
procedure CopyInterlacedRGB8_(const Pass: Byte; Src, Dest : PByte; Trans, Extra: pChar);
begin
Dest[0] := GammaTable[Src[2]];
Dest[1] := GammaTable[Src[1]];
Dest[2] := GammaTable[Src[0]];
end;
Much more readable, isn't it?
Upvotes: 1