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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Opening unicode file names with Delphi 2007

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
AndyColmes Posted - Feb 25 2014 : 12:51:49
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
18   L A T E S T    R E P L I E S    (Newest First)
AndyColmes Posted - Mar 02 2014 : 06:47:46
Thanks very much Yogi. Mormot seems like a good thing to have.
yogiyang Posted - Feb 28 2014 : 04:50:21
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
AndyColmes Posted - Feb 26 2014 : 14:55:43
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.
w2m Posted - Feb 26 2014 : 12:58:47
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
AndyColmes Posted - Feb 26 2014 : 12:37:08
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?
w2m Posted - Feb 26 2014 : 12:07:03
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
xequte Posted - Feb 26 2014 : 11:58:13
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
AndyColmes Posted - Feb 26 2014 : 11:56:54
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?
AndyColmes Posted - Feb 26 2014 : 11:25:08
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;

w2m Posted - Feb 26 2014 : 08:17:21
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
AndyColmes Posted - Feb 26 2014 : 07:58:45
The error is actually in ImageEn's TImageEnView using LoadFromFile.
AndyColmes Posted - Feb 26 2014 : 07:54:18
I am using TntOpenDialog to open the Unicode file name but somehow it still gives me the error.
spetric Posted - Feb 26 2014 : 01:42:32
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/

w2m Posted - Feb 25 2014 : 18:47:27
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
AndyColmes Posted - Feb 25 2014 : 14:56:58
How about using streams returned from a dll? Can streams from a Unicode dll be returned to the application?
w2m Posted - Feb 25 2014 : 14:52:38
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
AndyColmes Posted - Feb 25 2014 : 14:41:10
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.
w2m Posted - Feb 25 2014 : 13:18:38
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