Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-02

Component rename in lazarus...

8 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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

Reply by email

Mattias Gaertner
to Bo Berglund
Show quoted text 10 lines
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?

Show quoted text 21 lines
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.

Show quoted text 6 lines
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

Reply by email

Paul Ishenin
to Mattias Gaertner
Mattias Gaertner wrote 5 lines
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.

Show quoted text 6 lines
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

Reply by email

Bo Berglund
to Mattias Gaertner: On Mon, 14 Feb 2011 13:06:50 +0100 I thought Delphi does that? Ctrl+Space (identifier…
Mattias Gaertner wrote 15 lines
On Mon, 14 Feb 2011 13:06:50 +0100 Bo Berglund 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...

Show quoted text 9 lines
> 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...

Show quoted text 13 lines
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

Reply by email

Mattias Gaertner
to Bo Berglund
Show quoted text 6 lines
[...] 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.

Show quoted text 5 lines
>> 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

Reply by email

Alexander Klenin
to Mattias Gaertner: On Mon, 14 Feb 2011 13:06:50 +0100 I thought Delphi does that? Ctrl+Space (identifier…
Mattias Gaertner wrote 13 lines
On Mon, 14 Feb 2011 13:06:50 +0100 Bo Berglund 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

Reply by email