[Lazarus] Component rename in lazarus...

Bo Berglund bo.berglund at gmail.com
Mon Feb 14 17:46:35 CET 2011


On Mon, 14 Feb 2011 14:40:17 +0100, Mattias Gaertner
<nc-gaertnma at netcologne.de> wrote:

>On Mon, 14 Feb 2011 13:06:50 +0100
>Bo Berglund <bo.berglund at gmail.com> wrote:
>
>> By accident I just discovered a feature of Lazarus that I was not
>> aware of:
>> I had misnamed a component and wanted to correct it, so I gave it a
>> new name in the property editor. Then I planned on going over the code
>> and change the places where the component was used to the new name.
>> 
>> But it was already done! Apparently Lazarus keeps tabs on such renames
>> and changes the places in the form code where the old name was used to
>> the new name! Excellent!! :-)
>> This is something I had wanted in Delphi too...
>
>I thought Delphi does that?

Only for events that are linked to the component, like OnClick for a
button. These change name when the button changes name. But no other
references to the button name in code are fixed...


>> then the editor will immediately correct the case of the variables so
>> the code comes out like this:
>> 
>>   MyVar:= 23;
>>   MyOtherVar := MyVar + 56;
>
>Ctrl+Space (identifier completion) copies the case.
>Automatic recasing may be unwanted if the declaration has no casing at
>all. For example SysUtils is nicer to read than sysutils.

I tested with the following:
var
  ..
  Data: string;
begin
  ...
  Data := 'something';

Then I changed the declaration to DaTa.
If I now put the cursor at the declaration name and hit Ctrl-Space a
list is shown that starts with Date.
And if I put the cursor in the reference in the code and hit
Ctrl-Space a list is shown which starts with DaTa : string;
So if I know that an identifer needs to be fixed I can use this
shortcut to change it but it won't modify anything else so all other
instances of the wrong casing stays the same...


>I'm not sure, maybe jcf can fix casing.
>
> 
>> And if I later change the declaration to:
>>   Myvar: byte;
>> 
>> then the places it is used will change to the new case style.
>> 
>> Is there some way one can make this happen in Lazarus?
>
>Shift+Ctrl+E renames variables and references. It does not yet find all
>references, but IMO it is already a useful tool.
>

This actually does work by finding all references to the same
identifier within scope and renaming to whatever is put into the
editbox.
Although not entirely what I was looking for it may still help to
clean up the code after typing along without proper casing.

-- 
Bo Berglund
Developer in Sweden





More information about the Lazarus mailing list