Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Delphi does support unicode in the compiler by using WideString.</p> <p>But you'll face the following problems:</p> <ul> <li>Delphi &lt; 2009 does not support unicode in their VCL.</li> <li>A lot of API mapping is done on the ANSI (OpenFileA for instance) variants of the API.</li> <li>The delphi compiler will convert the WideStrings to a string a lot, so be very explicit about them.</li> </ul> <p>It will work if you use the raw unicode windows api's.</p> <p>So FindFirst uses the api <a href="http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx" rel="nofollow noreferrer">FindFirstFile</a> which delphi maps to the FindFirstFileA variant, and you'll need to directly call FindFirstW.</p> <p>So you'll have 2 options.</p> <ol> <li>Upgrade to Delphi 2009 and have a lot of unicode mapping done for you <ul> <li>Write your own unicode mapping functions</li> </ul></li> </ol> <p>For the text file writing you might be able to use the <a href="http://gp.17slon.com/gp/gptextfile.htm" rel="nofollow noreferrer">GpTextFile</a> or <a href="http://gp.17slon.com/gp/gptextstream.htm" rel="nofollow noreferrer">GpTextSteam</a> by Primoz Gabrijelcic (aka gabr), they have unicode support.</p> <p>Her is an example of opening a file with a unicode filename:</p> <pre><code>function OpenLongFileName(const ALongFileName: WideString; SharingMode: DWORD): THandle; overload; begin if CompareMem(@(WideCharToString(PWideChar(ALongFileName))[1]), @('\\'[1]), 2) then { Allready an UNC path } Result := CreateFileW(PWideChar(ALongFileName), GENERIC_READ, SharingMode, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0) else Result := CreateFileW(PWideChar('\\?\' + ALongFileName), GENERIC_READ, SharingMode, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); end; function CreateLongFileName(const ALongFileName: WideString; SharingMode: DWORD): THandle; overload; begin if CompareMem(@(WideCharToString(PWideChar(ALongFileName))[1]), @('\\'[1]), 2) then { Allready an UNC path } Result := CreateFileW(PWideChar(ALongFileName), GENERIC_WRITE, SharingMode, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0) else Result := CreateFileW(PWideChar('\\?\' + ALongFileName), GENERIC_WRITE, SharingMode, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); end; </code></pre> <p>I've used these functions because the ANSI api's have a path limit of 254 chars, the unicode have a limit of 2^16 chars if I'm not mistaken.</p> <p>After you've got the handle to the file you can just call the regular ReadFile delphi api mapping, to read data from your file.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload