QuotedStr replacing Double Quote In Delphi

-1
down vote
favorite
	

I need to make a comma separated string which would have multiple string values and each of these value should be in single quote.

When I am using QuotedStr, it is quoting with double-quote,instead of single.

I even tried using single-quote but still it is having same issue.

I tried googling but didn't get any resulting info.

I tried AnsiQuotedStr, but no use.


procedure TForm1.Button3Click(Sender: TObject);
var
  TextValue1, TextValue2, TextValue3, TextValue4, CompleteTextValue : String;
begin
  dsetMyQuert.Close;

  TextValue1 := '{0EC5A35F-273E-4D13-B436-47A826B7858F}';
  TextValue2 := '{0FDC729A-8FCC-4D23-8619-436A459835DD}';
  TextValue3 := '{19930B7E-5792-40BA-9E56-FCF954165596}';
  TextValue4 := '{B10831A0-6A51-45D4-B96B-DA92330DECEF}';

  CompleteTextValue := QuotedStr(TextValue1);
  CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue2);
  CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue3);
  CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue4);

  //CompleteTextValue contains below value
  //'''{0EC5A35F-273E-4D13-B436-47A826B7858F}'', ''{0FDC729A-8FCC-4D23-8619-436A459835DD}'',
  //''{19930B7E-5792-40BA-9E56-FCF954165596}'', ''{B10831A0-6A51-45D4-B96B-DA92330DECEF}'''

  dsetMyQuert.Params[0].Value := CompleteTextValue;
  dsetMyQuert.Open;
  ShowMessage(IntToStr(dsetMyQuert.RecordCount));
end;

Any other ways to make it ?

Regards.

Vishal
0
Vishal
5/19/2015 11:17:01 AM
embarcadero.delphi.firedac 822 articles. 2 followers. Follow

7 Replies
956 Views

Similar Articles

[PageSpeed] 1

Hi Vishal,

as Robert already mentioned, the debug watch window shows quoted strings. That means it will double each single quote!

Create a demo VCL app and add one TEdit to the form. Make the form and the TEdit field as wide as possible.
Use an OnCreate Event like below to create the string as before and set the Edit.Text property.
You'll see the correct string in the running app.


procedure TForm2.FormCreate(Sender: TObject);
var CompleteTextValue : String;
    TextValue1, TextValue2, TextValue3, TextValue4 : String;
begin
  TextValue1 := '{0EC5A35F-273E-4D13-B436-47A826B7858F}';
  TextValue2 := '{0FDC729A-8FCC-4D23-8619-436A459835DD}';
  TextValue3 := '{19930B7E-5792-40BA-9E56-FCF954165596}';
  TextValue4 := '{B10831A0-6A51-45D4-B96B-DA92330DECEF}';

  CompleteTextValue := Format('''%s'', ''%s'', ''%s'', ''%s''', [TextValue1, TextValue2, TextValue3, TextValue4 ]);

  Edit1.Text := CompleteTextValue;
end;


Regards
Norbert
0
Norbert
5/19/2015 1:01:01 AM
> When I am using QuotedStr, it is quoting with double-quote,instead of single.
No, it isn't. You are maybe looking at a debug watch window for the 
value of the variable. These watch windows also place a quote around a 
stringvalue in the display.

To see the real value for example:

{code}
procedure TForm.BitBtn1Click(Sender: TObject);
var TextValue1, TextValue2, TextValue3, TextValue4, CompleteTextValue : String;
    lst: TStringlist;
begin
  lst:=TStringlist.Create;
  try
    TextValue1 := '{0EC5A35F-273E-4D13-B436-47A826B7858F}';
    TextValue2 := '{0FDC729A-8FCC-4D23-8619-436A459835DD}';
    TextValue3 := '{19930B7E-5792-40BA-9E56-FCF954165596}';
    TextValue4 := '{B10831A0-6A51-45D4-B96B-DA92330DECEF}';

    CompleteTextValue := QuotedStr(TextValue1);
    CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue2);
    CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue3);
    CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue4);

    lst.Text:=CompleteTextValue;
    lst.SaveToFile('c:\quotedStr.txt');
  finally
    lst.Free;
  end;
end;
{code}

If you look to the textfile it contains:

