Recent

Author Topic: Strange happenings with TLIST holding initiated Generic classes.  (Read 938 times)

jamie

  • Hero Member
  • *****
  • Posts: 7711
First a bit of code

Code: Pascal  [Select][+][-]
  1. constructor TCDocManager.Create;
  2. begin
  3.   pStaticList := Nil;
  4.   m_templateList := TList.Create;
  5.   m_templateList.Clear;//<< Must do this?
  6. end;                                      
  7.  

I had an issue where a Generic instance of a class was being returned and thus with that, I was calling a method of that class, however, the method for whatever reason was not getting called and the Debugger would flag it as a GREEEN, meaning it was never called or linked etc.

I am in the middle of porting some old MFC code so some may notice things, for example, that is part of the CDocMrg and the m_templatelist holds the numerous (Generics) that were created.

 I corrected the issue by merely calling the CLEAR of the list at construction time so this tells me there could be garbage not cleared out when created?

 The returned Generic instance came from that list via a function.

 Shouldn't TLIST=Class(TFPList) be clearing the garbage when created?

Jamie

The only true wisdom is knowing you know nothing

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12865
  • FPC developer.
Re: Strange happenings with TLIST holding initiated Generic classes.
« Reply #1 on: April 12, 2026, 06:41:55 pm »
Please post a fully compileable example showing your potential problem.

jamie

  • Hero Member
  • *****
  • Posts: 7711
Re: Strange happenings with TLIST holding initiated Generic classes.
« Reply #2 on: April 12, 2026, 06:53:51 pm »
 The project is quite large so that may not be an easy thing to do but I can tell you also that when I scan the list without doing first the clear and adding some, there appears to be some already in the count, because when I use ADD method, I only add 1, but in a query loop it randomly may return 2,3 or more items that does not live there.

 This is from Fpc 3.2.2 if that makes any difference.

 I generically don't use a TLIST but go more for the Generics but in this case I found it easier to manage.

 I'll see if I can do something as an example.

Jamie


The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12345
  • Debugger - SynEdit - and more
    • wiki
Re: Strange happenings with TLIST holding initiated Generic classes.
« Reply #3 on: April 12, 2026, 07:56:33 pm »
however, the method for whatever reason was not getting called and the Debugger would flag it as a GREEEN, meaning it was never called or linked etc.

(Not sure which "green" you mean, but probably one that applies to "no code found")


But, be aware, IIRC FPC still sometimes writes wrong line info for specialized generics. => It will pretend that the source lines are in the unit that did the "specialize", but they are not.
In that case the debugger also can't find them.

jamie

  • Hero Member
  • *****
  • Posts: 7711
Re: Strange happenings with TLIST holding initiated Generic classes.
« Reply #4 on: April 12, 2026, 09:01:56 pm »
The GREEN debug line is when there are no links or references to the code, these are Virtual methods give this and it seems only when I get ready to RUN is when I see this.

  I have seen this if I forgot to override an ancestor method also, so it seems the mystery is around virtual methods.

 As for the debugger not playing well with Generics, that little bit I can work around. I've found that when making changes to the generics (templates) a BUILD of the app is in order to get things going again.

 Also, while we are GENERICS, I've noticed I cannot Type set a parameter in a ancestor class but I can type set the results (output) of that class.

The CDocTemplate is a complete abstract class and with the inherited class, which is a Generics (Template) I set the types for the virtual override rides but I can only do that with the Result types, not the input parameters, for some reason It does not work but works if the method was created in the Generics class.
   Maybe this has been fixed in the trunk.

 Btw,
   Any way to pass a constant as a TYPE to a generic Type info?

Jamie


 

The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12345
  • Debugger - SynEdit - and more
    • wiki
Re: Strange happenings with TLIST holding initiated Generic classes.
« Reply #5 on: April 12, 2026, 09:23:02 pm »
The GREEN debug line is when there are no links or references to the code, these are Virtual methods give this and it seems only when I get ready to RUN is when I see this.
Ah, dark/olive green, rather than lighter disabled break green. (also line, rather than icon)

Quote
As for the debugger not playing well with Generics, that little bit I can work around. I've found that when making changes to the generics (templates) a BUILD of the app is in order to get things going again.
Depends on many factors...
Line info goes wrong, but not too often (at least 3.2.3 and up).

Quote
Also, while we are GENERICS, I've noticed I cannot Type set a parameter in a ancestor class but I can type set the results (output) of that class.
not sure what you mean?

Quote
The CDocTemplate is a complete abstract class and with the inherited class, which is a Generics (Template) I set the types for the virtual override rides but I can only do that with the Result types, not the input parameters, for some reason It does not work but works if the method was created in the Generics class.
   Maybe this has been fixed in the trunk.
You mean the "override" function has a diff return type (a more precise class). IIRC results only, but not sure.

You can of course pass types into the generic, and have the correct types there to begin with... Not sure if that works for your case.

Quote
Btw,
   Any way to pass a constant as a TYPE to a generic Type info?

Yes.

Not sure from which version (may be 331)
  generic Foo<const a: integer>

But you can always pass a record  (advanced) or class => and they can have constants embedded.

And you can also use that to pass templates for records/objects. (though you may need 2 units for that)

LazListClasses is doing a lot of that

jamie

  • Hero Member
  • *****
  • Posts: 7711
Re: Strange happenings with TLIST holding initiated Generic classes.
« Reply #6 on: April 12, 2026, 09:29:17 pm »
Ok, I'll look into it; Thanks.

Jamie
The only true wisdom is knowing you know nothing

mas steindorff

  • Hero Member
  • *****
  • Posts: 586
Re: Strange happenings with TLIST holding initiated Generic classes.
« Reply #7 on: April 13, 2026, 03:58:33 am »
not sure if it will help but I to was having issues with generic Tlist until I changed over to TFPGList.  this has worked for me in several Window programs without anything special in the code (other than  specialize TFPGList(xx)) in my type area.
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

jamie

  • Hero Member
  • *****
  • Posts: 7711
Re: Strange happenings with TLIST holding initiated Generic classes.
« Reply #8 on: April 13, 2026, 12:41:42 pm »
I am glad I am not the only one who has found that.

Jamie
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018