Caution! This is an unpleasant hack and may fail when the internal structure of the field of the hacked class changes.
type TJPEGDataHack = class(TSharedImage) FData: TCustomMemoryStream; // must be at the same relative location as in TJPEGData! end; // TJPEGDataHelper function TJPEGDataHelper.Data: TCustomMemoryStream; begin Result := TJPEGDataHack(self).FData; end;
This will only work if the parent class of the hack class matches the parent class of the source class. So, in this case, TJPEGData is inherited from TSharedImage, as well as a hack class. The positions should also match, so if there was a field in the list before FData, then the equivalent field should be in the "hack" class, even if it is not used.
A full description of how this works can be found here:
Hack # 5: access to private fields
Uwe raabe
source share