'{0EC5A35F-273E-4D13-B436-47A826B7858F}', '{0FDC729A-8FCC-4D23-8619-436A459835DD}', '{19930B7E-5792-40BA-9E56-FCF954165596}', '{B10831A0-6A51-45D4-B96B-DA92330DECEF}'
0
Robert
5/19/2015 11:34:52 AM
Hi,

try to use FireDAC Escape Sequences

 [http://docwiki.appmethod.com/appmethod/1.13/topics/en/Preprocessing_Command_Text_%28FireDAC%29#Escape_Sequences] 

Example for: {s <string>}

     CompleteTextValue := Format('{s %s}, {s %s}, {s %s}, {s %s}' [TextValue1, TextValue2, TextValue3, TextValue4 ]);

Regards
Norbert

> {quote:title=Vishal Tiwari wrote:}{quote}
> -1
> down vote
> favorite
> 	
> 
> I need to make a comma separated string which would have multiple string values and each of these value should be in single quote.
> 
> When I am using QuotedStr, it is quoting with double-quote,instead of single.
> 
> I even tried using single-quote but still it is having same issue.
> 
> I tried googling but didn't get any resulting info.
> 
> I tried AnsiQuotedStr, but no use.
> 
> 
> procedure TForm1.Button3Click(Sender: TObject);
> var
>   TextValue1, TextValue2, TextValue3, TextValue4, CompleteTextValue : String;
> begin
>   dsetMyQuert.Close;
> 
>   TextValue1 := '{0EC5A35F-273E-4D13-B436-47A826B7858F}';
>   TextValue2 := '{0FDC729A-8FCC-4D23-8619-436A459835DD}';
>   TextValue3 := '{19930B7E-5792-40BA-9E56-FCF954165596}';
>   TextValue4 := '{B10831A0-6A51-45D4-B96B-DA92330DECEF}';
> 
>   CompleteTextValue := QuotedStr(TextValue1);
>   CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue2);
>   CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue3);
>   CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue4);
> 
>   //CompleteTextValue contains below value
>   //'''{0EC5A35F-273E-4D13-B436-47A826B7858F}'', ''{0FDC729A-8FCC-4D23-8619-436A459835DD}'',
>   //''{19930B7E-5792-40BA-9E56-FCF954165596}'', ''{B10831A0-6A51-45D4-B96B-DA92330DECEF}'''
> 
>   dsetMyQuert.Params[0].Value := CompleteTextValue;
>   dsetMyQuert.Open;
>   ShowMessage(IntToStr(dsetMyQuert.RecordCount));
> end;
> 
> Any other ways to make it ?
> 
> Regards.
> 
> Vishal
0
Norbert
5/19/2015 11:38:44 AM
Hi Norbert,

I used the statement like below: (Used all single quotes)

CompleteTextValue := Format(''' %s'', '' %s'', '' %s'', '' %s''', [TextValue1, TextValue2, TextValue3, TextValue4 ]);

I got the result like:

''' {0EC5A35F-273E-4D13-B436-47A826B7858F}'', '' {0FDC729A-8FCC-4D23-8619-436A459835DD}'', '' {19930B7E-5792-40BA-9E56-FCF954165596}'', '' {B10831A0-6A51-45D4-B96B-DA92330DECEF}'''


> {quote:title=Norbert Meier wrote:}{quote}
> Hi,
> 
> try to use FireDAC Escape Sequences
> 
>  [http://docwiki.appmethod.com/appmethod/1.13/topics/en/Preprocessing_Command_Text_%28FireDAC%29#Escape_Sequences] 
> 
> Example for: {s <string>}
> 
>      CompleteTextValue := Format('{s %s}, {s %s}, {s %s}, {s %s}' [TextValue1, TextValue2, TextValue3, TextValue4 ]);
> 
> Regards
> Norbert
> 
> > {quote:title=Vishal Tiwari wrote:}{quote}
> > -1
> > down vote
> > favorite
> > 	
> > 
> > I need to make a comma separated string which would have multiple string values and each of these value should be in single quote.
> > 
> > When I am using QuotedStr, it is quoting with double-quote,instead of single.
> > 
> > I even tried using single-quote but still it is having same issue.
> > 
> > I tried googling but didn't get any resulting info.
> > 
> > I tried AnsiQuotedStr, but no use.
> > 
> > 
> > procedure TForm1.Button3Click(Sender: TObject);
> > var
> >   TextValue1, TextValue2, TextValue3, TextValue4, CompleteTextValue : String;
> > begin
> >   dsetMyQuert.Close;
> > 
> >   TextValue1 := '{0EC5A35F-273E-4D13-B436-47A826B7858F}';
> >   TextValue2 := '{0FDC729A-8FCC-4D23-8619-436A459835DD}';
> >   TextValue3 := '{19930B7E-5792-40BA-9E56-FCF954165596}';
> >   TextValue4 := '{B10831A0-6A51-45D4-B96B-DA92330DECEF}';
> > 
> >   CompleteTextValue := QuotedStr(TextValue1);
> >   CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue2);
> >   CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue3);
> >   CompleteTextValue := CompleteTextValue + ', ' + QuotedStr(TextValue4);
> > 
> >   //CompleteTextValue contains below value
> >   //'''{0EC5A35F-273E-4D13-B436-47A826B7858F}'', ''{0FDC729A-8FCC-4D23-8619-436A459835DD}'',
> >   //''{19930B7E-5792-40BA-9E56-FCF954165596}'', ''{B10831A0-6A51-45D4-B96B-DA92330DECEF}'''
> > 
> >   dsetMyQuert.Params[0].Value := CompleteTextValue;
> >   dsetMyQuert.Open;
> >   ShowMessage(IntToStr(dsetMyQuert.RecordCount));
> > end;
> > 
> > Any other ways to make it ?
> > 
> > Regards.
> > 
> > Vishal
0
Vishal
5/19/2015 1:11:16 PM
Hi Norbert,

The Edit Box is showing correct values, but when I use that variable to add to query component, I still don't get result.

What I feel is, there is work around with this. Fill the value in the text box and then assign that text box to query component's parameter as an parameter value.

What is your opinion. Because, still I could not use the variable which we assigned to Edit Box directly to query component.


With Best Regards.

Vishal

> {quote:title=Norbert Meier wrote:}{quote}
> Hi Vishal,
> 
> as Robert already mentioned, the debug watch window shows quoted strings. That means it will double each single quote!
> 
> Create a demo VCL app and add one TEdit to the form. Make the form and the TEdit field as wide as possible.
> Use an OnCreate Event like below to create the string as before and set the Edit.Text property.
> You'll see the correct string in the running app.
> 
> 
> procedure TForm2.FormCreate(Sender: TObject);
> var CompleteTextValue : String;
>     TextValue1, TextValue2, TextValue3, TextValue4 : String;
> begin
>   TextValue1 := '{0EC5A35F-273E-4D13-B436-47A826B7858F}';
>   TextValue2 := '{0FDC729A-8FCC-4D23-8619-436A459835DD}';
>   TextValue3 := '{19930B7E-5792-40BA-9E56-FCF954165596}';
>   TextValue4 := '{B10831A0-6A51-45D4-B96B-DA92330DECEF}';
> 
>   CompleteTextValue := Format('''%s'', ''%s'', ''%s'', ''%s''', [TextValue1, TextValue2, TextValue3, TextValue4 ]);
> 
>   Edit1.Text := CompleteTextValue;
> end;
> 
> 
> Regards
> Norbert
0
Vishal
5/20/2015 5:23:52 AM
Hi Vishal,

you are wrong. The string isn't changed.

Try this to check that:

procedure TForm2.FormCreate(Sender: TObject);
var CompleteTextValue1, CompleteTextValue2 : String;
    TextValue1, TextValue2, TextValue3, TextValue4 : String;
