Recent

Author Topic: Renaming can’t be done from source editor.  (Read 2730 times)

Joanna

  • Hero Member
  • *****
  • Posts: 1099
Renaming can’t be done from source editor.
« on: September 19, 2024, 12:57:26 am »
He everyone
I’m still curious about a quirk in the Lazarus ide that I’ve known about for a long time. It is particularly confusing for people new to using Lazarus...

When a lcl componet is renamed in the source editor, it’s name in object inspector remains unchanged.
It then becomes impossible to switch from the source editor to form view if it was the name of the form changed.
It can also cause errors when launching project which can sometimes only be fixed by opening the lfm file and fixing it there.

Would it be possible to make the source editor able to update the lfm file and object inspector? I understand that componets created at runtime would not have a presence in object inspector and would be disregarded.
« Last Edit: September 20, 2024, 11:03:07 pm by Joanna »
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

440bx

  • Hero Member
  • *****
  • Posts: 4563
Re: Why renaming must be done from object inspector
« Reply #1 on: September 19, 2024, 01:13:06 am »
IDEs like Lazarus and Delphi are limited code generators. 

In those IDEs when an object is created, the IDE generates some code, often a named event, e.g, OnClick, OnWhatever, etc (but can also be a form or other object) which is in part determined by something, usually a name, in the object inspector.

One of the things to be keenly aware of is that, in the great majority of cases (maybe all?) this is a one way street because renaming in the source would necessitate not only continuous parsing of the Pascal source (codetools like) but, in addition to that the parser would have to keep track of which names were generated and which were programmer created.  That's very difficult to accomplish and very error prone.  Not only it is unclear that it may be possible, it isn't practical.

HTH.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Joanna

  • Hero Member
  • *****
  • Posts: 1099
Re: Why renaming must be done from object inspector
« Reply #2 on: September 19, 2024, 01:30:00 am »
I’m unsure of the mechanism by which changing things in object inspector can update bothe the .pas and .lfm files.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1408
    • Lebeau Software
Re: Why renaming must be done from object inspector
« Reply #3 on: September 19, 2024, 06:53:13 am »
I’m unsure of the mechanism by which changing things in object inspector can update bothe the .pas and .lfm files.

I can't speak for Lazarus, but I imagine it is the same as in Delphi.  In Delphi, the TComponent.Name property setter notifies the IDE when a name change occurs at design-time. As the IDE has access to the object being renamed and its old and new names, the IDE is able to update the name of the component in the .pas file, as well as rename any event handlers that are currently assigned to the component that match the old name. And then it regenerates the .dfm file.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

WooBean

  • Sr. Member
  • ****
  • Posts: 271
Re: Why renaming must be done from object inspector
« Reply #4 on: September 19, 2024, 07:40:57 am »
I observed in Lazarus IDE that renaming identifiers being event handlers (procedure heads) - if done via source editor (F2/Find or Rename Identifier) - is propagated to .lfm file content. Those changes can be visible in object inspector (some focus issues remain so something needs to be refreshed manually).

Renaming identifiers being type definitions does not work for replacing them inside .lfm file, so far.

Explained - some wrong conclusions drown as external editors opened .lfm files.
 
Will be solved.
« Last Edit: September 20, 2024, 06:38:09 pm by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

Joanna

  • Hero Member
  • *****
  • Posts: 1099
Re: Why renaming must be done from object inspector
« Reply #5 on: September 19, 2024, 08:48:40 am »
Thanks for the answers.
I just tested using f2 to change name of the form and it had no affect upon the object inspector..
Also recently I was trying to use f2 to rename something and it was ignoring the change. I’m not sure what caused that?  Has anyone ever had that happen?

An idea I’ve thought of for preventing the changing of the name of an existing componet on the form {which can cause a lot of trouble.}
How about if the ide could somehow detect if you are trying to change something that should be changed in object inspector and stop you or at least give a warning? I can imagine that changing the type of an existing  componet From inside the source editor would also be allowed and have disastrous results.

I have not used ides for other languages for a long time so I’m not sure if they have these issues, but this one is very easy to make and can cause some spectacular crashes which is really not too user friendly to people who don’t know how to fix lfm files.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

WooBean

  • Sr. Member
  • ****
  • Posts: 271
Re: Why renaming must be done from object inspector
« Reply #6 on: September 19, 2024, 09:24:06 am »
Thanks for the answers.
I just tested using f2 to change name of the form and it had no affect upon the object inspector..
Also recently I was trying to use f2 to rename something and it was ignoring the change. I’m not sure what caused that?  Has anyone ever had that happen?
...

