> On Jan 8, 2017, at 2:37 AM, Andrew Hall <andrew.h...@shaw.ca> wrote: > > If you cast your “something” to a typed pointer, the compiler will do the > work for you in the usual way: > > PDouble(something)^ := myDouble; > PAnsiString(something)^ := myAnsiString; > myRecordStructure := PMyRecordStructure(something)^;
I’m not getting any of this to work. Here is the pattern I was attempting. It’s a “release existing, retain and assign new” function which handles nil inputs safely. I thought I could use untyped params so I don’t need to typecast “io” to TObject when I call RetainObject every time. procedure RetainObject (var io; newObject: TObject); var obj: TObject absolute io; begin if obj <> nil then obj.Release; if newObject <> nil then begin obj := newObject; obj.Retain; end else obj := nil; TObjectPtr(io)^ := obj; // crashes here end; var foo: TMyObject; something: TMyObject; foo := TMyObject.Create; RetainObject(something, foo); Regards, Ryan Joseph _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal