Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/IDE/Search/Replace    [ Add a report in this area ]  
Report #:  7006   Status: Open
Replace All Selected Text replaces outside of the selected text
Project:  Delphi Build #:  4.453
Version:    7.0 Submitted By:   Christopher Latta
Report Type:  Basic functionality failure Date Reported:  1/20/2004 2:26:15 AM
Severity:    Infrequently encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   195033
Resolution: Need More Info (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (5 Total Ratings)
5.00 out of 5
Total Votes: 5
Description
If you use Replace All for selected text where the selected text starts in the middle of the line, it will replace all occurences of the string to replace on that line prior to the selected text (not just in the selected text).

For example, I often need some variables called similar names. So I create the initial variables, copy and paste them, then select the last occurences, and Replace All to change the section of the variable name that needs changing. This won't work if you select the last occurences, but will if you select the first. To illustrate, lets say I create two variables, then copy and paste them to get the following declaration:

foo1, foo2, foo1, foo2: integer;

I then select the last two variables (foo1, foo2) and do Search-Replace All changing "foo" to "bar". What you get is:

bar1, bar2, bar1, bar2: integer;

The first two instances of foo also got changed!

However, if you select the first two occurences of "foo1, foo2", then you will get the expected result:

foo1, foo2, bar1, bar2: integer;

It seems that Replace All regards the selected text to start at the beginning of the line, rather than where the selected text actually starts. The end of the selected text is implemented correctly.

This bug is also in Delphi 6 update 2.
Steps to Reproduce:
1. Type the following line in your code:
foo1, foo2, foo1, foo2: integer;

2. Select the last two occurences of "foo1, foo2"

3. Go Search - Replace All, and choose to replace "foo" with "bar" in the selected text

4. Note that all occurences of "foo" have changed to "bar" on the line, not just those selected, so the result is:
bar1, bar2, bar1, bar2: integer;

Workarounds
None
Attachment
None
Comments

Dave Nottage at 2/1/2004 1:50:22 PM -
Confirmed. Probably treats the whole line as selected, regardless of how much of the line is selected.

Christopher Latta at 2/1/2004 7:55:01 PM -
No. As I noted, the end point seems to be okay, so if your selection ends before the end of the line, the remaining text isn't searched/replaced. It is just that the start point seems to be regarded as the start of the line, not the start of the selected text.

Alexandre Prostorov at 10/24/2007 6:42:45 AM -
Same problem in Turbo Delphi.

Source string:     RegisterEnumeration ('TcxTrackBarTickMarks', ['cxtmBoth, cxtmTopLeft, cxtmBottomRight);

Selected text: from cxtmBoth to the end of line.
Text to find: [, ] without branches (comma-and-space)
Replace with: [', '] (apostrophe-comma-space-apostrophe)
Scope: selected text
Origin: entire scope
Action: replace all

As a result, text around first comma changed.

From 2004 to 2007, from Delphi 6 to current releases... good bug :)

????????? ?????? at 6/29/2010 6:24:54 AM -
Change happens from the beginning of the first row of the selected text until the end of the selected text. Common sense says that the replacement should be done from the beginning of the selected text until the end of the selected text.
This error exists in Delphi5 and Delphi2010. (14.0.3593.25826)

Server Response from: ETNACODE01