Recent

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

LV

  • Full Member
  • ***
  • Posts: 134
Re: Why renaming must be done from object inspector
« Reply #15 on: September 20, 2024, 08:07:13 pm »
Did I get the question right? I tried to change the name manually:

1. Project->New Project-> Application

2. Project->Save Project (Somewhere)

3. Rename in Unit1.pas in Source Editor
   Unit1 -> UnitMain
   TForm1 -> TFormMain
   Form1 -> FormMain
   File -> Save As unitmain.pas
           Dialog Windows:
           Delete old file? -> Yes
           Update references automatically? -> Not to all
           Maybe:
           Some files have changed on disk -> Reload checked files from disk
           Unable to find the component class "TForm1" -> Ignore, use TForm as ancestor

4. Rename in project1.lpr in Source Editor
   Unit1 -> UnitMain
   TForm1 -> TFormMain
   Form1 -> FormMain

5. File Open unitmain.lfm in Source Editor
   TForm1 -> TFormMain
   Form1 -> FormMain

Run(F9) -> Some files have changed on disk -> Reload checked files from disk -> everything works :)

Updated: after manually renaming Project1.zip
« Last Edit: September 21, 2024, 10:07:58 am by LV »

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1180
Re: Renaming can’t be done from source editor.
« Reply #16 on: September 20, 2024, 11:04:41 pm »
Lfm file is not supposed to be edited under normal conditions which is why it doesn’t open automatically. I have fixed the title of this thread
✨ 🙋🏻‍♀️ 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: 12409
Re: Why renaming must be done from object inspector
« Reply #17 on: September 21, 2024, 12:03:35 am »
wp, with due respect, where is the sync between form and code? ctrl-shift-e doNOT sync in fpc/lazarus.
You are right. But I change component names in the object inspector, and this affects the lfm, probably not project-wide, though.

LV

  • Full Member
  • ***
  • Posts: 134
Re: Renaming can’t be done from source editor.
« Reply #18 on: September 21, 2024, 10:02:24 am »
"Renaming can’t be done from source editor"
I'm sorry, I don't quite understand. If you really want to change it in the source editor, then the sequence of actions is given in Reply #15 (a description of pop-up dialog boxes has been added there).
Have a nice weekend :)

Aruna

  • Sr. Member
  • ****
  • Posts: 494
Re: Why renaming must be done from object inspector
« Reply #19 on: September 21, 2024, 11:13:38 am »
Did I get the question right? I tried to change the name manually:
Hello @LV,
  • Standard Components Pallete->Button->drop into form
  • Compile->Run(F9)!
  • Works, Great!!
Now ...
  • In the Object Inspector->Select Button1:TButton
  • Change property Name from Button1 to AButton1 and keep an eye on the source editor while your doing this.
  • Source editor updates correctly shows your changes, good!
Analysis so far tell us:
  • When you change something in the object inspector it is tracked correctly and updated correctly in the source editor.
  • Great!
Now ...
  • In the source editor just below Button1 physically type in Button2: TButton;
  • Compile+Run and it works
  • But, there is NO Button2 rendered on the Form
  • And surprise NO ERROR MESSAGES
  • This Button we added DOES NOT get into the object inspector.
  • So we can go from the OI to the source editor but not the other way around? It seems to be a one way street?
So you can try ...
  • Putting any other component on the Form.
  • Same story, we change anything in the object inspector it tracks and updates the source editor.Great!
  • We type in directly in the source editor we are screwed :-)
Now ...
  • Rename your TFormMain = class(TForm) to TmyFormMain = class(TForm) in the object inspector.
  • compile+run
  • Works,Great!
Now ...
  • Undo the 'my' in the object inspector and type in 'my' directly in the source editor
  • try to comple and run and ...
  • We get project1.lpr(22,26) Error: Identifier not found "TFormMain"
Try to fix this in project1.lpr by changing
  • Application.CreateForm(TFormMain, FormMain);  to
  • Application.CreateForm(TmyFormMain, myFormMain);
  • Compile+Run
  • The attached screenshots should be self explanatory

I believe this behaviour is by design and I am fine and ok with it BUT if we can go back and forth from the Object Inspector to the Source Editor and vice-versa it can seriously help boost a programmers productivity?

« Last Edit: September 21, 2024, 11:23:18 am by Aruna »

MarkMLl

  • Hero Member
  • *****
  • Posts: 7884
Re: Renaming can’t be done from source editor.
« Reply #20 on: September 21, 2024, 01:45:35 pm »
I don't like getting involved with this since, unlike OP, I don't believe that the work is trivial. And unlike Thaddy I'm not convinced that all the work's already been done and that the patches are in a state in which they can be applied painlessly to the Lazarus trunk.

Everybody agrees that a major part of Delphi's success was that it was able to do a "two-way" reconciliation between form and text: and usually got it right.

There's already areas where the Lazarus IDE requires a certain style of source text. Please note that the last thing I'm trying to do here is criticise the developers and maintainers, but as an example, I offer its not-quite-perfect ability to pick up the comment at the start of a function (etc.) and present it as a pop-up at the point of use.

The risk is that without tight integration of the IDE and compiler (which, I'd remind everybody, are two separate projects with two teams of developers with their own priorities), empowering the IDE to update the form from the source text would require that the latter is in a specific format (perhaps with mandatory source reformatting using Codetools) and possibly incremental parsing as the user types each character... and speaking personally I find that sort of nannyism an infuriating waste of resources.

So: everybody understands that the form designer and object inspector are there to edit the form and other resources, and generally agree that they do a good job. And everybody /should/ understand that the source text editor is there to manipulate objects instantiated by the form. And I think everybody agrees that Lazarus does those jobs very well indeed.

If somebody doesn't agree, and particularly if they believe that all the pieces are in place to fix their perceived problem, I'm sure the rest of the community would be supportive if they produced a branch demonstrating how everything could be pulled together.

Because I certainly don't claim that I'd be up to the job.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

LV

  • Full Member
  • ***
  • Posts: 134
Re: Renaming can’t be done from source editor.
« Reply #21 on: September 21, 2024, 09:54:20 pm »
@Aruna, @MarkMLI. Thanks.

Let's see if we can get two-way traffic going in Lazarus City.

I have Windows 11 and Lazarus 2.2.6 (rev lazarus_2_2_6) FPC 3.2.2 x86_64-win64-win32/win64.

Let's go!

1. Project -> New Project -> Application

2. Project -> Save Project As (..\project1\project1.lpi)

3. From the Standard palette, drag and drop a Button1 onto Form1.

   File -> Save All

4. Change code unit1.pas

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Button2: TButton; // manually
  17.   private
  18.  
  19.   public
  20.  
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. end.  
  31.  

   File -> Save All

5. File -> Open -> unit1.lfm
   Change code unit1.lfm

Code: Pascal  [Select][+][-]
  1. object Form1: TForm1
  2.   Left = 950
  3.   Height = 240
  4.   Top = 503
  5.   Width = 320
  6.   Caption = 'Form1'
  7.   ClientHeight = 240
  8.   ClientWidth = 320
  9.   DesignTimePPI = 120
  10.   LCLVersion = '2.2.6.0'
  11.   object Button1: TButton
  12.     Left = 104
  13.     Height = 31
  14.     Top = 32
  15.     Width = 94
  16.     Caption = 'Button1'
  17.     TabOrder = 0
  18.   end
  19.   object Button2: TButton
  20.     Left = 104
  21.     Height = 31
  22.     Top = 62
  23.     Width = 94
  24.     Caption = 'Button2'
  25.     TabOrder = 1
  26.   end
  27. end      
  28.  
   
    File -> Save All

6. Go to the Unit1.pas tab, then
   File -> Save All
   A dialog box will appear:
   Some files have changed on disk -> Reload checked files from disk,
   then
   (see screenshot 1)

7. Run(F9) everything is fine (see screenshot 2) 

So, Button1 was dragged and dropped onto Form1, and Button2 was added only using the Source Editor. :)


dsiders

  • Hero Member
  • *****
  • Posts: 1259
Re: Why renaming must be done from object inspector
« Reply #22 on: September 21, 2024, 10:30:58 pm »
5. File -> Open -> unit1.lfm
   Change code unit1.lfm

Simplest question I can ask:
Why are you changiing  the contents of the LFM file at all?
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Aruna

  • Sr. Member
  • ****
  • Posts: 494
Re: Why renaming must be done from object inspector
« Reply #23 on: September 21, 2024, 10:34:48 pm »
5. File -> Open -> unit1.lfm
   Change code unit1.lfm

Simplest question I can ask:
Why are you changiing  the contents of the LFM file at all?
That was from @LV not from me :-)

dsiders

  • Hero Member
  • *****
  • Posts: 1259
Re: Why renaming must be done from object inspector
« Reply #24 on: September 21, 2024, 10:39:09 pm »
5. File -> Open -> unit1.lfm
   Change code unit1.lfm

Simplest question I can ask:
Why are you changiing  the contents of the LFM file at all?
That was from @LV not from me :-)

Sorry about that. Question remains...
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Aruna

  • Sr. Member
  • ****
  • Posts: 494
Re: Why renaming must be done from object inspector
« Reply #25 on: September 21, 2024, 10:41:11 pm »
5. File -> Open -> unit1.lfm
   Change code unit1.lfm

Simplest question I can ask:
Why are you changiing  the contents of the LFM file at all?
That was from @LV not from me :-)

Sorry about that. Question remains...
No worries and I think that is the 'only' way to get the ide to 'sync' things but let's wait for @LV to explain why ...

LV

  • Full Member
  • ***
  • Posts: 134
Re: Why renaming must be done from object inspector
« Reply #26 on: September 21, 2024, 10:45:16 pm »
5. File -> Open -> unit1.lfm
   Change code unit1.lfm

Simplest question I can ask:
Why are you changiing  the contents of the LFM file at all?

The simple answer is: I added Button2.

dsiders

  • Hero Member
  • *****
  • Posts: 1259
Re: Why renaming must be done from object inspector
« Reply #27 on: September 21, 2024, 10:50:37 pm »
Quote
5. File -> Open -> unit1.lfm
   Change code unit1.lfm

Simplest question I can ask:
Why are you changiing  the contents of the LFM file at all?

The simple answer is: I added Button2.

You can cut your fingers off with garden shears... that does not mean you should
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

LV

  • Full Member
  • ***
  • Posts: 134
Re: Renaming can’t be done from source editor.
« Reply #28 on: September 21, 2024, 10:54:55 pm »
Witty :)

MarkMLl

  • Hero Member
  • *****
  • Posts: 7884
Re: Why renaming must be done from object inspector
« Reply #29 on: September 21, 2024, 11:25:00 pm »
The simple answer is: I added Button2.

OK, I think we need to make a distinction here.

If I understand things correctly, OP's saying that it should be possible to rename something in the text representation and the form tracks it. That's fair, although because of the Lazarus/FPC split it might in practice be implausible.

However I think that you're saying that you added an entirely new control by editing the .lfm, and with the best will in the World I really don't think that's the same thing at all at all.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018