Re: [fpc-pascal] Procedural generics question

2020-08-24 Thread leledumbo via fpc-pascal
> I remember something like this in RTTI though but can't find it in your
docs yet for generics.

{$mode objfpc}

uses
  typinfo;

generic procedure Add;
begin
   if TypeInfo(T) = TypeInfo(Integer) then WriteLn('an integer');
   if TypeInfo(T) = TypeInfo(String) then WriteLn('a string');
end;

begin
  specialize Add;
  specialize Add;
end.



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Procedural generics question

2020-08-24 Thread Lars via fpc-pascal
Inside a generic procedure (no objects used just a procedure) is there a 
way to check which type the code is being used for such as:


generic procedure Add();
begin
  if type = integer then...

  if type = string then...
  begin
// specialized code for that type only
  end
end;

I remember something like this in RTTI though but can't find it in your 
docs yet for generics.


The current way might be to code up separate procedures for each type, 
but that's kind of defeating the purpose of generics since that would 
simply be an overloaded regular function.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How reliable are Hashlists in Contnrs

2020-08-24 Thread Lars via fpc-pascal

On 2020-08-24 14:01, nore...@z505.com wrote:

I've noticed some problem with another hashlist that after adding
about 2000 items to it, it starts to have problems.


BTW, sorry to be more clear I meant I used another hashlist unit, not 
the contnrs one but another open source public domain one


This one:

https://github.com/z505/delphi-hashlist

And had problems with it.

I will try out contnrs one to compare soon!
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Difference between Associative array and Hashlist?

2020-08-24 Thread Sven Barth via fpc-pascal

Am 24.08.2020 um 21:47 schrieb Lars via fpc-pascal:
Since FPC has no associative array I was thinking that the closest is 
TStringList with name/value pairs.


Then there is a hashlist in contnrs.

Maybe an associative array means you don't have to implement it using 
hashes in order for it to work?


If there is a need for one I might write one as the TStringList is a 
bit slow, but do they already exist elsewhere before undertaking it...


I suggest you to take a look at TDictionary<,> in Generics.Collections. 
You can find a comparison regarding performace of various hash list 
classes available with/for FPC here: 
http://www.benibela.de/fpc-map-benchmark_en.html


Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How reliable are Hashlists in Contnrs

2020-08-24 Thread Sven Barth via fpc-pascal

Am 24.08.2020 um 21:01 schrieb Lars via fpc-pascal:
I've noticed some problem with another hashlist that after adding 
about 2000 items to it, it starts to have problems. There are 
duplicates added (possibly a collision?)


Is there a such thing as a perfect hashlist which never has a 
collision, or will they always have problems... In that case a regular 
but slower List might be of use for perfection.


If there is an error would it throw an exception?


Hash lists will always create collisions if enough elements are added. 
After all their purpose is to speed up the search thus they reduce the 
search space. This is by design.


If there should really be a problem with adding an element then an 
exception will be thrown.


Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How reliable are Hashlists in Contnrs

2020-08-24 Thread Bart via fpc-pascal
On Mon, Aug 24, 2020 at 9:25 PM Lars via fpc-pascal
 wrote:

> Is there a such thing as a perfect hashlist which never has a collision,

No, there are infinite possible items you can add to a haslist, but
only a finite number of available hashes.
It's the pigeon hole principle:
https://en.wikipedia.org/wiki/Pigeonhole_principle

-- 
Bart
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Difference between Associative array and Hashlist?

2020-08-24 Thread Lars via fpc-pascal
Since FPC has no associative array I was thinking that the closest is 
TStringList with name/value pairs.


Then there is a hashlist in contnrs.

Maybe an associative array means you don't have to implement it using 
hashes in order for it to work?


If there is a need for one I might write one as the TStringList is a bit 
slow, but do they already exist elsewhere before undertaking it...

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] How reliable are Hashlists in Contnrs

2020-08-24 Thread Lars via fpc-pascal
I've noticed some problem with another hashlist that after adding about 
2000 items to it, it starts to have problems. There are duplicates added 
(possibly a collision?)


Is there a such thing as a perfect hashlist which never has a collision, 
or will they always have problems... In that case a regular but slower 
List might be of use for perfection.


If there is an error would it throw an exception?


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Lazarus start problem after power outage on RPi4

2020-08-24 Thread Bo Berglund via fpc-pascal
On Mon, 24 Aug 2020 09:59:19 +0200, Mattias Gaertner via fpc-pascal
 wrote:

