I recently wrote a function to obtain the CLR Framework path. But then, I realized a few things:
  1. It's inefficient.
  2. The name of the Common Object Runtime Library (CORLib) is hardcoded in the function.
I realized there could be a better way to write it, and came up with the following function.

The function below is much much faster, doesn't require enumerating all the assemblies loaded in the current domain. It does assume that the System.Object is located in the CORLib.

function FrameworkPath: string; inline;
var
  LObject: System.Object;
begin
  LObject := System.Object.Create;
  Result := Path.GetDirectoryName(LObject.GetType.Assembly.Location);
end;

The inline directive is a new Delphi 2005 directive, telling the Delphi compiler to output the IL code in this function directly at the location where the function is called.