Recent

Author Topic: My first Generic Type...  (Read 3258 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: My first Generic Type...
« Reply #15 on: March 08, 2024, 09:00:42 pm »
for fpc mode you used Generics.Collections instead of fgl as I did, may I know what the difference is?
The difference is mainly that generics.collections is compatible with Delphi, but fgl is much older and stable. Those are libraries and there are many more, like std-fcl, which mimics the C library of the same name and lgenerics, which is also very good, probably the best regarding theory. The last one you currently need to install.
For now I would stick with FGL. It is very powerful and very stable.
The others I mentioned are even more powerful, but less suited to start with in your case.
You can always ask questions here.
« Last Edit: March 08, 2024, 09:05:38 pm by Thaddy »
But I am sure they don't want the Trumps back...

r.lukasiak

  • Full Member
  • ***
  • Posts: 167
Re: My first Generic Type...
« Reply #16 on: March 13, 2024, 05:57:21 am »
Quote
The difference is mainly that generics.collections is compatible with Delphi, but fgl is much older and stable. Those are libraries and there are many more, like std-fcl, which mimics the C library of the same name and lgenerics, which is also very good, probably the best regarding theory. The last one you currently need to install.
For now I would stick with FGL. It is very powerful and very stable.
The others I mentioned are even more powerful, but less suited to start with in your case.
You can always ask questions here.
Ohh,  get it. I think I just came across some link providing info about it https://wiki.freepascal.org/Data_Structures,_Containers,_Collections.
As you say, I'll stick with FGL for now, that's what I learnt from posts on this forum.

Quote
Also note this is a rather strict class. If you want the itemlist to contain different wincontrol descendents at the same time, you should bring the type declaration for Titemlist outside of the class, because the above class restricts the list to only one type of wincontrol, like a button. If you want the class to work with e.g. Tedit, Tmemo and Tbutton  at the same time, the Titemlist should be outside of the class and delared as: type Ttemlist  = Tlist<Twincontrol>;.
this could be an interesting feature but I'm not sure how I should apply the given code to mine. :-[

Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: My first Generic Type...
« Reply #17 on: March 13, 2024, 08:19:39 am »
Specializing from TWincontrol gives you the mouse events you were struggling with. That is the reason I put a constraint on T that it must be at least a TWincontrol derived control.
« Last Edit: March 13, 2024, 08:44:00 am by Thaddy »
But I am sure they don't want the Trumps back...

r.lukasiak

  • Full Member
  • ***
  • Posts: 167
Re: My first Generic Type...
« Reply #18 on: May 12, 2024, 06:26:10 am »
@Thaddy I'm ashamed to notice I missed your last answer...  :-[

Specializing from TWincontrol gives you the mouse events you were struggling with. That is the reason I put a constraint on T that it must be at least a TWincontrol derived control.
What I was asking is how I can change my generic class to work with different Wincontrol descendents at the same time. As you pointed out previously, this class in its current state is restricted to just one type of Wincontrol descendent.

Quote
Also note this is a rather strict class. If you want the itemlist to contain different wincontrol descendents at the same time, you should bring the type declaration for Titemlist outside of the class, because the above class restricts the list to only one type of wincontrol, like a button. If you want the class to work with e.g. Tedit, Tmemo and Tbutton  at the same time, the Titemlist should be outside of the class and delared as: type Ttemlist  = Tlist<Twincontrol>;.

Thanks in advance and once again I'm sorry for overlooking your last answer.


Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: My first Generic Type...
« Reply #19 on: May 12, 2024, 07:00:19 am »
In such a case you would be better off with a type helper for TWinControl instead of a generic implementation.. The type helper is then available to any TWinControl.
But I am sure they don't want the Trumps back...

r.lukasiak

  • Full Member
  • ***
  • Posts: 167
Re: My first Generic Type...
« Reply #20 on: May 12, 2024, 07:05:44 am »
ohh I see.... I've never touched helpers but they are on my to-learn list so I take a look these days.
thanks!

 

TinyPortal © 2005-2018