?
Solved

StringReplace

Posted on 2003-03-29
8
Medium Priority
?
316 Views
Last Modified: 2010-04-04
I am trying to replace substrings within a string using the function StringReplace.

But I get an error:

"[Error] SChtmlemail.dpr(151): Incompatible types"

I have following in my code:

type
    TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);

var
  TemplateFields : array of record
    Name : string;
    Value : string;
  end
  s : string;
  flags : TReplaceFlags;

begin
 flags := [rfReplaceAll];
 s := StringReplace(s,TemplateFields[n].Name,TemplateFields[n].Value, flags);
end;


I have tried following variations of StringReplace:

StringReplace(s,TemplateFields[n].Name,TemplateFields[n].Value, flags);
StringReplace(s,TemplateFields[n].Name,TemplateFields[n].Value, [rfReplaceAll]);
StringReplace(s,TemplateFields[n].Name,TemplateFields[n].Value, 'rfReplaceAll');

but none works. What am I doing wrong?

0
Comment
Question by:tommykjensen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 6

Expert Comment

by:DaFox
ID: 8230195
Hi.

These calls should work:

StringReplace(s,TemplateFields[n].Name,TemplateFields[n].Value, flags);
StringReplace(s,TemplateFields[n].Name,TemplateFields[n].Value, [rfReplaceAll]);

This one doesn't (it's not of type TReplaceFlags, it's a String!):

StringReplace(s,TemplateFields[n].Name,TemplateFields[n].Value, 'rfReplaceAll');

There is no error in your code. s, TemplateFields[n].Name, TemplateFields[n].Value are all string type!

Something wrong with your dynamic array?
Where does the error occur?

Markus
0
 
LVL 3

Expert Comment

by:marcoszorrilla
ID: 8230198
procedure TForm1.Button1Click(Sender: TObject);
var
s:String;
r:String;
begin
Oldp:='h';
newp:='b';
s:='holaholaholahola';
r:=StringReplace(s,'hola','bola',[rfReplaceAll]);
ShowMessage(r);
end;


Best Regards
Marcos
0
 
LVL 3

Expert Comment

by:marcoszorrilla
ID: 8230200
Pardon Oldp and Newp were string variables that I tested before the code above.




procedure TForm1.Button1Click(Sender: TObject);
var
s:String;
r:String;
begin
s:='holaholaholahola';
r:=StringReplace(s,'hola','bola',[rfReplaceAll]);
ShowMessage(r);
end;

Best Regars.
Marcos.


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tommykjensen
ID: 8230229
The error occurs during compile.
0
 
LVL 6

Expert Comment

by:DaFox
ID: 8230251
Yep, but where is line 151 in your snippet?
0
 

Author Comment

by:tommykjensen
ID: 8230258
Line 151 is the line with Stringreplace
0
 
LVL 6

Accepted Solution

by:
DaFox earned 100 total points
ID: 8230293
Okay, the problem is that you're redefining TReplaceFlags. Delete this line
-> TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
and you're done.

Markus
0
 

Author Comment

by:tommykjensen
ID: 8230314
Yep that did it. Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question