[Lazarus] Tooltip shows value of some but not all const items....

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Tooltip shows value of some but not all const items....

Free Pascal - Lazarus mailing list
I am using Lazarus 2.0.8/fpc3.0.4 on RaspberryPi4.

When working on Windows -> Linux porting of an old Delphi app I have
noted that the Lazarus IDE behaves differently when I hover the mouse
over a const item in the source editor. The consts are declared in the
top of the implementation section to be global in the file.

1) The const is declared like this:
  MKFILE= #$E5;
When I hover the mouse I see:
"const MKFILE = #$E5"

2) The const is declared like this:
  REMMEASON: char = #$D5;
When I hover the mouse I see:
"const REMMEASON: char"

So in one case I see the value of the const and in the other case only
the type...

Is there some Lazarus setting that will enable always showing the
value?

Another question:
-----------------
Is there a difference between the two types of declarations?
I think that the # specifier of the value also declares the const as a
char in the first place, or not?

If there is no difference to the compiler I could remove the char type
item for these consts and then be able when navigating the code to see
what the const value actually is, right?

I really do not know why there is a difference there, the code was
worked on from 2004 to 2012 in Delphi 7/2007, but we need to get away
from Windows now so I am porting it to FPC/Lazarus...


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Tooltip shows value of some but not all const items....

Free Pascal - Lazarus mailing list
On 1/2/21 6:09 AM, Bo Berglund via lazarus wrote:
>    MKFILE= #$E5;

this is a constant...

>    REMMEASON: char = #$D5;

this is a typed constant...

that's the difference between the two i see immediately... i don't think there's
a setting like you asked about but i haven't looked... seems like a possible
oversight or defect, tho...

--
  NOTE: No off-list assistance is given without prior approval.
        *Please keep mailing list traffic on the list where it belongs!*
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Tooltip shows value of some but not all const items....

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
Am 02.01.2021 um 12:09 schrieb Bo Berglund via lazarus:
> Is there some Lazarus setting that will enable always showing the
> value?

You would probably need to do a feature request for that.

> Another question:
> -----------------
> Is there a difference between the two types of declarations?
> I think that the # specifier of the value also declares the const as a
> char in the first place, or not?

The first is a "untyped constant". It takes its type implicitely from
the right side and not everything can be a constant (e.g. you can't use
records). So in your case, yet's it's a Char due to the right side being
a character constant.

The second is a so called "typed constant". They are essentially
variables that might be readonly (they are readonly if {$J-} is set
which is *not* the default). They were originally introduced in Turbo
Pascal to allow for static variables inside functions (cause that is how
they behave).

The main difference is that an untyped constant can be used inside
constant expressions (e.g. to declare a static array with certain
bounds) while a typed constant can not. On the other hand you can take
the address of a typed constant (as it's essentially a variable with
readonly data) while you can't do that for untyped constants.

And yes, it behaves this way in Delphi, too.

Regards,
Sven
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Tooltip shows value of some but not all const items....

Free Pascal - Lazarus mailing list
On Sat, 2 Jan 2021 12:36:06 +0100, Sven Barth via lazarus
<[hidden email]> wrote:

>Am 02.01.2021 um 12:09 schrieb Bo Berglund via lazarus:
>> Another question:
>> -----------------
>> Is there a difference between the two types of declarations?
>> I think that the # specifier of the value also declares the const as a
>> char in the first place, or not?
>
>The first is a "untyped constant". It takes its type implicitely from
>the right side and not everything can be a constant (e.g. you can't use
>records). So in your case, yet's it's a Char due to the right side being
>a character constant.
>
>The second is a so called "typed constant". They are essentially
>variables that might be readonly (they are readonly if {$J-} is set
>which is *not* the default). They were originally introduced in Turbo
>Pascal to allow for static variables inside functions (cause that is how
>they behave).
>
>The main difference is that an untyped constant can be used inside
>constant expressions (e.g. to declare a static array with certain
>bounds) while a typed constant can not. On the other hand you can take
>the address of a typed constant (as it's essentially a variable with
>readonly data) while you can't do that for untyped constants.
>
>And yes, it behaves this way in Delphi, too.

Since I see no difference in the usage of these constants typed or
not, I might as well remove the type declaration.
After all I do not want thes to change like a variable can...
The value is a char thanks to the #$ part, I guess.
Or a byte, which is really what it is used as, they are command
identifiers in a packet sent by RS232 to the equipment.


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Tooltip shows value of some but not all const items....

Free Pascal - Lazarus mailing list
Am 02.01.2021 um 23:29 schrieb Bo Berglund via lazarus:

> On Sat, 2 Jan 2021 12:36:06 +0100, Sven Barth via lazarus
> <[hidden email]> wrote:
>
>> Am 02.01.2021 um 12:09 schrieb Bo Berglund via lazarus:
>>> Another question:
>>> -----------------
>>> Is there a difference between the two types of declarations?
>>> I think that the # specifier of the value also declares the const as a
>>> char in the first place, or not?
>> The first is a "untyped constant". It takes its type implicitely from
>> the right side and not everything can be a constant (e.g. you can't use
>> records). So in your case, yet's it's a Char due to the right side being
>> a character constant.
>>
>> The second is a so called "typed constant". They are essentially
>> variables that might be readonly (they are readonly if {$J-} is set
>> which is *not* the default). They were originally introduced in Turbo
>> Pascal to allow for static variables inside functions (cause that is how
>> they behave).
>>
>> The main difference is that an untyped constant can be used inside
>> constant expressions (e.g. to declare a static array with certain
>> bounds) while a typed constant can not. On the other hand you can take
>> the address of a typed constant (as it's essentially a variable with
>> readonly data) while you can't do that for untyped constants.
>>
>> And yes, it behaves this way in Delphi, too.
> Since I see no difference in the usage of these constants typed or
> not, I might as well remove the type declaration.
> After all I do not want thes to change like a variable can...
> The value is a char thanks to the #$ part, I guess.
> Or a byte, which is really what it is used as, they are command
> identifiers in a packet sent by RS232 to the equipment.
For most cases the two can indeed be considered equal, thus it doesn't
matter which one you use.

Your untyped constant will have type Char due to the # prefix.

Regards,
Sven
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus