Recent

Author Topic: Cannot set TAction.Name to Delete  (Read 2301 times)

mm7

  • Full Member
  • ***
  • Posts: 231
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Cannot set TAction.Name to Delete
« 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?

wp

  • Hero Member
  • *****
  • Posts: 13334
Re: Cannot set TAction.Name to Delete
« Reply #1 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".

mm7

  • Full Member
  • ***
  • Posts: 231
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Cannot set TAction.Name to Delete
« Reply #2 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

ASerge

  • Hero Member
  • *****
  • Posts: 2475
Re: Cannot set TAction.Name to Delete
« Reply #3 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

dsiders

  • Hero Member
  • *****
  • Posts: 1509
Re: Cannot set TAction.Name to Delete
« Reply #4 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

d2010

  • Full Member
  • ***
  • Posts: 246
Re: Cannot set TAction.Name to Delete
« Reply #5 on: April 03, 2025, 08:57:44 am »

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1570
    • Lebeau Software
Re: Cannot set TAction.Name to Delete
« Reply #6 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.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018