Lazarus

Free Pascal => Beginners => Topic started by: guest64953 on December 07, 2019, 03:09:11 am

Title: Which unit should I use?
Post by: guest64953 on December 07, 2019, 03:09:11 am
I want a unit provide List data structure and to some extent, Map too. There are so many of units provide these data structure, e.g: FCL, Generics.Collection, FGL... Which unit should I use?  :)
Title: Re: Which unit should I use?
Post by: jamie on December 07, 2019, 03:21:31 am
You are in luck, there just happens to be a unit calls MAPS !

 Last time I looked at it, it looked like it could need some clean up but its used deep in the heart of a lot of code I guess.
 
Title: Re: Which unit should I use?
Post by: dsiders on December 07, 2019, 04:20:51 am
You are in luck, there just happens to be a unit calls MAPS !

 Last time I looked at it, it looked like it could need some clean up but its used deep in the heart of a lot of code I guess.

Are you trolling me?  >:(

locate maps.pp

Who's trolling who?
Title: Re: Which unit should I use?
Post by: guest64953 on December 07, 2019, 04:24:31 am
You are in luck, there just happens to be a unit calls MAPS !

 Last time I looked at it, it looked like it could need some clean up but its used deep in the heart of a lot of code I guess.

Are you trolling me?  >:(

locate maps.pp

Who's trolling who?

The maps.pp of LazUtils? Sorry, he wrote in uppercase and didn't point me to where the unit is so I think it must be troll  :-[

p/s: He should provide at lease one link like this https://lazarus-ccr.sourceforge.io/docs/lazutils/maps/tmap.html (https://lazarus-ccr.sourceforge.io/docs/lazutils/maps/tmap.html). Anyway, it's my fault. Sorry everyone  :(
Title: Re: Which unit should I use?
Post by: guest64953 on December 07, 2019, 04:34:52 am
You are in luck, there just happens to be a unit calls MAPS !

 Last time I looked at it, it looked like it could need some clean up but its used deep in the heart of a lot of code I guess.

Sorry for misunderstand your post  :( About List, which unit should be used? Thanks  :)
Title: Re: Which unit should I use?
Post by: jamie on December 07, 2019, 10:55:18 pm
it depends on the type of data you are manipulating.

Also, are you looking for viewing options of this data, too ?
Title: Re: Which unit should I use?
Post by: PascalDragon on December 08, 2019, 11:48:49 am
Sorry for misunderstand your post  :( About List, which unit should be used? Thanks  :)
In general you should go with Generics.Collections nowadays. Due to them being generics they allow for typesafe containers and thus less programmer errors due to incorrect casts that can happen with Classes.TList for example. They also don't require you to implement special operators for comparison as the FGL ones require.

FGL should be used if you want typesafe containers on the one hand, but are also constrained to small code sizes (e.g. for embedded platforms).

The containers in Classes are mainly useful if you want to store multiple different types of objects (e.g. TObjectList if you'll store a TStringList and a TComponent in the same list, cause using TObjectList<TObject> from Generics.Collections is a bit of an overkill...)
Title: Re: Which unit should I use?
Post by: guest64953 on December 09, 2019, 03:46:15 pm
Sorry for misunderstand your post  :( About List, which unit should be used? Thanks  :)
In general you should go with Generics.Collections nowadays. Due to them being generics they allow for typesafe containers and thus less programmer errors due to incorrect casts that can happen with Classes.TList for example. They also don't require you to implement special operators for comparison as the FGL ones require.

FGL should be used if you want typesafe containers on the one hand, but are also constrained to small code sizes (e.g. for embedded platforms).

The containers in Classes are mainly useful if you want to store multiple different types of objects (e.g. TObjectList if you'll store a TStringList and a TComponent in the same list, cause using TObjectList<TObject> from Generics.Collections is a bit of an overkill...)

How to install Generics.Collections? Is it shipped with Lazarus by default?  :)
Title: Re: Which unit should I use?
Post by: guest64953 on December 09, 2019, 03:50:11 pm
it depends on the type of data you are manipulating.

Also, are you looking for viewing options of this data, too ?

I just want something similar to Java ArrayList or C++ vector. Indeed, I want an dynamic array without having to setlength and this array just grow up when more data is added. The data itself, currently, just simple integer or double  :)
Title: Re: Which unit should I use?
Post by: Handoko on December 09, 2019, 04:12:43 pm
How to install Generics.Collections? Is it shipped with Lazarus by default?  :)

As far as I know Generics already included in recent versions of Free Pascal. Read more:
https://wiki.freepascal.org/Generics
Title: Re: Which unit should I use?
Post by: PascalDragon on December 10, 2019, 09:33:19 am
How to install Generics.Collections? Is it shipped with Lazarus by default?  :)
With FPC 3.2 it's part of the packages provided by FPC. For older versions I think Lazarus provides an implementation.

How to install Generics.Collections? Is it shipped with Lazarus by default?  :)

As far as I know Generics already included in recent versions of Free Pascal. Read more:
https://wiki.freepascal.org/Generics
We're not talking about generics in general, but a specific class library that utilizes generics.
TinyPortal © 2005-2018