[Lazarus] Annoying code completion failure

Ondrej Pokorny lazarus at kluug.net
Sun Nov 3 11:21:19 CET 2019


On 02.11.2019 11:23, Michael Van Canneyt via lazarus wrote:
> TStrings has a property
>
>     property Values[const Name: string]: string read GetValue write 
> SetValue;
>
> The setter is defined as:
>
> procedure SetValue(const Name, Value: string);
>
> Note that both arguments are 'const'
>
> When adding a new property, and pressing 'CTRL-C', the IDE adds the new
> property, but also insists on adding a new SetValue:
>
> procedure SetValue(const Name: string; AValue: string);
>
> Note the missing const on the second parameter.
>
> It does this of course not only for TStrings, but for all such properties.

The problem is not the const - Lazarus can ignore it. The problem is 
that the parameters are joined - that is what Lazarus cannot handle.

Replace
     procedure SetValue(const Name, Value: string);
with
     procedure SetValue(const Name: string; const Value: string);

then Lazarus won't add it every time you do class completion. I know - 
it's not what you currently have in the interface, but the difference is 
just cosmetic. I usually let Lazarus do its job and don't care that the 
parameters are separated.

Furthermore, you can make Lazarus to add the "const" automatically in 
IDE options -> Codetools -> Class Completion -> Property completion -> 
use const. You can also define an own parameter name or prefix (I use a 
prefix).

Ondrej


More information about the lazarus mailing list