From 7e96130ba66c3138d01d6bd0cbfecb93cf5bcc7e Mon Sep 17 00:00:00 2001 From: Martijn Laan <1092369+martijnlaan@users.noreply.github.com> Date: Wed, 15 May 2024 16:35:17 +0200 Subject: [PATCH] Fix two TStream issues: 1) It's not abstract anymore. Don't know since when exactly but at least in Sidney it's not abstract. 2) Read/Write(Buffer) prototype is bad and very impractical on Unicode. Make it like it really is: they accept a var of any type and this can be done in PS by using 'const' as the type and still _not_ using 'var'. Tested it to work unchanged when a string type is used in the call anyway. Also note this fix has no runtime changes so it's not surprising that it still works. --- Source/uPSC_classes.pas | 10 ++++++---- Source/uPSR_classes.pas | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Source/uPSC_classes.pas b/Source/uPSC_classes.pas index c297b47..12d3f5a 100644 --- a/Source/uPSC_classes.pas +++ b/Source/uPSC_classes.pas @@ -134,9 +134,11 @@ procedure SIRegisterTSTREAM(Cl: TPSPascalCompiler); begin with Cl.AddClassN(cl.FindClass('TObject'), 'TStream') do begin + {$IFNDEF DELPHI_SYDNEY_UP} IsAbstract := True; - RegisterMethod('function Read(Buffer: string; Count: LongInt): LongInt'); - RegisterMethod('function Write(Buffer: string; Count: LongInt): LongInt'); + {$ENDIF} + RegisterMethod('function Read(Buffer: const; Count: LongInt): LongInt'); + RegisterMethod('function Write(Buffer: const; Count: LongInt): LongInt'); {$IFDEF DELPHI_TOKYO_UP} {$IFNDEF PS_NOINT64} RegisterMethod('function Seek(Offset: Int64; Origin: Word): Int64'); @@ -144,8 +146,8 @@ begin {$ELSE} RegisterMethod('function Seek(Offset: LongInt; Origin: Word): LongInt'); {$ENDIF} - RegisterMethod('procedure ReadBuffer(Buffer: string; Count: LongInt)'); - RegisterMethod('procedure WriteBuffer(Buffer: string; Count: LongInt)'); + RegisterMethod('procedure ReadBuffer(Buffer: const; Count: LongInt)'); + RegisterMethod('procedure WriteBuffer(Buffer: const; Count: LongInt)'); {$IFDEF DELPHI4UP} {$IFNDEF PS_NOINT64} RegisterMethod('function CopyFrom(Source: TStream; Count: Int64): Int64'); diff --git a/Source/uPSR_classes.pas b/Source/uPSR_classes.pas index 51f6370..2e17d9d 100644 --- a/Source/uPSR_classes.pas +++ b/Source/uPSR_classes.pas @@ -624,9 +624,15 @@ procedure RIRegisterTSTREAM(Cl: TPSRuntimeClassImporter); begin with Cl.Add(TSTREAM) do begin + {$IFNDEF DELPHI_SYDNEY_UP} RegisterVirtualAbstractMethod(TMemoryStream, @TMemoryStream.READ, 'Read'); RegisterVirtualAbstractMethod(TMemoryStream, @TMemoryStream.WRITE, 'Write'); RegisterVirtualAbstractMethod(TMemoryStream, @TMemoryStream.SEEK, 'Seek'); + {$ELSE} + RegisterVirtualMethod(@TStream.READ, 'Read'); + RegisterVirtualMethod(@TStream.WRITE, 'Write'); + RegisterVirtualMethod(@TStream.SEEK, 'Seek'); + {$ENDIF} RegisterMethod(@TSTREAM.READBUFFER, 'ReadBuffer'); RegisterMethod(@TSTREAM.WRITEBUFFER, 'WriteBuffer'); RegisterMethod(@TSTREAM.COPYFROM, 'CopyFrom');