Recent

Author Topic: [SOLVED]Problem with accented characters in folder name  (Read 8259 times)

rocka1

  • New Member
  • *
  • Posts: 21
[SOLVED]Problem with accented characters in folder name
« on: July 16, 2012, 01:26:49 pm »
When trying to run an application on Windows Mobile, I have to confirm where's the data file, I also have to load it later and so I have to indicate the path ...

When creating the application in the emulator I do the tests in English version of WinMobile, when tested with a mobile version in Portuguese, "kaput!"

I did some tests, like:

Code: [Select]
Showmessage(ExtractFilePath (Application.ExeName));
Gives error, the application is in Storage Card ("Cartão de Memória" in  portuguese), and the result is:

\Cart?o de Mem?ria\Test12\....

And then, of course, this also fails:

Code: [Select]
if FileExists(ExtractFilePath(Application.ExeName)+'test.db') then
And so on ...

Code: [Select]
Mypath:=ExtractFilePath(Application.ExeName)+'test.db';
It's clear that the problem is due to the accented characters.

If someone runs the application on portuguese WinMobile and put the app in the Storage Card, the app will never work ...

Someone with a solution for these cases?

Thank you
« Last Edit: July 21, 2012, 10:04:25 pm by rocka1 »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Problem with accented characters in folder name
« Reply #1 on: July 16, 2012, 05:16:37 pm »
This should work though?
Code: [Select]
if FileExists('test.db') then
At some point i stopped putting full path on anything in Lazarus projects. I haven't had any issues with it, it's like guaranteed to be in executable folder always.

Also, there are FileExistsUTF8 and other UTF8 there for accented characters.
« Last Edit: July 16, 2012, 05:20:47 pm by User137 »

rocka1

  • New Member
  • *
  • Posts: 21
Re: Problem with accented characters in folder name
« Reply #2 on: July 16, 2012, 05:42:19 pm »
This should work though?
Code: [Select]
if FileExists('test.db') then
At some point i stopped putting full path on anything in Lazarus projects. I haven't had any issues with it, it's like guaranteed to be in executable folder always.

Also, there are FileExistsUTF8 and other UTF8 there for accented characters.

Unfortunately works on win32, but in wince without giving full path does not work.

rocka1

  • New Member
  • *
  • Posts: 21
Re: Problem with accented characters in folder name
« Reply #3 on: July 18, 2012, 03:34:42 am »
Well, I was wrong, I found that the problem was further ahead, not in Fileexists and the full path, but in SQLite3Connection1,
where I have to give the full path ...

I think I have a "smart" solution, not a beautiful code, but i think will work
Cannot test right now on a real Pda, my and the emulator are in English
Tested with a subfolder named " Cartão de Memória" in the emulator

Something like this :

Code: [Select]
var
  bu:TSQLite3Backup;
  File1:AnsiString;   
Begin
Edit2.Text:=ExtractFilePath(Application.ExeName);
if pos('Cart?o de Mem?ria',Edit2.Text)>0 then Edit2.Text:= AnsiReplaceStr(Edit2.Text,'Cart?o de Mem?ria','Cartão de Memória'); 
...
...
bu.Restore(Edit2.Text+'test.db',SQLite3Connection1);
.....
.....
end;

Edit2.text is hidden.

Strange, if I replace edit2.text by "File1" , declared in var,  it doesn't work, only with the text in the Tedit ..

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Problem with accented characters in folder name
« Reply #4 on: July 18, 2012, 01:59:39 pm »
It is a caracteristic of the platform. Pathes always need to be complete in WinCE.

ezlage

  • Sr. Member
  • ****
  • Posts: 284
  • (Silêncio)
    • Lageteck
Re: Problem with accented characters in folder name
« Reply #5 on: July 18, 2012, 02:22:49 pm »
I remember of a problem like this, I solved by changing the CharSet property of the DataSet at run-time and using the DataSet to get the path (FilePathFull or FilePath).
It worked, but I just had bypassed the issue.

Regards.
Sorry by my poor english.

Atenciosamente,

Ezequiel Lage
ezequiel@lageteck.com

https://github.com/ezlage

rocka1

  • New Member
  • *
  • Posts: 21
Re: Problem with accented characters in folder name
« Reply #6 on: July 18, 2012, 04:18:06 pm »
I found this code, ...

This trick can be very usefull, If anyone want to convert to pascal ...

From :
http://www.codeproject.com/Articles/161388/Windows-Mobile-Programming-Tricks-on-the-NET-Compa

Quote
Get the names of all storage cards

Some devices may have several storage cards installed in them.
What's even more important is that the storage cards don't necessarily have to be named \Storage Card.
To iterate through all storage cards, we don't even need to use any Platform Invokes.
The trick is to find all folders which have the Temporary attribute set.
The code is very simple:
Code: [Select]
static public List<string> GetStorageCardNames()
{
    DirectoryInfo rootInfo = new DirectoryInfo("\\");
    List<string> paths = new List<string>();

    foreach (DirectoryInfo dirInfo in rootInfo.GetDirectories())
    {
        if ((dirInfo.Attributes & FileAttributes.Temporary) != 0)
        {
            //Debug.WriteLine("Directory Name: " + dirInfo.Name)
            //Debug.WriteLine("     Full Name: " + dirInfo.FullName)
            paths.Add(dirInfo.FullName);
        }
    }

    return paths;
}

rocka1

  • New Member
  • *
  • Posts: 21
[SOLVED] Re: Problem with accented characters in folder name
« Reply #7 on: July 21, 2012, 10:04:00 pm »
Done :

AnsiToUtf8(ExtractFilePath(Application.ExeName)

Now, instead of "Cart?o de mem?ria" the result is : "Cartão de memória"

« Last Edit: July 21, 2012, 10:18:53 pm by rocka1 »