EldoS | Feel safer!

Software components for data protection, secure storage and transfer

StrToUTF8 Converting Delphi 2010 to Delphi 10

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#35301
Posted: 12/24/2015 04:03:56
by Stephen Miyasato (Standard support level)
Joined: 04/24/2009
Posts: 5

I'm converting the following from Delphi 2010 to Delphi Seattle 10 and getting an error.

Code
function TfrmSFTP.StrFromANSI(const Src : string) : string;
begin
  if SftpClient.UseUTF8 then
    Result := SBUtils.StrToUTF8(Src)
  else
    Result := Src;
end;


The following does not compile even if I make changes as follow:
Code
begin
  if SftpClient.UseUTF8 then
    Result := SBUtils.Unit.StrToUTF8(Src)
  else
    Result := Src;
end;


How do I get this working/compiling for Delphi10
#35302
Posted: 12/24/2015 06:41:50
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

StrToUTF8 returns ByteArray, but not a string. Maybe this is the reason of error.
#35303
Posted: 12/24/2015 10:59:22
by Stephen Miyasato (Standard support level)
Joined: 04/24/2009
Posts: 5

SBUtils.StrToUTF dones not compile. It return error on Delphi 10 Seattle.
[dcc32 Fatal Error] fSFTP2.pas(159): F2063 Could not compile used unit 'fSFTP.pas'

Thanks,

Stephen K. Miyasato
#35304
Posted: 12/24/2015 11:09:11
by Eugene Mayevski (EldoS Corp.)

This is not the actual compiler error. There should be some other error in the log.


Sincerely yours
Eugene Mayevski
#35305
Posted: 12/24/2015 11:37:53
by Stephen Miyasato (Standard support level)
Joined: 04/24/2009
Posts: 5

[dcc32 Error] fSFTP.pas(355): E2003 Undeclared identifier: 'StrToUTF8'

The strToUTF8 is underlined red probably meaning not a function in SBUtils.dcu?

Stephen K. Miyasato
#35306
Posted: 12/24/2015 11:47:53
by Vsevolod Ievgiienko (EldoS Corp.)

StrToUTF8 is located in SBStrUtils unit. Please add it to uses sections.
#35307
Posted: 12/24/2015 12:45:32
by Stephen Miyasato (Standard support level)
Joined: 04/24/2009
Posts: 5

So how do you convert String to byte array for the code below.
This seems to have changed from Delphi 2010 to Delphi 10?

Code
function StrToByteArray(Buffer: String): TByteArrays;
begin
  SetLength(Result,lstrlen(PChar(Buffer)));
  CopyMemory(@Result[0],@Buffer[1],Length(Buffer));
end;

function TfrmSFTP.StrFromANSI(const Src : String) : string;
var
  bytes : TBytearrays;
begin
  bytes := StrToByteArray(Src: string); <= Does not work.

  if SftpClient.UseUTF8 then
    Result := SBStrUtils.StrToUTF8(bytes)
  else
    Result := src;
end
;

Stephen K. Miyasato
#35308
Posted: 12/24/2015 12:58:16
by Eugene Mayevski (EldoS Corp.)

I am not sure that I understand what you are trying to do, actually. Could you please tell me, what exactly your StrFromANSI() function should do? What kind of string it has in input and what it should return as output?


Sincerely yours
Eugene Mayevski
#35309
Posted: 12/24/2015 13:16:24
by Stephen Miyasato (Standard support level)
Joined: 04/24/2009
Posts: 5

I need a simple string To byte function since the parameters have changed from string to Array of byte in the original call.
I'm update my previous code in Delphi 2010 to Delphi 10 and getting errors.

SBStrUtils.StrToUTF8(string) //previous

SBStrUtils.StrToUTF8(bytes) //current

Stephen K. Miyasato
#35310
Posted: 12/24/2015 13:32:29
by Eugene Mayevski (EldoS Corp.)

1) What string do you have in Input - is it UTF16 (Unicode) or some code page?

2) what exactly bytes do you need? Bytes can hold anything. What do you want to get in them?

StrToUTF8 works as before. It converts the platform-native (Unicode in your case) string to UTF8 and returns ByteArray filled with UTF8 bytes.

If you need bytes of Unicode string, then simple Move() would work (or you can use BytesOfString method in SBUtils).


Sincerely yours
Eugene Mayevski
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

Topic viewed 3482 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!