HeapTrace Detection ?? lazarus / 21-General ---------------------------------------------------------------------- Josh · 2023-11-20 13:43 Hi I stumbled across an issue wher an old app is thinking heaptrace is active, so i done some test. creating new project, placing a button on it, then in onclick i have Code: [Select]{$if declared(UseHeapTrace)}   if UseHeapTrace then ShowMessage('Heaptrc is active')   else showmessage('Heaptrc is used.');   {$else}   ShowMessage('No trace of Heaptrc.');   {$endIf}  if i create debug / release builds, debug mode has heaptrace turned on. no matter which build mode i use, none are reporting heaptrace is active when i click button. yet on one of my projects set to release, no heaptrace turned on in proj options and no-gh switch, it reports it active. am i doing something stupid here... currently on painkillers, so is very possible its a stupid me error. Lazarus 2.2.7 (rev ada7a90f86) FPC 3.2.3 i386-win32-win32/win64 ---------------------------------------------------------------------- MarkMLl · 2023-11-20 16:13 In principle, I believe that declared() can also take a unit name as parameter: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$macro on }uses//                              LogicAnalyzer; {$define ANALYZER__:= LogicAnalyzer }//                              LogicAnalyzer_Dynamic; {$define ANALYZER__:= LogicAnalyzer }                              Analyzer_VcdCode; {$define ANALYZER__:= Analyzer_VcdCode } {$if declared(LogicAnalyzer_Dynamic)    }var  logicAnalyzer: TLogicAnalyzer= nil;{$endif                               }  However yesterday, with v3.2.2, I started to find that erratic in a way I could not characterise which is why I added that macro with the uses statement rather than putting it in a slightly later conditional. But that variable declaration works as expected... Edited to add: xref to https://forum.lazarus.freepascal.org/index.php/topic,65320.0.html MarkMLl ---------------------------------------------------------------------- cpicanco · 2023-11-21 01:22 I am using this to check heaptrace (when -gh option is checked) and dump it to a file: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if FileExists('heaptrc.txt') then begin    DeleteFile('heaptrc.txt');  end;  {$IF Declared(heaptrc)}  SetHeapTraceOutput('heaptrc.txt');  {$ENDIF} ---------------------------------------------------------------------- Thaddy · 2023-11-21 13:29 It is also explained in the wiki years ago. I wrote that entry. https://wiki.freepascal.org/heaptrc Btw it was editted by someone else, who may have damaged the full information... I checked just now and the information about detection is still OK. Florian himself helped me with advice. Any other edits will be reverted. ---------------------------------------------------------------------- Josh · 2023-11-21 14:01 Hi Excuse still on strong painkillers. What i was saying is currently on my test its not reliable. as explained in my first post, in various build modes, including debug where i have -gh set its does not think heaptrc is active. and on one of my old projects it thinks it is active even when build mode is set to release and no -gh switch is set. It only showed up recently and is not fixed in stone, which makes it hard to pin down. further tests it appears more likely to go awry if i do a clean and build in debug mode then it says its active, if i then set to release and run, now and again it willstill think heaptrc is set, i cant catagorically say this is this case but it seems more likely to happen. ie the old project that was set to release but said heaptrc was active, i done a clean deleteall and rebuild (releae mode) then it was fine. i noticed it when i compiled old project and moved to its run location and it failed with file not found and the file was a debug file that was written to in various location but only if heaptrc was active, in  a sub folder of the exe folder, which only exists in develop environment location. what i am concerned about is if it is to do a clean build being done with debug mode, then a release build 'failing' this will have an impact on my compile and build many, as will have to do clean and delete all before running it. Like i said I need to do more tests, to pin point; but my head is a bit fuzzy and euphoric with the meds.