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

Sven Barth pascaldragon at googlemail.com
Sun Jan 3 14:35:08 CET 2021


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
> <lazarus at lists.lazarus-ide.org> 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


More information about the lazarus mailing list