Recent

Author Topic: Respecting the case when naming units  (Read 2207 times)

ricardo_sdl

  • New Member
  • *
  • Posts: 21
Respecting the case when naming units
« on: November 20, 2015, 05:19:57 pm »
I'm using Lazarus Version:1.4.4, FPC:2.6.4, Rev SVN:49931, i386-win32-win32/win64.
Whenever a I create a new Unit, I change the name in the code editor to, for example, "unit Util;". When I ask to save it, I change the name to Util.pas, but Lazarus doesn't seem to respect the case in the name Util.pas, saving the file as util.pas, and I noticed that in the uses clause the capitalized name is used, like "uses Util;". I know that on windows this isn't a problem, but I intend to change and compile the same project on Linux too. How can I change this behavior? Or is there a better way to work on projects in different platforms?
Thanks.

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Respecting the case when naming units
« Reply #1 on: November 20, 2015, 07:10:29 pm »
FPC can handle that in different platforms, so there is no need to change that behavior.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Respecting the case when naming units
« Reply #2 on: November 20, 2015, 07:38:30 pm »
The best way to work crossplatform is to make sure your IDE is set to
"Auto rename file lowercase"
in both the cases where this is one of the options.

(See IDE Options dialog, Environment, Naming page and the two sections:
"Ambiguous file action"
"Save As - auto rename Pascal files lowercase"

Note that the file name of a unit will then be renamed by the IDE (if necessary) all lowercase. However, the unit name, the identifier appearing after the reserved word unit at the start of the unit will remain in the casing you first gave it.

For instance your unit might be named MainProgramUnit. The unit would begin thus:
Code: Pascal  [Select][+][-]
  1. unit MainProgramUnit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface            
  6.  

Although the unit has this CamelCased name, the filename of the unit  (as seen by the OS) will have been changed by the IDE to mainprogramunit.pas (or perhaps mainprogramunit.pp, depending on your settings).

This distinction between the unit name and its associated filename can be confusing for newcomers to Pascal.

ricardo_sdl

  • New Member
  • *
  • Posts: 21
Re: Respecting the case when naming units
« Reply #3 on: November 24, 2015, 01:28:47 am »
Thanks guys! Now I understand better how the naming works. I was having some problems on Linux because I'm using some external units that mixed upper and lower case. I think I will just rename them to all lower case like Lazarus does.

 

TinyPortal © 2005-2018