Wizzard
Wizzard

Reputation: 12702

Delphi 2009 - Implicit string to RawByteString conversion warnings

I have just got my hands on D2009 and using it with one of our existing projects - it all compiles fine however I have just picked up DIRegEx to use some regex in the project.

However it's always giving warnings about String to RawByteString and vice versa. Eg

var
  Response : string;
begin
  Response := idHTTP.Get('http://www.somesite.com');
  DIRegEx.SetSubjectStr(Response);
  ......

Now, the SetSubjectStr parameter is of RawByteString type, and the response from idHTTP.Get is just string. It seems strange that I would have either, do

DIRegEx.SetSubjectStr(utf8string(Response));

or

var
  Response : Utf8String;
begin
  Response := Utf8String(idHTTP.Get......);

What am I supposed to do here.

Upvotes: 0

Views: 3667

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 596267

Since DIRegEx clearly does not accept Unicode input, you have no choice but to perform some kind of data conversion from what you download online to what you pass to DIRegEx. TIdHTTP is already doing its own conversions internally from the data's original encoding (as specified by the server) to Unicode before passing the final data to you. If you want to operate on the raw bytes that the server sends, without TIdHTTP's internal interpretations being applied to it, then you will have to pass a TMemoryStream to TIdHTTP to receive the raw output, and then do whatever you need to with it.

Upvotes: 2

Related Questions