Lajos Juhász 293 Posted March 27, 2023 There is no "unicode" set in Delphi. Using CharInSet will only work on Ansi. For example on my Windows this will not show true on my laptop: procedure TForm1.FormCreate(Sender: TObject); var a: char; s: string; begin a:='њ'; if CharInSet(a, ['њ', 'а', 'м']) then ShowMessage('true'); end; Here is the reason: [dcc32 Warning] Unit1.pas(32): W1061 Narrowing given WideChar constant (#$045A) to AnsiChar lost information [dcc32 Warning] Unit1.pas(32): W1061 Narrowing given WideChar constant (#$0430) to AnsiChar lost information [dcc32 Warning] Unit1.pas(32): W1061 Narrowing given WideChar constant (#$043C) to AnsiChar lost information Share this post Link to post
Lajos Juhász 293 Posted March 27, 2023 2 minutes ago, Fr0sT.Brutal said: Btw, I wonder how do you check whether a char is a letter of a some language (f.ex. Norwegian, German)? They have not only latin chars but some additional which can't be declared with simple 'a'..'z'. You have to add them explicitly, like 'a'..'z', 'æ'? That's easy for me. I use FireDAC with settings to string fields to widestring (unicode). When writing back the data firedac requires that windows is set for non unicode language to be the correct codepage (simply ignores client and db codepage). Thus I know for sure that if I convert a unicode string it will use the correct codepage. This is going to work until the database is using code page. Share this post Link to post
Lars Fosdal 1791 Posted March 27, 2023 2 minutes ago, Fr0sT.Brutal said: I wonder how do you check whether a char is a letter of a some language (f.ex. Norwegian, German)? They have not only latin chars but some additional which can't be declared with simple 'a'..'z'. You have to add them explicitly, like 'a'..'z', 'æ'? Like the latter, yes. Then there is the question of codepage. What if we combine Unicode characters that are not available in the same codepage in the same set of ansi characters? I guess that will fail. AnsiString has codepage declaration support - but AnsiChar does not. Relevant read: Marco's Tech Paper https://www.embarcadero.com/images/dm/technical-papers/delphi-and-unicode-marco-cantu.pdf 10 minutes ago, Fr0sT.Brutal said: They couldn't. Set is limited to 255 elements True - but look at InOpArray. Technically it would be possible to have a in operator that checks if a value exists in an array that would be syntactically identical to value in set. Whether it would be efficient or not with even more compiler magic is questionable. Share this post Link to post
Fr0sT.Brutal 900 Posted March 27, 2023 (edited) 2 hours ago, Lajos Juhász said: That's easy for me. I use FireDAC with settings to string fields to widestring (unicode). When writing back the data firedac requires that windows is set for non unicode language to be the correct codepage (simply ignores client and db codepage). Thus I know for sure that if I convert a unicode string it will use the correct codepage. No, this was a non-DB-related question, just curiosity. While there is IsLetter function, it checks for all letters in Unicode table so I wondered which constructions are popular for the purpose. 2 hours ago, Lars Fosdal said: What if we combine Unicode characters that are not available in the same codepage in the same set of ansi characters? I guess that will fail. AnsiString has codepage declaration support - but AnsiChar does not. Yes, that's possible. CharInSet won't check whether a char is ASCII or not and codepage-dependent cases are possible that won't produce neither compile-time messages nor run-time errors. Alas, I can't imagine how they could force the check. Runtime exception in such a basic function doesn't look good True - but look at InOpArray. Technically it would be possible to have a in operator that checks if a value exists in an array that would be syntactically identical to value in set. Whether it would be efficient or not with even more compiler magic is questionable. Sounds nice, create request to QC? 🙂 Edited March 27, 2023 by Fr0sT.Brutal Share this post Link to post
Lajos Juhász 293 Posted March 27, 2023 23 minutes ago, Fr0sT.Brutal said: No, this was a non-DB-related question, just curiosity. The FD reference was just to give context the reason why I have to lock all my users to a specific code page (also a nice example a problem when you're dealing with an ansi database using Delphi). 24 minutes ago, Fr0sT.Brutal said: CharInSet won't check whether a char is ASCII or not and codepage-dependent cases are possible that won't produce neither compile-time messages nor run-time errors it will: [dcc32 Warning] Unit1.pas(32): W1061 Narrowing given WideChar constant (#$045A) to AnsiChar lost information 25 minutes ago, Fr0sT.Brutal said: Runtime exception in such a basic function doesn't look good There is no runtime problem. The compiler will try to convert unicode string to ansistring, code points that cannot be represent in ansistring will be replaced with ? a well known behavior of windows. Share this post Link to post
David Schwartz 426 Posted March 27, 2023 There are also the functions in StrUtuils like IndexText/Str and ContainsText/Str Share this post Link to post
Fr0sT.Brutal 900 Posted March 27, 2023 3 hours ago, Lajos Juhász said: it will: Ah, you're right. Nice, the compiler is a bit more clever than I thought Share this post Link to post
Lars Fosdal 1791 Posted March 27, 2023 4 hours ago, Fr0sT.Brutal said: 6 hours ago, Lars Fosdal said: True - but look at InOpArray. Technically it would be possible to have a in operator that checks if a value exists in an array that would be syntactically identical to value in set. Whether it would be efficient or not with even more compiler magic is questionable. Sounds nice, create request to QC? 🙂 I would, except compiler magic is not a popular subject these days. Also, the corner cases for very short arrays would make it a lot of code for very little gain. Share this post Link to post
KoRiF 1 Posted April 5, 2023 On 3/17/2023 at 5:12 PM, Willicious said: Incidentally, if anyone knows of any good online tutors for Delphi/Embarcadero (i.e. live tutoring, NOT video tutorials), I'm interested! please write to me directly if you are still interested Share this post Link to post
Patrick PREMARTIN 69 Posted April 6, 2023 Hi For moving a sprite in a game for desktop OS, don't forget to manage WASD (QWERTY keyboard), ZWQS (AZERTY keyboards) and arrow keys. More accessible for users : add an option window where they choose what keys they want to use (what I never does, but I must add it to all my games too). You have some open sourced games in Delphi on GitHub at https://github.com/topics/delphi-game You can also find some on GetIt if you look for "arcade" or "game". Share this post Link to post
Willicious 8 Posted April 9, 2023 On 4/6/2023 at 8:16 AM, Patrick PREMARTIN said: You have some open sourced games in Delphi on GitHub at https://github.com/topics/delphi-game You can also find some on GetIt if you look for "arcade" or "game". Thanks for the advice. I'll take a look at these games Share this post Link to post