Renaming a form name is equal to renaming a type of TForm1 (or alike). As I have written this option does not work from source code editor - changes are not propagated to . lfm file.
 
Platforms: Win7/64, Linux Mint Ulyssa/64

Thaddy

  • Hero Member
  • *****
  • Posts: 15731
  • Censorship about opinions does not belong here.
Re: Why renaming must be done from object inspector
« Reply #7 on: September 19, 2024, 10:54:43 am »
I’m unsure of the mechanism by which changing things in object inspector can update bothe the .pas and .lfm files.

I can't speak for Lazarus, but I imagine it is the same as in Delphi. 
No, it isn't. In Delphi any refactoring with e.g. ctrl-shift-E is done properly, meaning both the code and the resource are kept in sync. This is still not the case in FreePascal/Lazarus although bug reports regarding that issue are over 15 years old. That is a bit strange, because all the code needed to implement it is already present.
If I smell bad code it usually is bad code and that includes my own code.

Joanna

  • Hero Member
  • *****
  • Posts: 1099
Re: Why renaming must be done from object inspector
« Reply #8 on: September 19, 2024, 02:17:17 pm »
Why can’t it be fixed then? It is a serious flaw.
Thaddy can you fix it?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Thaddy

  • Hero Member
  • *****
  • Posts: 15731
  • Censorship about opinions does not belong here.
Re: Why renaming must be done from object inspector
« Reply #9 on: September 19, 2024, 05:35:09 pm »
I can, but it would take me probably a lot more time than it would for the core IDE developers.
Only thing that needs adding is also parsing the lfm file when you refactor the pas or pp file.
IOW sync the sourcecode and the lfm. All code to parse lfm is already there, it only needs to be invoked when refactoring.
This is how the Delphi IDE does it: it also parses the dfm when refactoring.
« Last Edit: September 19, 2024, 05:38:14 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Joanna

  • Hero Member
  • *****
  • Posts: 1099
Re: Why renaming must be done from object inspector
« Reply #10 on: September 20, 2024, 12:03:48 am »
How would the updated lfm file update the object inspector?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Thaddy

  • Hero Member
  • *****
  • Posts: 15731
  • Censorship about opinions does not belong here.
Re: Why renaming must be done from object inspector
« Reply #11 on: September 20, 2024, 09:06:16 am »
The object inspector a.o. reads and writes the lfm file...? It is simply just a design time helper/editor to achieve that.
But the real code is the pas or pp file + the form resource. Refactoring is simply not mplemented very well in Lazarus, so if you need to change the name of a control in Lazarus that has to be done tediously through the object inspector, whereas in Delphi refactoring can be done on the project level, which includes the dfm and completely synced with the sourcecode.( and that is by design!)
Technically there is not much difference in renaming sourcecode declarations and do the same in the form file. S&R is S&R.
« Last Edit: September 20, 2024, 09:13:25 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Joanna

  • Hero Member
  • *****
  • Posts: 1099
Re: Why renaming must be done from object inspector
« Reply #12 on: September 20, 2024, 02:10:32 pm »
I create most controls at runtime so refactoring is done with f2 however it doesn’t update the references to what was refactored in other files most of the time . I don’t know if delphi changes all reverence’s in all files for what was refactored?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

wp

  • Hero Member
  • *****
  • Posts: 12368
Re: Why renaming must be done from object inspector
« Reply #13 on: September 20, 2024, 06:07:00 pm »
Refactoring is simply not mplemented very well in Lazarus, so if you need to change the name of a control in Lazarus that has to be done tediously through the object inspector, whereas in Delphi refactoring can be done on the project level, which includes the dfm and completely synced with the sourcecode.( and that is by design!)
I don't agree. Pressing the "Refactoring" > "Rename identifier" command (on main menu, or context menu of an identifer, or by key shortcut) has a lot of options about the scope of the renaming action, and it works very well in my experience, and I have not seen anything that powerful in Delphi.

Thaddy

  • Hero Member
  • *****
  • Posts: 15731
  • Censorship about opinions does not belong here.
Re: Why renaming must be done from object inspector
« Reply #14 on: September 20, 2024, 08:01:10 pm »
wp, with due respect, where is the sync between form and code? ctrl-shift-e doNOT sync in fpc/lazarus.
in many respects the IDE is better than Delphi but in this -essential - respect it is lacking big time.
And possibly the easiest to fix. Does that need to take over 15 years? Maybe wrong priorities.
« Last Edit: September 20, 2024, 08:03:06 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018