Domanda

I have some derived Stream classes for older versions of RADStudio that just reimplement the Read,Write,Seek methods, and the Size and Position properties.

I'm looking to port these to XE3, but I see that there are now (for example) three overloads for Read - the original one, plus two that take TBytes as parameters.

Delphi

function Read(var Buffer; Count: Longint): Longint; overload; virtual;
function Read(Buffer: TBytes; Offset, Count: Longint): Longint; overload; virtual;
function Read(var Buffer: TBytes; Count: Longint): Longint; overload;

C++

virtual int __fastcall Read(void *Buffer, int Count)/* overload */;
virtual int __fastcall Read(System::DynamicArray<System::Byte> Buffer, int Offset, int Count)/* overload */;
int __fastcall Read(System::DynamicArray<System::Byte> &Buffer, int Count)/* overload */;

Do I need to implement all three, or just one? And if just one, which one...?

Normally I'd be able to find this from the VCL source, but I've just got the trial version (no source) at present.

È stato utile?

Soluzione

You only need implement the method read and write with these signatures

function Read(var Buffer; Count: Longint): Longint; overload; virtual;
function Write(const Buffer; Count: Longint): Longint

because the overloads versions which uses the TBytes (and System::DynamicArray<System::Byte>) as parameter internally calls to the above versions of Read and Write.

Altri suggerimenti

The bare minimum virtual TStream methods that you need to override are:

function Read(var Buffer; Count: Longint): Longint; overload; virtual;
function Write(const Buffer; Count: Longint): Longint; overload; virtual;
function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; overload; virtual;

If you want to support the assigning to the Size property you need to override:

procedure SetSize(NewSize: Longint); overload; virtual;
procedure SetSize(const NewSize: Int64); overload; virtual;

The implementation of the 32 bit SetSize must call the 64 bit SetSize. And the 64 bit SetSize does the work.

If you don't override these methods then assigning to the stream's Size property will silently do nothing.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top