Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Project from Ansi to Unicode (https://www.delphipraxis.net/179881-project-ansi-unicode.html)

WojTec 8. Apr 2014 16:06

Delphi-Version: 2010

Project from Ansi to Unicode
 
I found nice unit to work with torrents:

Code:
http://torrentspy.cvs.sourceforge.net/viewvc/torrentspy/TorrentSpy-0.2-delphi/src/
So, TorrentFile.pas and included ones are not Unicode ready. I can't make it working with D2010+ (I only can exchange MessageDigests.pas with DEC). Could you help, please?

Delphi-Quellcode:
// Test code: Ansi - oke, Unicode - empty

var
  T: TTorrentFile;
  F: TStream;
begin
  if OpenDialog1.Execute then
  begin
    T := TTorrentFile.Create;
    F := TFileStream.Create(OpenDialog1.FileName, fmOpenRead);
    try
      T.Load(F);
      ShowMessage(T.Announce + #13#10 + T.CreatedBy + #13#10 + T.CreationDateAsString);
    finally
      T.Free;
      F.Free;
    end;
  end;
end;

jaenicke 8. Apr 2014 19:35

AW: Project from Ansi to Unicode
 
After a quick look I think you just have to replace String with AnsiString and PChar with PAnsiChar inside the unit.

WojTec 9. Apr 2014 19:02

Re: Project from Ansi to Unicode
 
Liste der Anhänge anzeigen (Anzahl: 1)
So, I made some modifications, result attached, but don't working as expected, eg. name is empty or length is zero or wrong hash, but announce or agent are good. :wall: Same project on Ansi compiler is oke :pale:

jaenicke 9. Apr 2014 20:20

AW: Project from Ansi to Unicode
 
You forgot to exchange Char with AnsiChar in unit BCode. If I do so it works.

WojTec 10. Apr 2014 09:26

Re: Project from Ansi to Unicode
 
Yap, I forgot :oops: Thank you, now working :-D

But now there is next problem, because can use Unicode in file names and unit is Ansi, can't read Unicode names. I saw maybe 2 times Unicode torrents, but it is possible. How to enable support for Unicode strings inside?

Here Torrent_file#File_structure is information that strings are Unicode at all. Now I don't understand, why Ansi is working, but Unicode is not working :?:

jaenicke 10. Apr 2014 14:26

AW: Project from Ansi to Unicode
 
You find the answer in your own link:
Zitat:

All strings must be UTF-8 encoded.
Perhaps it already works, if you use UTF8String instead of AnsiString, but perhaps you have to decode the UTF-8 format explicitly or perhaps it has to be read differently (I did not have a look now). Delphi uses UTF-16, so it does not understand UTF-8, if you don't tell it to read something as UTF-8.

WojTec 10. Apr 2014 16:49

Re: Project from Ansi to Unicode
 
Exchange type Ansi to UTF8 is working, but what with PAnsiChar typecast and AnsiChar (working, but there is no additional UTF8 routines required?)?

WojTec 10. Apr 2014 17:41

Re: Project from Ansi to Unicode
 
Also another question: has Delphi build-in routines to replace Hashes.pas unit?


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:24 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz