How can I detect from code when FastMM4 is used

Viewed 183

I want to show a label on a form when FastMM4 is being used ('Uses' in the project file), so that I don't make the mistake of giving the executable to someone who doesn't have FastMM_FullDebugMode.dll installed.

I tried these, but they have are no effect:

{$ifdef FullDebugMode}
LblFastMM4.Visible := true;
{$endif}

{$ifdef EnableMemoryLeakReporting}
LblFastMM4.Visible := true;
{$endif}

How can I detect FastMM4 at runtime?

Note: I don't 'officially' distribute the app with FastMM4. This is just a reminder to myself when I want to give the alpha version to a non-technical user for a quick look. It's annoying if they then bump into the error.

3 Answers

Your {$ifdef}'s don't work because your own code is not including FastMM4Options.inc directly, so FastMM's conditionals are not defined in scope of your code. They are only defined in scope of FastMM's code. You can't test for conditionals that are {$define}'d in someone else's unit.

However, you can use {$If Declared(...)} to check for public symbols that are in scope from using another unit. In this case, the interface section of FastMM4.pas declares various symbols under certain conditions, for instance TRegisteredMemoryLeak when EnableMemoryLeakReporting is defined, DebugGetMem when FullDebugMode is defined, etc.

{$if declared(DebugGetMem)}
LblFastMM4.Visible := true;
{$endif}

{$if declared(TRegisteredMemoryLeak)}
LblFastMM4.Visible := true;
{$endif}

try this: LblFastMM4.Visible := InitializationCodeHasRun;

Related