ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Opening unicode file names with Delphi 2007
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AndyColmes

USA
351 Posts

Posted - Feb 25 2014 :  12:51:49  Show Profile  Reply
I am having issues with files that have Unicode file names like Japanese when I try to load them into a TImageEnView using LoadFromFile in Delphi 2007. Is there any way to open such files?

Thanks for any help.

Andy

Samples:
http://uploaded.net/file/cvo2at0z

w2m

USA
1990 Posts

Posted - Feb 25 2014 :  13:18:38  Show Profile  Reply
I think you need Delphi 2010 or higher to support Unicode.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Custom ImageEn Development

Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Feb 25 2014 :  14:41:10  Show Profile  Reply
Is it possible to create a small exe or dll that is compiled with XE so that it supports Unicode to load the Unicode file name and then save it to a regular English file name. I would call this exe or dll from within the Delphi 2007 to get the converted file name. Do you foresee any complications from doing it this way, at least until the whole application gets converted to XE in the future.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 25 2014 :  14:52:38  Show Profile  Reply
I am not sure because I never tried it.... but I suspect it will fail. A Unicode string in Delphi 2010 or higher is string. In Delphi 2007 string is AnsiString. I suspect that you can not just assign the string from Unicode to an AnsiString. Someone other than I with a lot more knowledge about Unicode may be able to help. You could also post to stackoverflow.com. There are a bunch of developers there that could could answer this better than I can. I do know that almost everyone has said to update the IDE and the problem is solved.

I am not sure if TMS still sells the Unicode components, but if it has a Unicode OpenPictureDialog you might be able to get the filename that way.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Custom ImageEn Development
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Feb 25 2014 :  14:56:58  Show Profile  Reply
How about using streams returned from a dll? Can streams from a Unicode dll be returned to the application?
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 25 2014 :  18:47:27  Show Profile  Reply
I just checked and the TMS Unicode Components do include TTntOpenDialog
TTntSaveDialog

You should be able to use these to get filenames,, although I do not own them nor have I tested them.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Custom ImageEn Development
Go to Top of Page

spetric

Croatia
308 Posts

Posted - Feb 26 2014 :  01:42:32  Show Profile  Reply
I have the same problem (BCB6). I've search around and found that it can be solved using Win APIs to get widestring path and then to convert it to ansistring.

However, the easier way is to switch to newer Delphi/Builder version (sooner the better). Although my company recently both XE5 and ImageEn 5.0.5, the transition is not so smooth, as too many versions were skipped.

Edit: There are free Tnt components with unicode support available:

http://www.axolot.com/TNT/

Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Feb 26 2014 :  07:54:18  Show Profile  Reply
I am using TntOpenDialog to open the Unicode file name but somehow it still gives me the error.
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Feb 26 2014 :  07:58:45  Show Profile  Reply
The error is actually in ImageEn's TImageEnView using LoadFromFile.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 26 2014 :  08:17:21  Show Profile  Reply
Maybe if you show your code we can look at it.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Custom ImageEn Development
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Feb 26 2014 :  11:25:08  Show Profile  Reply
Not much to the code, except that it is in Delphi 2007. All I want is to be able to load it into a TImageEnView and save it another file with a known filename. The file that I am loading is one of the sample files I uploaded above:

procedure TLoadMatchForm.BmpConvert(Infile,Outfile: Widestring);
var
ImageEnView: TImageEnView;
begin
Screen.Cursor := crHourGlass;

ImageEnView := TImageEnView.Create(Self);
try
ImageEnView.IO.LoadFromFile(Infile);
finally
ImageEnView.Update;
ImageEnView.IO.SaveToFile(Outfile);
ImageEnView.Free;
Screen.Cursor := crDefault;
end;
end;

Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Feb 26 2014 :  11:56:54  Show Profile  Reply
It seems that I need to use CreateFileW() to convert the file first before loading it into TImageEnView. Any idea on how to use CreateFileW() in Delphi?
Go to Top of Page

xequte

38615 Posts

Posted - Feb 26 2014 :  11:58:13  Show Profile  Reply
Hi Andy

I have not specifically tested this, but as LoadFromFile supports a Widestring, it should work as long as it is passed a valid widestring filename. Have you checked the validity of the filename using another method (that supports widestring).

Also, try loading the image into ImageEn using its 8.3 filename.

If you have a newer Unicode version of Delphi, then you could easily create a DLL for file conversion.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 26 2014 :  12:07:03  Show Profile  Reply
Not sure but maybe this will help.
{:Converts Unicode string to Ansi string using specified code page.
   @param   ws       Unicode string.
   @param   codePage Code page to be used in conversion.
   @returns Converted ansi string.
 }

function WideStringToString(const ws: WideString; codePage: Word): AnsiString;
var
   l: integer;
begin
   if ws = ' then
     Result := '
   else 
   begin
     l := WideCharToMultiByte(codePage,
       WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR,
       @ws[1], - 1, nil, 0, nil, nil);
     SetLength(Result, l - 1);
     if l > 1 then
       WideCharToMultiByte(codePage,
         WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR,
         @ws[1], - 1, @Result[1], l - 1, nil, nil);
   end;
end; { WideStringToString }


 {:Converts Ansi string to Unicode string using specified code page.
   @param   s        Ansi string.
   @param   codePage Code page to be used in conversion.
   @returns Converted wide string.
 }
function StringToWideString(const s: AnsiString; codePage: Word): WideString;
var
   l: integer;
begin
   if s = ' then
     Result := '
   else 
   begin
     l := MultiByteToWideChar(codePage, MB_PRECOMPOSED, PChar(@s[1]), - 1, nil, 0);
     SetLength(Result, l - 1);
     if l > 1 then
       MultiByteToWideChar(CodePage, MB_PRECOMPOSED, PChar(@s[1]),
         - 1, PWideChar(@Result[1]), l - 1);
   end;
end; { StringToWideString }

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Custom ImageEn Development
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Feb 26 2014 :  12:37:08  Show Profile  Reply
I am passing a Widestring filename to TImageEnView from TntOpenDialog which is Unicode in Delphi 2007. But TImageEnView gives the "Floating point division by zero" error when trying to SaveToFile, as you can see my code snippet.

Any idea why?
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 26 2014 :  12:58:47  Show Profile  Reply
What does the string look like when it is returned by the dialog? Is it a valid file path? Also... does the file open correctly? Try doing it in two steps... LoadFromFile to test if it loads correctly, then a second step to save the file. Is the outfile string a valid path?

William Miller
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Feb 26 2014 :  14:55:43  Show Profile  Reply
Hello all, it was not an ImageEn issue after all. TImageEnView loads and saves the file just fine. My issue was that the TTntOpenDialog was not really TTntOpenDialog but TOpenImageEnDialog which did not return a valid filename since it is not Widestring. Thank you everyone for helping and sorry for the confusion.
Go to Top of Page

yogiyang

India
727 Posts

Posted - Feb 28 2014 :  04:50:21  Show Profile  Reply
I am not sure but try out TNT Unicode controls and its code.

It many help.

http://www.yunqa.de/delphi/doku.php/products/tntunicodecontrols/index

Also check out Mormot. The developer of this open source lib seems to be able to handle UNICODE well. http://synopse.info/fossil/wiki/Synopse+OpenSource

I have not tested or used any of these UNICODE solutions as I have never found the need to use them. But I would advise you to check them. Who know they may prove to be useful to you.

Regards,



Yogi Yang
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Mar 02 2014 :  06:47:46  Show Profile  Reply
Thanks very much Yogi. Mormot seems like a good thing to have.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: