Lazarus

Using the Lazarus IDE => Designer => Topic started by: mm7 on April 02, 2025, 02:55:52 am

Title: Cannot set TAction.Name to Delete
Post by: mm7 on April 02, 2025, 02:55:52 am
Hi,
I cannot set TAction.Name to 'Delete' in a new form.
Though there is such action in old forms created in past.

Now Lazarus IDE shows error:  "Cannot set TAction.Name to Delete".

If I change it manually, the class with field Delete compiles Ok.
Code: Pascal  [Select][+][-]
  1.   TMyForm = class(TForm)
  2.     Delete: TAction;
  3.  

I checked FPC keywords docs - there is no keyword delete
I can add a var delete: integer; it is compiled fine.

So why IDE gives this error?
Title: Re: Cannot set TAction.Name to Delete
Post by: wp on April 02, 2025, 11:15:24 am
In Laz/main the error message is "Component name 'delete' is a Pascal keyword." I agree that this is not listed in the keywords list, it seems to be that the same restriction holds for other procedure/function names of the system unit ("inc", "include", "insert", "copy", "read", "write", "continue",...), but not for all ("assign", "reset", "halt", "blockread", "seek", ...). Maybe there is a bug, at least in the creation of the error message.

But it is not a good idea to name an action "Delete" anyway. What if you have a "Delete" button and want to name it "Delete" as well? It's just too ambiguous. Add a prefix (or suffix) to the name, and everything will be okay: "acDelete" or "DeleteAction", "btnDelete" or "DeleteButton".
Title: Re: Cannot set TAction.Name to Delete
Post by: mm7 on April 03, 2025, 01:13:31 am
Thank you wp.

I agree it is not a good idea to name an action "Delete".
The thing is, I dynamically load toolbar button icons based on action names. For example it will load Delete.png into an image list and assign ImageIndex of the Delete action to this.
This allows to change icon themes and sizes dynamically.

It would be nice to have something like "ImageAlias" String property instead of int "ImageIndex". In this case I could use "ImageAlias" to search for PNG files. But it is not the case.

Thanks for a great idea to use a prefix!
Probably I will rename all actions with a prefix. Then I will remove the prefix before searching of an image file.
Then, for action ActionDelete it will load Delete.png
Title: Re: Cannot set TAction.Name to Delete
Post by: ASerge on April 03, 2025, 02:42:40 am
I agree that this is not listed in the keywords list, it seems to be that the same restriction holds for other procedure/function names of the system unit ("inc", "include", "insert", "copy", "read", "write", "continue",...), but not for all ("assign", "reset", "halt", "blockread", "seek", ...). Maybe there is a bug, at least in the creation of the error message.
The entire list can be read from $LAZARUS/components/codetools/keywordfunclists.pas
Title: Re: Cannot set TAction.Name to Delete
Post by: dsiders on April 03, 2025, 03:30:05 am
I agree that this is not listed in the keywords list, it seems to be that the same restriction holds for other procedure/function names of the system unit ("inc", "include", "insert", "copy", "read", "write", "continue",...), but not for all ("assign", "reset", "halt", "blockread", "seek", ...). Maybe there is a bug, at least in the creation of the error message.
The entire list can be read from $LAZARUS/components/codetools/keywordfunclists.pas

Including:
https://gitlab.com/freepascal.org/lazarus/lazarus/-/blob/main/components/codetools/keywordfunclists.pas#L1382-1420
Title: Re: Cannot set TAction.Name to Delete
Post by: d2010 on April 03, 2025, 08:57:44 am
Including:
https://gitlab.com/freepascal.org/lazarus/lazarus/-/blob/main/components/codetools/keywordfunclists.pas#L1382-1420

Why do you not use < or  >  at Line=918?
Code: [Select]
IsNonWordChar[c]=(C<'A' OR c>'z')?
OR is more faster

Title: Re: Cannot set TAction.Name to Delete
Post by: Remy Lebeau on April 03, 2025, 09:23:48 am
it seems to be that the same restriction holds for other procedure/function names of the system unit ("inc", "include", "insert", "copy", "read", "write", "continue",...)

Those are Pascal language keywords.

but not for all ("assign", "reset", "halt", "blockread", "seek", ...).

Those are not Pascal language keywords. They are names of RTL functions.
TinyPortal © 2005-2018