begin
  TextValue1 := '{0EC5A35F-273E-4D13-B436-47A826B7858F}';
  TextValue2 := '{0FDC729A-8FCC-4D23-8619-436A459835DD}';
  TextValue3 := '{19930B7E-5792-40BA-9E56-FCF954165596}';
  TextValue4 := '{B10831A0-6A51-45D4-B96B-DA92330DECEF}';

  CompleteTextValue1 := Format('''%s'', ''%s'', ''%s'', ''%s''', [TextValue1, TextValue2, TextValue3, TextValue4 ]);

  FDQuery1.Params[0].Value := CompleteTextValue1; 
  CompleteTextValue2 := FDQuery1.Params[0].Value;

  Edit1.Text := CompleteTextValue1;
  Edit2.Text := CompleteTextValue2;

  if CompleteTextValue1 = CompleteTextValue2 then
    ShowMessage('CompleteTextValue1 and CompleteTextValue2 are identical!')
  else
    ShowMessage('CompleteTextValue1 and CompleteTextValue2 differ!');

  ShowMessage('CompleteTextValue1:' +#13+ CompleteTextValue1);
  ShowMessage('CompleteTextValue2:' +#13+ CompleteTextValue2);
end;

Regards
Norbert
0
Norbert
5/20/2015 6:28:00 AM
You are doing an Insert or Update statement of the query and not a Select.
With a Select statement you do "myQuery.Open" (you espect a result set) but 
with insert and update you should do "myQuery.ExecSQL".
0
Robert
5/20/2015 6:59:21 AM
Reply:

Similar Artilces:

"Sneak Preview: Delphi 2011 is Delphi XE"
Today, Delphi's Welcome page showed this: Sneak Preview: Delphi 2011 is Delphi XE http://www.embarcadero.com/rad-studio-xe-preview When trying to watch the video, it gives an error message: Server not found: rtmp://etnastream01.embarcadero.com/vod/ How nice :-( Achim Achim Kalwa wrote: > Sneak Preview: Delphi 2011 is Delphi XE > http://www.embarcadero.com/rad-studio-xe-preview > > When trying to watch the video, it gives an error message: > > Server not found: > rtmp://etnastream01.embarcadero.com/vod/ Works for me on second try (first ...

Does the type "double" mean the same thing in Delphi and C?
My Delphi app needs to call a function from OpenSSL DLL, which has the following prototype: void RAND_add(const void *buf, int num, double entropy); Is the Delphi type "double" compatible with the double type used in Windows-based C programming language? If not, how can I pass a C-compatible value of the double type to the DLL? Thanks. Simon Lau wrote: > My Delphi app needs to call a function from OpenSSL DLL, which has > the following prototype: > > void RAND_add(const void *buf, int num, double entropy); > > > Is the Delphi type &quo...

"borland.public.delphi.thirdpartytools.general" group replacement?
There was a nice place to post relases announcements about 3rd party components - "borland.public.delphi.thirdpartytools.general" group. Is there any place to post such ANN at this forum? Mikhail Oleynik wrote: > There was a nice place to post relases announcements about 3rd party > components - "borland.public.delphi.thirdpartytools.general" group. > Is there any place to post such ANN at this forum? news://forums.codegear.com/embarcadero.public.delphi.thirdpartytools.general or https://forums.codegear.com/forum.jspa?forumID=92&start=0 -- ...

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

How do I REPLACE the double quote (")???
Can anybody here help me with a problem? See, I wanted to use the Replace function to find any and all double quotes (") and replace it with a special character. However, I am having problem specifying the double quote to be replaced because of this: Syntax: [code] str.Replace("<character to be replaced>", "<replace with this character instead>") [/code] But since the first argument requires the character to be replaced to be wrapped in doucble quotes, how do I specify that I want double quotes in my strings to be replaced? Please hel...

NOT SOLVED "Delphi.Personality" and platform "win32" missing or unavailable
Hello, Just installed (21st February 2012) Delphi XE2 Starter. Build 16.0.4276.44006 *Installed Updates* (RAD Studio XE2 Delphi and C++ Builder Update 1) (BTW why can't this info be copied instead of typing from Help>About) Got: *[DCC Error] Compiler for personality "Delphi.Personality" and platform "win32" missing or unavailable* when trying to run 1st Sample VBlock (BTW why there is no standard Hello World to show that IDE works?) *In spite of CASE SOLVED:* Report #: 98901 Status: Closed "Delphi.Personality" and platform "Win32...

Delphi 2007 assert
The assertion message from Delphi 2007 is... "(!"SetThreadContext failed")" in ..\win32src\thread32.cpp at line 412 Any way I can patch this out? CodeGearâ„¢ Delphi® 2007 for Win32® Version 11.0.2902.10471 El 18/01/2014 21:48, Michael Leahy escribió: > The assertion message from Delphi 2007 is... > > "(!"SetThreadContext failed")" in ..\win32src\thread32.cpp at line 412 > > Any way I can patch this out? > > CodeGearâ„¢ Delphi® 2007 for Win32® Version 11.0.2902.10471 > An unofficial fix fo...

[XE2] "Delphi.Personality" and platform "Win32" missing or unavailable
I'm using Windows Vista Business 32-bit and C++ Builder XE2. When I create a new VCL project, add some Delphi files (.pas) to the project and try to compile, I receive the following error messages: {code} [DCC Fatal Error] Exception Exception: Compiler for personality "Delphi.Personality" and platform "Win32" missing or unavailable. [DCC Error] Compiler for personality "Delphi.Personality" and platform "Win32" missing or unavailable. {code} Normally, in C++ Builder XE, when I add some Delphi files to my projects, it compiles without any prob...

[XE2] "Delphi.Personality" and platform "Win32" missing or unavailable
Today I reinstall XE2 with update 1, when I try to run the application, I got following error message, I am sure it used to works fine before rebuilding my PC. [DCC Fatal Error] Exception Exception: Compiler for personality "Delphi.Personality" and platform "Win32" missing or unavailable. [DCC Error] Compiler for personality "Delphi.Personality" and platform "Win32" missing or unavailable. so what I can do now to work around it? solved, I removed the environment varible platform(platform=win32) and not get this error message again. > {qu...

QUOTEDSTR Problems in DELPHI XE: Doble Quoted
Hi! QUOTEDSTR, In delphi 7: 'select * from customers where name like ' + quotedStr('smith%') //'select * from customers where name like 'smith%' In delphi XE: 'select * from customers where name like ' + quotedStr('smith%') //'select * from customers where name like ''smith%'' WHY DELPHI XE insert DOBLE QUOTED "smith"? could you help me? Thanks. > {quote:title=JOSE IGNACIO RUIZ wrote:}{quote} > Hi! > > QUOTEDSTR, > > In delphi 7: 'select * from customers where name li...

Delphi 2010 IDE throws error on "find" and "find in files"
I will greatly appreciate any advice how to cure the suddenly appeared misbehaviour: I just loaded the main project file and then tried to find code snippets fore re-use with "find" and "find in files" the Eurekalog extract is: 2.2 Address : 20EB30B6 2.3 Module Name : vclide140.bpl - (Integrated Development Environment Specific Components) 2.4 Module Version: 14.0.3593.25826 2.5 Type : EOutOfResources 2.6 Message : Unable to insert a line. 2.7 ID : 61FB 2.8 Count : 1 2.9 Status ...

First use of XE7, "Delphi Package Output Directory", "path is too long"
I have been using Delphi 2010, and also had XE2 installed (but never used it). Yesterday I purchased the Delphi XE7 update, and installed it. Upon first launch, I got this dialog: {code} Warning [window title] Your current Delphi Package Output Directory is not part of your system path. In order to use runtime packages that are built into this directory, this directory needs to be on your path. However, it appears that your current system path is too long. Please manually edit your system path to remove unnecessary items and/or include this directory. Directory to be added: c:\User...

double quote
hello there...  i tried everything of think but not working the way i wanted to be... not sure what i'm missing...i'm generating a <span> in code behind and then using in javascript.... here is what i'm doing code behind: int i=0string _keywordID = "keyword";string _name = row["visit_info_nm"].ToString().Trim(); String _getElementByID = String.Format("<span id='{0}' OnClick = \"document.getElementById('{1}').value='{2}';\">{3}</span><br>", i, _keywordID, _name, _name); here is what it generate : <span id='1' OnClick = \"document.getElementById('keyword')...

replace the "." with a ","
Oi.... I need to build a small programm in ASP.NET and chose to use C# for it.Now i got everything working but there's one little problem.the first textbox is a double. I need to make it so that when someone enters a "." then it gets replaced by a ","any ideas?Ghan  string blah = "4.2.2.2";blah = blah.Replace(".", ",");Ryan Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

Web resources about - QuotedStr replacing Double Quote In Delphi - embarcadero.delphi.firedac

Resources last updated: 1/23/2016 12:20:25 PM