Hi it's because you free the aPNG Variable. You assign aPNG as reference to Result . It's not a copy. So when your free aPNG result also become nil
Use Result.Assign(aPNG) instead.
But why using intermediate variable ? just use result.
Sorry for my english.
function TForm1.GetRes(aRESOURCE : string) : TPortableNetworkGraphic;
var
ResStream : TResourceStream;
begin
Result := TPortableNetworkGraphic.Create;
ResStream := TResourceStream.Create(HINSTANCE, aRESOURCE, RT_RCDATA);
try
Result.LoadFromStream(ResStream);
finally
ResStream.Free;
end;
end;
Best regards