Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: QuotedStr replacing Double Quote In Delphi


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 7 - Last Post: May 19, 2015 11:59 PM Last Post By: Robert Triest
Vishal Tiwari

Posts: 10
Registered: 3/27/10
QuotedStr replacing Double Quote In Delphi  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2015 4:17 AM
-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

Robert Triest

Posts: 687
Registered: 3/24/05
Re: QuotedStr replacing Double Quote In Delphi  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2015 4:34 AM   in response to: Vishal Tiwari in response to: Vishal Tiwari
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:

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;


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}'
Norbert Meier

Posts: 19
Registered: 11/26/01
Re: QuotedStr replacing Double Quote In Delphi  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2015 4:38 AM   in response to: Vishal Tiwari in response to: Vishal Tiwari
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

Vishal Tiwari wrote:
-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

Vishal Tiwari

Posts: 10
Registered: 3/27/10
Re: QuotedStr replacing Double Quote In Delphi  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2015 6:11 AM   in response to: Norbert Meier in response to: Norbert Meier
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}'''

Norbert Meier wrote:
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

Vishal Tiwari wrote:
-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

Norbert Meier

Posts: 19
Registered: 11/26/01
Re: QuotedStr replacing Double Quote In Delphi  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2015 6:43 AM   in response to: Vishal Tiwari in response to: Vishal Tiwari
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

Vishal Tiwari

Posts: 10
Registered: 3/27/10
Re: QuotedStr replacing Double Quote In Delphi  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2015 10:23 PM   in response to: Norbert Meier in response to: Norbert Meier
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

Norbert Meier wrote:
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

Norbert Meier

Posts: 19
Registered: 11/26/01
Re: QuotedStr replacing Double Quote In Delphi  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2015 11:28 PM   in response to: Vishal Tiwari in response to: Vishal Tiwari
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
Robert Triest

Posts: 687
Registered: 3/24/05
Re: QuotedStr replacing Double Quote In Delphi  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2015 11:59 PM   in response to: Vishal Tiwari in response to: Vishal Tiwari
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".
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02