>> Can I copy this file from an RPi3B where I have installed the same
>> versions of Lazarus and Fpc in the same file locations (I use the same
>> install scripts on all RPi:s)?
>
>Yes.
>After start fix the paths in Tools / Options / Env. / Files to point to
>the right fpc.

Same paths, different RPi.
It worked fine so I can continue working where I left off.
Thanks.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Regression in 3.2.0 ??

2020-08-24 Thread Peter via fpc-pascal
Thanks to Sven & Michael for commenting.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Lazarus start problem after power outage on RPi4

2020-08-24 Thread Mattias Gaertner via fpc-pascal
On Mon, 24 Aug 2020 09:12:19 +0200
Bo Berglund via fpc-pascal  wrote:

> Tonight there was a power outage in my home where I have a RaspberryPi
> 4B development system with Lazarus 2.0.8 and Fpc 3.0.4.
> 
> When it happened the system was running including Lazarus.
> Now when I start Lazarus I get to a dialog saying:
> 
> -
> Upgrade configuration
> THere is already a configuration from version prior to 2.0.8 in
> /home/pi/.lazarus_2.0.8
> The old configuration will be upgraded.
> If you want to use two different Lazarus versions you must
> start the second Lazarus with the command line parameter
> primary-config-path or pcp
> 
> 
> [Abort]  [Upgrade]
> -
> 
> Obviously my start desktop file for Lazarus specifies to use pcp as I
> have several versions of Lazarus installed.
> 
> In order not to break anything I used Abort and started checking the
> content of my config dir and comparing to another 2.0.8 version.
> 
> What I found is that there are 3 files in the problem dir that have
> suspicious timestamps/sizes:
> 
> -rw-r--r--  1 pi pi306 Aug 24 03:59 EditorMacros.xml
> -rw-r--r--  1 pi pi  0 Jan  1  1970 environmentoptions.xml
> -rw-r--r--  1 pi pi   2883 Aug 24 03:59 inputhistory.xml
> 
> In the other Lazarus 2.0.8 config dir (set to use fpc 3.2) these files
> are as follows:
> 
> -rw-r--r--  1 pi pi   9735 Jun 21 17:13 environmentoptions.xml
> -rw-r--r--  1 pi pi712 Jun 21 17:13 inputhistory.xml
> 
> EditorMacros.xml is missing in the other dir.
> 
> 
> What to do? It seems like the environmentoptions.xml got hosed in the
> power outage...
> 
> Can I copy this file from an RPi3B where I have installed the same
> versions of Lazarus and Fpc in the same file locations (I use the same
> install scripts on all RPi:s)?

Yes.
After start fix the paths in Tools / Options / Env. / Files to point to
the right fpc.

 
> I really do not want to lose any of what I worked on last night before
> I stopped at 00:31 after finally fixing a persistent bug.


Mattias
 
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Lazarus start problem after power outage on RPi4

2020-08-24 Thread Bo Berglund via fpc-pascal
Tonight there was a power outage in my home where I have a RaspberryPi
4B development system with Lazarus 2.0.8 and Fpc 3.0.4.

When it happened the system was running including Lazarus.
Now when I start Lazarus I get to a dialog saying:

-
Upgrade configuration
THere is already a configuration from version prior to 2.0.8 in
/home/pi/.lazarus_2.0.8
The old configuration will be upgraded.
If you want to use two different Lazarus versions you must
start the second Lazarus with the command line parameter
primary-config-path or pcp


[Abort]  [Upgrade]
-

Obviously my start desktop file for Lazarus specifies to use pcp as I
have several versions of Lazarus installed.

In order not to break anything I used Abort and started checking the
content of my config dir and comparing to another 2.0.8 version.

What I found is that there are 3 files in the problem dir that have
suspicious timestamps/sizes:

-rw-r--r--  1 pi pi306 Aug 24 03:59 EditorMacros.xml
-rw-r--r--  1 pi pi  0 Jan  1  1970 environmentoptions.xml
-rw-r--r--  1 pi pi   2883 Aug 24 03:59 inputhistory.xml

In the other Lazarus 2.0.8 config dir (set to use fpc 3.2) these files
are as follows:

-rw-r--r--  1 pi pi   9735 Jun 21 17:13 environmentoptions.xml
-rw-r--r--  1 pi pi712 Jun 21 17:13 inputhistory.xml

EditorMacros.xml is missing in the other dir.


What to do? It seems like the environmentoptions.xml got hosed in the
power outage...

Can I copy this file from an RPi3B where I have installed the same
versions of Lazarus and Fpc in the same file locations (I use the same
install scripts on all RPi:s)?

I really do not want to lose any of what I worked on last night before
I stopped at 00:31 after finally fixing a persistent bug.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal