Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ReturnAddressUnit to provide ReturnAddress to Delphi versions not supporting it, and prevent CallerAddr warnings for Delphi versions having ReturnAddress. See https://bitbucket.org/jeroenp/wiert.me/src/8ae6cf29ffc601fde7c1182dead740adddb13fb8/Native/Delphi/Library/RTL/ReturnAddressUnit.pas
unit ReturnAddressUnit;
// maps CallerAdddr to ReturnAddress to CallerAddr when not available (XE2 and higher have ReturnAddress)
// this avoids "W1000 Symbol 'CallerAddr' is deprecated: 'Use ReturnAddress'"
// from https://github.com/fabriciocolombo/dunit-extension/blob/master/src/TestCaseExtension.pas
interface
{$IFDEF CONDITIONALEXPRESSIONS}
{$IF (NOT DEFINED(CLR)) AND (CompilerVersion >= 23.0) }
{$DEFINE HAS_BUILTIN_RETURNADDRESS} // Requires ReturnAddress intrinsic function(Delphi XE2)
{$ENDIF}
{$ENDIF}
{$IFNDEF HAS_BUILTIN_RETURNADDRESS}
type
TReturnAddressFunc = function : Pointer;
var
ReturnAddress: TReturnAddressFunc = CallerAddr;
{$ENDIF}
implementation
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment