Hi all,
I thought I posted this, but maybe I wrote it and forgot to post. Apologies if you find the other one
Firstly I need to do this because:
It's Delphi to FPC and now Strings are Unicode strings and pChars are actually pWideChars
It's in a DYLIB that is used by C/C++ so the only parameters to be safe, are integer, boolean and pWideChar
The C++ calling routine uses Char IIRC which maps to pWideChar
So again, not being narked. but don't need any questions like 'why?', it just is.
I have looked at the posts and Wiki and what I am doing 'should' work. I'm trying to be as compatible with the current (10.3.xx) version of Delphi which is what I am converting from. So here's the theory, strings are unicode string type therefore setting x: string means x is a unicode string and and if I have a Edit then the text Edit.Text is also a string ergo it should be a unicode string (see {$MODE DelphiUnicode}).
My issue:
- I have set the compiler directive {$MODE DELPHIUNICODE}
- Stings are AFAICT unicode strings
- I thought I could just cast a unicode String to a pWideChar
var
loginemail: pWideChar;
...
...
WriteLog('DEBUG', 'Unicode String checkUserStatusEmailEdit.Text: ' + checkUserStatusEmailEdit.Text); // shows gobbledygook
loginemail := pWideChar(checkUserStatusEmailEdit.Text); // loginemail is pWideChar xxx.Text is Unicode (Wide) string
WriteLog('DEBUG', 'pWideChar Loginemail: ' + loginemail); // has been cast to pWideChar and is crap
WriteLog('DEBUG', 'Unicode String Loginemail: ' + string(loginemail));
And noting that string 'should' be a unicode string as should the TEdit of checkUserStatusEmailEdit.Text (just an input field). This is what I get:
[2019-03-19 11:45:23] DEBUG [EMPServerTest] Unicode String checkUserStatusEmailEdit.Text: dbid:AAD4_bi4MP1qQDCvIciNh3x-9sa3bciOtRA
[2019-03-19 11:45:26] DEBUG [EMPServerTest] pWideChar Loginemail: 扤摩䄺䑁弴楢䴴ㅐ共䍄䥶楣桎砳㤭慳戳楣瑏䅒栀䔮偍敓畣敲
[2019-03-19 11:45:27] DEBUG [EMPServerTest] Unicode String Loginemail: 扤摩䄺䑁弴楢䴴ㅐ共䍄䥶楣桎砳㤭慳戳楣瑏䅒栀䔮偍敓畣敲
BUT if I do this (I simply copy checkUserStatusEmailEdit.Text to a string variable (LE)) everything is goodness:
var
loginemail: pWideChar;
LE: string;
...
...
WriteLog('DEBUG', 'Unicode String checkUserStatusEmailEdit.Text: ' + checkUserStatusEmailEdit.Text); // shows gobbledygook
LE := checkUserStatusEmailEdit.Text;
Loginemail := pWideChar(LE);
WriteLog('DEBUG', 'pWideChar Loginemail: ' + loginemail); // has been cast to pWideChar and is crap
WriteLog('DEBUG', 'Unicode String Loginemail: ' + string(loginemail));
I get this (perfectly):
[2019-03-19 11:43:09] DEBUG [EMPServerTest] Unicode String checkUserStatusEmailEdit.Text: dbid:AAD4_bi4MP1qQDCvIciNh3x-9sa3bciOtRA
[2019-03-19 11:43:11] DEBUG [EMPServerTest] pWideChar Loginemail: dbid:AAD4_bi4MP1qQDCvIciNh3x-9sa3bciOtRA
[2019-03-19 11:43:12] DEBUG [EMPServerTest] Unicode String Loginemail: dbid:AAD4_bi4MP1qQDCvIciNh3x-9sa3bciOtRA
So my question (in several parts):
If I have {$MODE DelphiUnicode} does that ONLY apply to type 'string' and NOT to the result of say any component, ie a TEdit text like Edit.text IS AN ANSISTRING OR A WIDESTRING, but not a Unicode string (I understand Widestring and Unicodestring are not the same)?
And is that because the TEDIT has not been built with {$MODE DelphiUnicode} (clutching at straws here)?
And could I build the IDE with etc with {$MODE DelphiUnicode}?
Thanks