[Lazarus] Component rename in lazarus...

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Component rename in lazarus...

Bo Berglund
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...

Now I am just wondering what other goodies are hidden in Lazarus?
Pleasant surprieses await, no doubt.

Question:
In Delphi I really wanted a feature of the VisualBasic 6 editor but it
never materialized in Delphi: Case correction.

This means that if I write a function like this:
function MyFunc: boolean;
var
  MyVar: byte;
  MyOtherVar: word;
begin
  myvar := 23;
  myothervar := myVar + 56;

then the editor will immediately correct the case of the variables so
the code comes out like this:

  MyVar:= 23;
  MyOtherVar := MyVar + 56;

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?

(I made a quick test but it did not work right off the bat at least)


Bo Berglund


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Component rename in lazarus...

Mattias Gaertner
On Mon, 14 Feb 2011 13:06:50 +0100
Bo Berglund <[hidden email]> 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?

 

> Now I am just wondering what other goodies are hidden in Lazarus?
> Pleasant surprieses await, no doubt.
>
> Question:
> In Delphi I really wanted a feature of the VisualBasic 6 editor but it
> never materialized in Delphi: Case correction.
>
> This means that if I write a function like this:
> function MyFunc: boolean;
> var
>   MyVar: byte;
>   MyOtherVar: word;
> begin
>   myvar := 23;
>   myothervar := myVar + 56;
>
> 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'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.

 
> (I made a quick test but it did not work right off the bat at least)


Mattias

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Component rename in lazarus...

Paul Ishenin
14.02.2011 20:40, Mattias Gaertner wrote:
> 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?
Delphi does not rename all uses of component in the code.
>
> 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'm not sure, maybe jcf can fix casing.
Only using fixed list of words like: Assign, WriteLn

Best regards,
Paul Ishenin

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Component rename in lazarus...

Paul Ishenin
In reply to this post by Bo Berglund
14.02.2011 19:06, Bo Berglund wrote:
> Now I am just wondering what other goodies are hidden in Lazarus?
> Pleasant surprieses await, no doubt.
Try code observer - another hidden nice feature: http://imagebin.org/137895

It shows you places which are asking for refactoring.

Best regards,
Paul Ishenin

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Component rename in lazarus...

Bo Berglund
In reply to this post by Mattias Gaertner
On Mon, 14 Feb 2011 14:40:17 +0100, Mattias Gaertner
<[hidden email]> wrote:

>On Mon, 14 Feb 2011 13:06:50 +0100
>Bo Berglund <[hidden email]> 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


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Component rename in lazarus...

Mattias Gaertner
On Mon, 14 Feb 2011 17:46:35 +0100
Bo Berglund <[hidden email]> wrote:

>[...] On Mon, 14 Feb 2011 14:40:17 +0100, Mattias Gaertner
> >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...

Strange. I wonder why.

 
> >> then the editor will immediately correct the case of the variables so
> >> the code comes out like this:
>[...]
> If I now put the cursor at the declaration name and hit Ctrl-Space a
> list is shown that starts with Date.

I meant if you use Ctrl+Space while writing code the case is
automatically copied from the declaration and the editor will
immediately correct the case.
For example:

var
  Date: string;
begin
  dat|

Ctrl+Space will fix this to "Date".

Note: As I wrote: automatic fixing of not touched code is not always
wanted.

>[...]

Mattias

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Component rename in lazarus...

Hans-Peter Diettrich
In reply to this post by Bo Berglund
Bo Berglund schrieb:

> Now I am just wondering what other goodies are hidden in Lazarus?
> Pleasant surprieses await, no doubt.

Have a look at the editor context menu: Refactoring|Rename Identifier...

DoDi


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Component rename in lazarus...

Alexander Klenin
In reply to this post by Mattias Gaertner
On Mon, Feb 14, 2011 at 23:40, Mattias Gaertner
<[hidden email]> wrote:
> On Mon, 14 Feb 2011 13:06:50 +0100
> Bo Berglund <[hidden email]> wrote:

>> 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.
>

See also http://bugs.freepascal.org/view.php?id=17618

--
Alexander S. Klenin

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus