views:

408

answers:

2

Hello there,

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.

A: 

http://www.micro-isv.asia/2008/08/using-rawbytestring-effectively/ may be helpful?

EricLaw -MSFT-
Thanks, I read that page earlier and it said 'Essentially, RawByteString disables implicit conversion.' which isn't what I am seeing above.
Wizzard
RawByteString does not perform implicit conversions when assigned to/from other Ansi string types. That is not the case in your code. You are assigning a UnicodeString to a RawByteString. An implicit conversion is being performed (unless you type-cast it away).
Remy Lebeau - TeamB
+2  A: 

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.

Remy Lebeau - TeamB