Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What i really don't understand about Unicode (Delphi 2k9, 2k10, XE)

Posted on 2010-09-01
11
Medium Priority
?
1,184 Views
Last Modified: 2013-11-23
Hello Everybody!

Hey, sometime ago i asked about UNICODE and at that moment i really didnt need switch to UNICODE... i was using Delphi 2007 and skip the use of Delphi 2009/2010 since its UNICODE by default, make the app size greater and a little hard to convert all my codes...

But, there are things that i really don't understand... for example

Well, String become UnicodeString by the compiler... (UnicodeString is reference counted by Delphi instead of WideString... so UnicodeString has more performance) Char -> WideChar, PChar -> PWideChar and more

But, a lot of Windows functions/procedures still use "PAnsiChar" and others "PWideChar"... but why not use PWideChar them? And still using PAnsiChar?

Example WinExec uses PAnsiChar, its because in a PATH there is no Unicode Strings? (C:\Windows\Some Folder)
If true, then all my functions/procedures that will not support unicode characteres i must use "PAnsiChar" instead of PChar?

example, a DLL that return the instalattion path of my program

function GetInstallPath(lpBuffer: PAnsiChar): Integer; StdCall;

My doubt is, when to use or not UNICODE in the code!
and Windows will drop the support for ANSI futurelly?

Best Regards,
Carlos
0
Comment
Question by:cebasso
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 13

Accepted Solution

by:
aflarin earned 668 total points
ID: 33577178
Some of Win32 API functions have two version A (Ansi) and W (Unicode). But some of Win32 API functions have only one version A or W. You always can check MSDN site and see if function has Ansi or/and Unicode version.

WinExec is old function and it hasn't Unicode version.
http://msdn.microsoft.com/en-us/library/ms687393(VS.85).aspx

But if you check CreateProcess you'll find that it has:
http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx
Unicode and ANSI names      CreateProcessW (Unicode) and CreateProcessA (ANSI)

>> My doubt is, when to use or not UNICODE in the code!

If you use your Delphi version >= 2009, I think it'll be easier to use Unicode than Ansi.

But if you develop dll and it will be use from non-Unicode program - you have to use Ansi

>> Windows will drop the support for ANSI futurelly?

Probably, by I don't think it will be soon
0
 
LVL 25

Assisted Solution

by:epasquier
epasquier earned 668 total points
ID: 33577493
One general advice :
* You use String, Char & PChar in all general use, in your application core.
Depending on Delphi version, it will be the ANSI or Wide (Unicode) flavour that will be used at compile time, throughout all your VCL code. All managed as it should be, no unnecessary conversions.

* You use PANSIChar explicitly for all your dll interfaces, or the few places where you can't do otherwise because some API NEED it

* You probably won't need to use Unicode or PWideChar explicitly, except if you use some 3rd party components that fix it (and you still want to compile with Delphi <2009)

Same goes for the windows API : use the functions without A or W suffix, and let Delphi choose the one that will be used. That will work nicely if you didn't fixed in your code pANSIChar type for example, but only use pChar as I explained before.

If you follow these strict rules, you won't have many problems to compile your code in different Delphi versions, and will also reduce your future problems if something irremediably change in next Windows (but as aflarin said, I very much doubt that this will occur in the next decade)
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 33578014
Don't forget  you can code in native Chinese or Japanese in the IDE !
That's if you know the language ... :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:epasquier
ID: 33578708
How do you code in Chinese ?? You mean insert Chinese text properties & constant, not writing code in Chinese ? translated keywords ? or only identifiers ?
I hope I will never cross some Chinese code with chinese identifiers. I already had to work with IPX unit in german, that was hard enough for me
0
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 664 total points
ID: 33580614
i got some text of al jazeera and created a new type and execute method:

it'll be a bit harder reading delphi code in the future

but that shows what you can do with unicode in the ide
aljazeera.png
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 33580651
and don't ask what the translation is
it's in hebrew
0
 
LVL 4

Author Comment

by:cebasso
ID: 33580898
Heyy thank you all for reply!
@aflarin
For my DLLs, as its shared to others developers... i'll make like Windows does, an A and W version for each shared function/procedure and for structs something like
TMyStructA and TMyStructW using cbSize to check what kind of struct the addon is using...
In A struct, of course i will keep as AnsiChar and for W Char...
Examples
TMyStructA = record
  cbSize: DWORD;
  chSomething: array [0..10] of AnsiChar;
end;

TMyStructW = record
  cbSize: DWORD;
  chSomething: array [0..10] of Char; //will be widechar Delphi >= 2009
end;
the compiler probably will be Delphi XE so buying the licence i can use any Delphi version from 2007 as i read in embarcadero website

@epasquier
Cool... so for each func/proc i'll release a A and W way too
example

function GetInstallPathA(lpBuffer: PAnsiChar; var nBuffSize: DWORD): Integer; StdCall;
function GetInstallPathW(lpBuffer: PChar; var nBuffSize: DWORD); Integer; StdCall;
not tested yet, i downloaded Delphi XE to test everything of this... since many things will change... wait, more answers will come hahaha
@Geert_Gruwez
Fantastic!! and i think that it will be more dificulty to crackers?
instead of "isTrial" now i can use something like "¿¿¿¿¿¿¿"

function ¿¿¿¿¿¿¿: Boolean;
Haha, it was just an example, not necessary "isTrial" that i use =)

Is that true that making things in Arabic, except if the cracker know the language of course, will be more dificulty?

sorry if it's bullshit =X

I really don't know exactly how to crack a program, so reading articles over the web, many times i saw to not make stupid functions like "isTrial', "isActivated", etc

Cheers!
0
 
LVL 4

Author Comment

by:cebasso
ID: 33580927
ops... imagine that "¿¿¿¿¿¿¿" is something in Arabic language since it'snt displayed here (content="text/html; charset=UTF-8" Encoding) ;)
0
 
LVL 25

Expert Comment

by:epasquier
ID: 33581079
> Is that true that making things in Arabic, except if the cracker know the language of course, will be more dificulty?

No, not with compiled code that don't include debug information. Your arabic names would be removed and impossible to recover, so not much better than function ThisIsTheRegisterCheck:Boolean .

So no problems with Delphi, you can - and must - use significant names and will work better with no loss of security. Except if your source code is robbed, but that is another issue.

With C#, on the other hand, I think it most of the time include all the identifier names somewhere, except if you run some special tools to remove or obfuscate.
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 33581081
cebasso, i had to use a image to be able to show the arabic chars
doesn't work on this site to show other language chars

forgive me, but in america, they only need spanish, portugese, english, french and a little dutch
(those are all eu and ex colonies chars )
this post may already be scanned by the fbi or cia, just because i put al jazeera
i already took a holiday for 2 days, just in case the feds show up at work ... but don't tell them

and don't say there isn't americans in belgium
they are even storing nuclear weapons here in kleine brogel
0
 
LVL 4

Author Comment

by:cebasso
ID: 33581441
@epasquier
Ahh ok! Then i really prefer to use normal names :D
If you had said yes, probably now i would be changing my codes to arabic or at least put in my TODO list haha
@Geert_Gruwez

HAHA LOL! talking about a holiday... who need a holiday is me... i'm being crazy about unicode and 70% of components that i use isn't working on Delphi XE :(
Thank you all guys :D
See you in the next question haha

Cheers!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question