Author |
Topic |
|
AndyColmes
USA
351 Posts |
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
|
|
w2m
USA
1990 Posts |
|
AndyColmes
USA
351 Posts |
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
USA
1990 Posts |
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
USA
351 Posts |
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
USA
1990 Posts |
|
spetric
Croatia
308 Posts |
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/
|
|
|
AndyColmes
USA
351 Posts |
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. |
|
|
AndyColmes
USA
351 Posts |
Posted - Feb 26 2014 : 07:58:45
|
The error is actually in ImageEn's TImageEnView using LoadFromFile. |
|
|
w2m
USA
1990 Posts |
|
AndyColmes
USA
351 Posts |
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;
|
|
|
AndyColmes
USA
351 Posts |
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? |
|
|
xequte
38615 Posts |
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
|
|
|
w2m
USA
1990 Posts |
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 |
|
|
AndyColmes
USA
351 Posts |
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
USA
1990 Posts |
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
USA
351 Posts |
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. |
|
|
yogiyang
India
727 Posts |
|
AndyColmes
USA
351 Posts |
Posted - Mar 02 2014 : 06:47:46
|
Thanks very much Yogi. Mormot seems like a good thing to have. |
|
|
|
Topic |
|