Tuesday, November 4, 2014

UTF8 unicode long path HACK [WINDOWS]

function ShortFileName (const FileName: WideString): Widestring;
    var aTmp: WideString;
    begin
      SetLength(aTmp,255);
      if Windows.GetShortPathNameW (PWideChar (FileName), @aTmp[1], 254) = 0
      then
        Result:= FileName
      else
        Result:=aTmp;
    end;

HOW TO USE:

 
procedure TForm1.Button1Click(Sender: TObject);
var sn:String;
begin
 If OpenDialog1.Execute then
 begin
   sn:=ShortFileName(UTF8Decode(OpenDialog1.FileName));
   Caption:=sn;
   if FileExists(sn) then Memo1.Lines.LoadFromFile(sn);
 end;
end;
 
Or
 
hiddenImage.Picture.LoadFromFile(UTF8ToConsole(ShortFileName(UTF8Decode('C\imagefiles.jgp'))));