Forum > Beginners

How to rename default Form in Lazarus

<< < (2/5) > >>

dseligo:

--- Quote from: aag031 on March 20, 2022, 12:10:17 pm ---Is there more suitable way for renaming default form?

--- End quote ---

Generally, components that are in .lfm file (that includes form itself and all components, visual and non-visual put in the form) should be renamed using Object inspector.
Other identifiers are renamed in source (easiest is by pressing F2 or using menu Source / Refactoring / Rename Identifier or right click on the identifier and then Refactoring / Rename Identifier. It would be nice to get a warning when using this method and try to rename something that is also in .lfm file (I did so in couple of occasions which led me to similar problems you have).

howardpc:
I think aag031's problem came from manually renaming a variable in only one place in the source when that name occurs throughout the sources in all of *.pas, .lpr and .lfm files.
His problem is not related to using the Rename Identifier dialog, which was developed specifically to *avoid* the problem you mention. Rename Identifier carefully synchronises renaming across all affected parts of a project. If you find it does not, this is a bug which you should report with a compileable example.

wp:
Although renaming identifiers in the Object Inspector or by using the Refactoring menu item works in most cases there is still the possibility that something goes wrong. Here is an example: Drop a TSynEdit on a form - the new form gets the name "SynEdit1", and a new unit "SynEdit" will appear in the uses clause. Now you decide to rename "SynEdit1" to "SynEdit" (without the appended "1"). When you do this with the Object Inspector, it works fine. But finally you decide: there should be a clearer name - since the SynEdit displays - say - xml data it should be named "XMLSynEdit". Again you use the Object Inspector to change the component name. But when you compile the project, it will not work any more because the unit "SynEdit" in the uses clause has been renamed to "XmlSynEdit", too! (https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39669).

So, be careful.

dseligo:

--- Quote from: howardpc on March 20, 2022, 12:39:04 pm ---His problem is not related to using the Rename Identifier dialog, which was developed specifically to *avoid* the problem you mention. Rename Identifier carefully synchronises renaming across all affected parts of a project. If you find it does not, this is a bug which you should report with a compileable example.

--- End quote ---

I put example in the attachment.

On the form there is a button named Button1 (both in unit1.pas and in Object inspector). In the OnCreate event of the form there is Button1.Click; statement.

Now, try to rename Button1 using F2 shortcut (e.g. to ButtonTest). It is renamed in unit1.pas, but not in unit1.lfm (and consequently in Object inspector).
When you try to run project now you get access violation error:

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---[Window Title]Error [Content]Project project1 raised exception class 'External: ACCESS VIOLATION' with message:Access violation reading from address $0000000000000000.  In file 'unit1.pas' at line 34:ButtonTest.Click;
If you can confirm that this should not happen, I'll report bug.

I tested this with Lazarus 2.2.0, FPC 3.2.2, Windows 11, but it is exactly the same with Lazarus 2.0.10.

dseligo:

--- Quote from: howardpc on March 20, 2022, 12:39:04 pm ---I think aag031's problem came from manually renaming a variable in only one place in the source when that name occurs throughout the sources in all of *.pas, .lpr and .lfm files.
His problem is not related to using the Rename Identifier dialog, which was developed specifically to *avoid* the problem you mention. Rename Identifier carefully synchronises renaming across all affected parts of a project. If you find it does not, this is a bug which you should report with a compileable example.

--- End quote ---

I renamed form type from TForm1 to TFormTest and got message just like OP had:

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---[Debugger Exception Notification]  [Break]Project project1 raised exception class 'EResNotFound' with message:Form resource TFormTest not found. For resourceless forms CreateNew constructor must be used. See the global variable RequireDerivedFormResource.  In file 'customform.inc' at line 2053  [Ignore this exception type] [Continue]

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version