Recent

Author Topic: Help with OLE Automation and Unicode  (Read 4668 times)

mudah

  • New Member
  • *
  • Posts: 13
Help with OLE Automation and Unicode
« on: July 24, 2011, 09:54:10 am »
Hello,

I have problem using OLE Automation and Unicode input. Below code used to get object count for given folder. It's working fine with ASCII folder name but not on folder name with  UTF-8 / Unicode character (Thai, Japanese, Tamil).

Code: [Select]
function getFolderItemCount (sFolder: variant): integer;
var
   vServer, vFolder, vFolderItem: variant;
   iResult: integer;

begin

    CoInitialize(nil);

    try
    vServer := CreateOleObject('shell.application');

    except
        ShowMessage('error');
    end;

    vFolder := vServer.NameSpace(sFolder);
    vFolderItem := vFolder.Items; //<-- Error Here: Exception Class External SIGSEGV

    iResult:= vFolderItem.Count;

    CoUnInitialize;

    Result:= iResult


end;

Please help me!

Thanks.

Laksen

  • Hero Member
  • *****
  • Posts: 656
    • J-Software
Re: Help with OLE Automation and Unicode
« Reply #1 on: July 24, 2011, 01:37:59 pm »
I get the error. But it's because NameSpace returns nil. I guess something about the encodings aren't done correctly
Code: [Select]
   vFolder := vServer.NameSpace(sFolder);
   if not VarIsClear(vFolder) then
   begin
      vFolderItem := vFolder.Items;

      iResult:= vFolderItem.Count;
   end;

mudah

  • New Member
  • *
  • Posts: 13
Re: Help with OLE Automation and Unicode
« Reply #2 on: July 24, 2011, 05:41:59 pm »
Thanks Laksen

I tried to convert param to unicode/utf8 before sending to the function. But still can't get trough.

Example..


var
callingVar: widestring;

begin
ShowMessage(IntToStr(getFolderItemCount(callingVar));
end;

Also

var
callingVar: string;

begin
ShowMessage(IntToStr(getFolderItemCount(UTF8ToSys(callingVar)));
end;



Any proper solution to correctly parse unicode/utf8 to OLE variant?
« Last Edit: July 24, 2011, 05:47:46 pm by mudah »

 

TinyPortal © 2005-2018