Recent

Author Topic: [Workaround]Generic function is 'wreaking havoc' on my codetools, why?  (Read 666 times)

cdbc

  • Hero Member
  • *****
  • Posts: 1967
    • http://www.cdbc.dk
Hi
As the title says, this little function screws up my codetools:
Code: Pascal  [Select][+][-]
  1. {$ifdef usegen}
  2. { this generic factory is mainly for assigning services to properties }
  3. generic function  FetchSvc<T>(const aName: string = ''): T;
  4. { this generic factory is mainly for assigning services to properties }
  5. generic function  FetchSvcParams<T>(const Args: array of const;const aName: string = ''): T;
  6. {$endif}
Attached is a screenshot, showing what it's whining about...
For now, I've wrapped the functions in "ifdef"s, so that I can at least get my coding done, then by compile time I flip the switch...
It's a wee bit annoying...
Regards Benny
« Last Edit: February 25, 2025, 03:07:41 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

cdbc

  • Hero Member
  • *****
  • Posts: 1967
    • http://www.cdbc.dk
Re: Generic function is 'wreaking havoc' on my codetools, why?
« Reply #1 on: February 13, 2025, 12:22:15 pm »
Hi
Btw., I'm running Fpc-trunk / Lazarus-trunk, so it cannot be, because it's too old?!?
That said, my stable installation Fpc-3.2.2 / Lazarus-3.6, is exhibiting the exact same symptoms...  %)
I mean, if I use 'generics.collections' or fgl, these *Shenanigans* don't happen...

What the H*LL am I doing wrong...?!?
Any help will be deeply appreciated /\
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

cdbc

  • Hero Member
  • *****
  • Posts: 1967
    • http://www.cdbc.dk
Re: Generic function is 'wreaking havoc' on my codetools, why?
« Reply #2 on: February 14, 2025, 05:05:09 pm »
Hi again
Hmmm, could it be, that I forgot some compiler switches?!?
Grasping at straws here...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10921
  • Debugger - SynEdit - and more
    • wiki
Re: Generic function is 'wreaking havoc' on my codetools, why?
« Reply #3 on: February 14, 2025, 05:14:59 pm »
It is possible that Codetool just hasn't had those updates yet. Or at least that they are not bug free.

IIRC, if you search the bug tracker, there are a few open entries for code-completion and generics.

cdbc

  • Hero Member
  • *****
  • Posts: 1967
    • http://www.cdbc.dk
Re: Generic function is 'wreaking havoc' on my codetools, why?
« Reply #4 on: February 14, 2025, 06:06:30 pm »
Hi Martin
Thanks mate. I'll have a sniff in the bugtracker...
I mean, compared to 'fgl' & 'Generics.Collections', my 2 small functions pale in comparison - small potatoes  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10921
  • Debugger - SynEdit - and more
    • wiki
Re: Generic function is 'wreaking havoc' on my codetools, why?
« Reply #5 on: February 14, 2025, 06:24:42 pm »
Just to say, but if I open generics collection, go into a method body, and try to jump to a field => not working.

cdbc

  • Hero Member
  • *****
  • Posts: 1967
    • http://www.cdbc.dk
Re: Generic function is 'wreaking havoc' on my codetools, why?
« Reply #6 on: February 14, 2025, 06:54:15 pm »
Hi
I hear you and have experienced the same myself, come to think about it  ;)
Saw the issues in the bugtracker, up to 4 years old, I'm quite sure this is a difficult topic, but it also seems, that @Juha is fiddling with it... I don't envy him... Even when I create complex manual interfaces, the codetools play nice.
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

cdbc

  • Hero Member
  • *****
  • Posts: 1967
    • http://www.cdbc.dk
Re: Generic function is 'wreaking havoc' on my codetools, why?
« Reply #7 on: February 25, 2025, 09:40:46 am »
Hi
A small update, after fiddling with generics and codetools, I came up with the following, that oddly enough, the codetools will /eat/ without 'squeling like pigs', go figure:
Code: Pascal  [Select][+][-]
  1. unit bc.plugingenerics;
  2. {$mode ObjFPC}{$H+}
  3. {$modeswitch autoderef on}
  4. {-$define dbg}
  5. interface
  6. uses classes, sysutils;
  7. type
  8.   PFactoryGen = ^TFactoryGen;
  9.  
  10.   { TFactoryGen }
  11.   TFactoryGen = object
  12.     generic function GetSvc<T>(const aName: string = ''): T;
  13.     generic function GetSvcParams<T>(const Args: array of const;const aName: string = ''): T;
  14.   end;
  15.  
  16. function ObjFactory: PFactoryGen;
  17.  
  18. implementation
  19. uses TypInfo, bc_pluginmanager;
  20.  
  21. var Singleton: TFactoryGen;
  22.  
  23. function ObjFactory: PFactoryGen;
  24. begin
  25.   Result:= @Singleton; { pointer => less copying }
  26. end;
  27.  
  28. { TFactoryGen }
  29. generic function TFactoryGen.GetSvc<T>(const aName: string = ''): T;
  30. var ti: PTypeInfo;
  31. begin { we check if said plugin-service exist in repo, before returning it, else nil }
  32.   ti:= TypeInfo(T);
  33.   if aName = '' then begin { empty means we want the /default/ svc of this type }
  34.     if PluginMgr.QueryPliServiceDefault(ti.Name) then
  35.       pointer(Result):= PluginMgr.GetPliSvcDefaultWeak(ti.Name)
  36.     else Result:= T(nil);
  37.   end else begin { ok, we have to try and fetch the named svc of this type }
  38.     if PluginMgr.QueryPliService(ti.Name,aName) then
  39.       pointer(Result):= PluginMgr.GetPliSvcWeak(ti.Name,aName)
  40.     else Result:= T(nil);
  41.   end;
  42. end; { GetSvc<T> }
  43.  
  44. generic function TFactoryGen.GetSvcParams<T>(const Args: array of const;const aName: string = ''): T;
  45. var ti: PTypeInfo;
  46. begin  { we check if said plugin-service exist in repo, before returning it, else nil }
  47.   ti:= TypeInfo(T);
  48.   if aName = '' then begin { empty means we want the /default/ svc of this type }
  49.     if PluginMgr.QueryPliServiceDefault(ti.Name) then
  50.       pointer(Result):= PluginMgr.GetPliSvcDefaultWeakParams(ti.Name,Args)
  51.     else Result:= T(nil);
  52.   end else begin { ok, we have to try and fetch the named svc of this type }
  53.     if PluginMgr.QueryPliService(ti.Name,aName) then
  54.       pointer(Result):= PluginMgr.GetPliSvcWeakParams(ti.Name,aName,Args)
  55.     else Result:= T(nil);
  56.   end;
  57. end; { GetSvcParams<T> }
  58.  
  59. end.

...And it works like a charm, preserving refcounts and all...  8-)
Well, learnt a lot of new stuff, this time 'round.
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

 

TinyPortal © 2005-2018