Recent

Author Topic: On the naming of projects..  (Read 724 times)

tfurnivall

  • Jr. Member
  • **
  • Posts: 87
On the naming of projects..
« on: June 10, 2025, 11:40:41 pm »
(with apologies to TS Eliot)

Are there any suggestions for the naming of projects (and more specifically, their components).

I am trying to create a new project - which I want to call CATCOMP

Because it's a GUI application I get a generic unit1 which is associated with a form. I save the project after almost every line, and the last time I did this I ended up with 5 CATCOMP files:
Code: Pascal  [Select][+][-]
  1. CATCOMP.ico
  2. CATCOMP.lpi
  3. CATCOMP.lpr
  4. CATCOMP.lps
  5. CATCOMP.res
  6.  

My form and unit I want to name frmCATCOMP, but when I try to save the project I get Duplicate identifier frmCATCOMP.

I do have 2 frmCATCOMP files:
Code: Pascal  [Select][+][-]
  1. frmcatcomp.lfm
  2. frmcatcomp.pas
  3.  

If I try and change the name of the form, then I still end up with a duplicate identifier - but a different same (if you follow my meaning).

I've tried to locate anything that will give me any sort of guidance on how a project expects to see files named, but all I get is a set of "Do this, Do that" type steps, and narry a word about why this or why that!

