2

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.

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
  • "*so that I don't make the mistake of giving the executable to someone who doesn't have FastMM_FullDebugMode.dll installed*" - why would you not simply deploy the DLL with your app? It is not the user's responsibility to install the DLL. It is your app, it is your responsibility to deploy and install whatever dependancies it needs. – Remy Lebeau May 31 '21 at 07:32
  • again, why wouldn't you simply deploy the DLL with every alpha you give out? Not that hard. – Remy Lebeau May 31 '21 at 08:48
  • 2
    A lot of options can be configured for FastMM. In your case the option *DoNotInstallIfDLLMissing* can be of value. A nice application is available for setting options: http://jedqc.blogspot.com/2007/07/new-fastmm4-options-interface.html – Erwin May 31 '21 at 09:59
  • @Erwin I tested your suggestion and it works fine. Can you make it an answer so that I can upvote it – Jan Doggen Jun 17 '21 at 12:41
  • @Jan Doggen Good to hear! – Erwin Jun 17 '21 at 20:30

3 Answers3

3

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}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • After 40 years of programming there are still things to learn: I was not present to what you said in your first paragraph. Note however: These symbols are not known in my form unless I use FastMM4 there *also*. Which is sort of OK, I can disable two uses files instead of one. One would be nicer though ;-) – Jan Doggen May 31 '21 at 08:30
  • @JanDoggen did you read the documentation I linked to? If `FastMM4` is not in your Form's `uses` clause, or if it is not compiled with the particular conditionals you are interested in, then the `{if}`'s would simply evaluate as false – Remy Lebeau May 31 '21 at 08:51
1

A lot of options can be configured for FastMM. In your case the option DoNotInstallIfDLLMissing can be of value. A nice application is available for setting options: https://jedqc.blogspot.com/2007/07/new-fastmm4-options-interface.html

Erwin
  • 1,896
  • 1
  • 11
  • 17
  • This worked fine for me, so I'm marking it as the 'correct' answer. If I now accidentally give someone an executable with FastMM in it they don't get the missing DLL error – Jan Doggen Jun 18 '21 at 09:08
0

try this: LblFastMM4.Visible := InitializationCodeHasRun;