CodeTools detection using macros lazarus / 9-Editor ---------------------------------------------------------------------- H₂SO₄ · 2025-10-07 06:54 CodeTools works great for the most part, but some annoying bugs still show up from time to time. Since upgrading to Lazarus trunk isn't always an option, I wanted to ask: Does CodeTools define any special macros? For example, in Lazarus 4.0 CodeTools breaks if the first function in the  implementation  section is generic. Currently I'm using this workaround: 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 implementation {$ifopt D+} procedure __CodeTools_Jump_Fix(); begin end; {$endif} generic procedure Foo(): T; {...} It would be great if I could enclose problematic code in something like  {$ifdef CODETOOLS}  (at least until the underlying issue is fixed & upgrading becomes possible), but  Source → Unit information... → Show CodeTools Values  doesn't show anything interesting, so I'm not very optimistic. ---------------------------------------------------------------------- Thaddy · 2025-10-07 07:16 I had an idea but removed it. ---------------------------------------------------------------------- cdbc · 2025-10-07 07:25 Hi I've worked around like this: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 {-$define coding}{$ifNdef coding}  { TBucketFactory }  TBucketFactory = object         { creates and returns an IBucketListxxx depending on the provided type 1..5      0,1: Data | 2: String | 3: TObject | 4: IInterface | 5: ICorba }    function FetchBucketList(aBucketType: word;                             aFreeProc: TDisposeProc = nil;                             out anIBucketList): boolean;    { e.g.: bls:= BucketFactory.specialize GetBucketList(nil,BucketCompareKey,100); }    generic function GetBucketList(aFreeProc: TDisposeProc = nil): T;  end;  { factory object that creates an instance of the 5 available BucketLists }  var BucketFactory: TBucketFactory;{$endif}  ...implementation{$ifNdef coding}{ TBucketFactory }generic function TBucketFactory.GetBucketList(aFreeProc: TDisposeProc = nil): T;var ti: PTypeInfo;begin  ti:= TypeInfo(T);  case IndexStr(ti^.Name,['IBuck etListBase','IBucketListData','IBucketListStr','IBucketListObj','IBuck etListIntf','IBucketListCorba']) of    0,1: pointer(Result):= CreBucketListData(aFreeProc); { we don't do base!!! }    2: pointer(Result):= CreBucketListStr;    3: pointer(Result):= CreBucketListObj;    4: pointer(Result):= CreBucketListIntf;    5: pointer(Result):= CreBucketListCorba;  end;end; function TBucketFactory.FetchBucketList(aBucketType: word;                                      aFreeProc: TDisposeProc = nil;                                      out anIBucketList): boolean;begin  pointer(anIBucketList):= nil; { init }  if (aBucketType > 5) then exit(false);  case aBucketType of    0,1: pointer(anIBucketList):= CreBucketListData(aFreeProc); { we don't do base!!! }    2: pointer(anIBucketList):= CreBucketListStr;    3: pointer(anIBucketList):= CreBucketListObj;    4: pointer(anIBucketList):= CreBucketListIntf;    5: pointer(anIBucketList):= CreBucketListCorba;  end;  Result:= (pointer(anIBucketList) <> nil);end;{$endif} I just enable the define when I'm working on it and disable the define if I need it when compiling... Regards Benny ---------------------------------------------------------------------- Thaddy · 2025-10-07 15:03 Very intricate way to avoid assert Benny? ---------------------------------------------------------------------- cdbc · 2025-10-07 15:09 Hi Nah, /intricate/ I dunno, but for me it works very stable... Regards Benny ---------------------------------------------------------------------- H₂SO₄ · 2025-10-08 05:28 I found that  DEBUGINFO  (yes, as a preprocessor symbol/macro, not  {$debuginfo})  is only defined when editing (in debug mode of course), but not when compiling. Unreliable, but good enough for now ---------------------------------------------------------------------- PascalDragon · 2025-10-09 19:59 You can use this trick that I used for the Rtti unit before Lazarus was capable of handling generic methods: 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 { Note: since the Lazarus IDE is not yet capable of correctly handling generic  functions it is best to define a InLazIDE define inside the IDE that disables  the generic code for CodeTools. To do this do this:   - go to Tools -> Codetools Defines Editor  - go to Edit -> Insert Node Below -> Define Recurse  - enter the following values:    Name: InLazIDE      Description: Define InLazIDE everywhere      Variable: InLazIDE      Value from text: 1}{$ifdef InLazIDE}{$define NoGenericMethods}{$endif} ---------------------------------------------------------------------- Martin_fr · 2025-10-12 11:05 Quote from: Khrys on October 07, 2025, 08:54:12 amFor example, in Lazarus 4.0 CodeTools breaks if the first function in the  implementation  section is generic. Currently I'm using this workaround: 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 implementation {$ifopt D+} procedure __CodeTools_Jump_Fix(); begin end; {$endif} generic procedure Foo(): T; {...} I can not get Codetool to fail on the above example (in 4.3 (fixes branch). Well, as soon as I replace "procedure" with "function" because the former does not have a result type. ---------------------------------------------------------------------- H₂SO₄ · 2025-10-13 04:56 Quote from: Martin_fr on October 12, 2025, 01:05:28 pmWell, as soon as I replace "procedure" with "function" because the former does not have a result type. Yes, it should be a function. I just needed a quick example for my post and didn't check whether that specific issue might've already been fixed in trunk.