Can someone please point me in the direction of a good, useful piece of documentation about this not unimportant aspect of using Lazarus. (And no, I don't want a lifetime of projects all containing 'default' unit1 files)

Sorry about the rant, but internet searching and plowing through the res. ref.user. prog documents is not giving me any results!

Thanks,

Tony

PS I would have uploaded the project, but when I try to Publish it, I'm told there is an error in copying the files - presumably because of the duplicates!

bobby100

  • Sr. Member
  • ****
  • Posts: 301
    • Malzilla
Re: On the naming of projects..
« Reply #1 on: June 11, 2025, 12:24:17 am »
Are you using the same name for file and for your form's component name, e.g. does your form's name in Object Inspector has the same name as the filename you try to save (both frmcatcomp)?
"frm" prefix is a VisualBasic thing. Use "u" or "unt", or even "unit" when saving units (pas file with its corresponding lfm file if there is a form), like untcatcomp.
Even there, if your project is named catcomp, I wouldn't use catcomp in the name of a unit. Make it clear which unit/form is your main unit, and name it something like untMain, or uMain.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12109
  • Debugger - SynEdit - and more
    • wiki
Re: On the naming of projects..
« Reply #2 on: June 11, 2025, 12:50:55 am »
As explained by Bobby100.

In your unit you will likely have
Code: Pascal  [Select][+][-]
  1. unit frmCaTComp;
and
Code: Pascal  [Select][+][-]
  1. type
  2.    TfrmCaTComp = class(TForm)
and
Code: Pascal  [Select][+][-]
  1. var
  2.   frmCaTComp: TfrmCaTComp;

The unitname and the variable name then are the same => duplicate ident.



But, be careful when you rename them.

The unitname "unit abcd" MUST be the same as the filename (without the extension .pas or .pp). So if you want to change that, then use "Save AS".

The variable name is bound to what you name your form in the object inspector.
(and so is the typename "TfrmCaTComp", but that is not a duplicate in the above example)

So you want to change them, change the name in the object inspector.



Hence either pre/post fix your unit name, or the name of the form. They have to be different.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12109
  • Debugger - SynEdit - and more
    • wiki
Re: On the naming of projects..
« Reply #3 on: June 11, 2025, 12:54:23 am »
The reason (or one of them) the unitname and the variable name (or any other name/identifier) must be non-duplicats...

In pascal you can write
Code: Pascal  [Select][+][-]
  1. begin
  2.   unit1.form1.caption := '';
  3. end;

But if the unit was also called "form1", then when you write "form1.caption" do you mean the unit, or the form (variable)?

Just think, the unit could have a variable named caption, so both would compile...

tfurnivall

  • Jr. Member
  • **
  • Posts: 87
Re: On the naming of projects..
« Reply #4 on: June 11, 2025, 02:17:33 am »
Thanks to all who responded!

The nugget I found most useful was from Martin_fr who identified the duplicate as pointed out by the compiler (the variable name and the unit name: frmCatComp). Now, the question (without actually trying it):
If I change the name of one of those things from frmCatComp to (say) frabjit, will the project then try and change something else to match?

Without looking at the code for the IDE (to see exactly what the 'default' names are for things related to a project name), is there any list, anywhere which might be comprehensive enough to be useful?

If not, I may just create a series of projects using distinctive names (such as qwerty,kjhgfd and xcvbnm) to see what names emerge from the project creation business, and what happens when predictable names (like unit1, uni2, etc) get changed.

I've enjoyed learning to use IDEs and am amazed at the number of different files that they populate a directory with! All too often without documentation!

Thanks, again,

Tony

TBMan

  • Sr. Member
  • ****
  • Posts: 346
Re: On the naming of projects..
« Reply #5 on: June 11, 2025, 04:00:13 am »
I use I guess an old school method of naming projects. I name the project for what the purpose of the app is. If it's a Sprite Editor its called SpriteEd, if it is a palette editor it's called PalEd. My units follow a different naming convention. For types that I use often I have LG_Types. (LG = Lazarus GUI). For handy procedures and functions I have LG_Procs. For the GUI basic OOP declaration and methods I have LG_Objects, LG_Dialog, LG1Spr (sprites). For my run length encoded picture display routines I have LG_RLE. For procedures and functions that are more general in nature and can be used in textmode apps as well as GUI apps I have a unit called "General." Simple basic stuff. I keep it simple so I don't confuse myself. :)
Barry

Newest game (clone),
Missile Commander:
https://www.youtube.com/watch?v=tgKz0cxog-k

cdbc

  • Hero Member
  • *****
  • Posts: 2612
    • http://www.cdbc.dk
Re: On the naming of projects..
« Reply #6 on: June 11, 2025, 08:01:47 am »
Hi Tony
Quote
If I change the name of one of those things from frmCatComp to (say) frabjit, will the project then try and change something else to match?
The easy one first:
- In the object inspector: click on the form itself and give it another name -
  could be as simple as "TfrmCATCOMP --> TformCATCOMP";
  Then Lazarus will do all the renaming for you.
The more involved:
- Close Lazarus, open file-explorer, rename the 2 files (*.pas/*.lfm) to
  e.g.: view.catcomp.pas / view.catcomp.lfm, then open a text-editor and
  change the name in the line "unit frmcatcomp;" to "unit view.catcomp;"
- Now open Lazarus and the project again -- it will complain about not
  finding the (now renamed) form-unit, just say [OK] to get it to open.
  Now in the *.lpr file change the uses to include the new name instead of
  the old one.
- Finally [Ctrl] + click on the unit-name in the editor and it should open.
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12109
  • Debugger - SynEdit - and more
    • wiki
Re: On the naming of projects..
« Reply #7 on: June 11, 2025, 10:34:18 am »
If I change the name of one of those things from frmCatComp to (say) frabjit, will the project then try and change something else to match?

Again, I am only 2nd to reply.

1) If you do a "save as" then it should ask if it should rename references, and you should say yes.

Your unit is used in the project. (menu Project > View Project Source). That is in the project source there is
Code: Pascal  [Select][+][-]
  1. uses frmCatComp
That must be updated, and the IDE will do that if you let it.


2) If you change the name of the form in the Object Inspector, then that updates
- the variable
- the type TfrmCatComp
- the content of the LFM file

And if your code has other references that you added, then those too.



Since technically the 2 identifiers are indistinguishable, both of the above could get it wrong, and rename a reference that was not meant to be replaced. (I.e. the IDE could mistake a reference to the unit name for the variable or vice versa). You will notice when you compile. And you would just have to put the correct name in there.




My personal recommendation. Put your project into a (local) repo (no online account needed). E.g. create a local git repo in the project folder, and add/commit all your files.
That way you will
- see any changes
- be able to commit snapshots at any time, and roll back if you got something wrong.

Well, of course that (only) makes sense if you have some experience with revision mgmt systems. If not, it is still a recommendation, but wait till you got through the first bits of gitting into Lazarus/FPC. So you don't need to learn to many new things at once.

 

TinyPortal © 2005-2018