Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


vfbb last won the day on June 6 2020

vfbb had the most liked content!

Community Reputation

71 Excellent

Technical Information

  • Delphi-Version
    Delphi 10.4 Sydney

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. There are really few apps on Windows, except for chat apps, which fully support unicode (including MS apps), but in my case I really need to deal with this because it will be just a cross platform chat (Win, Android, iOS). Today's problem is to fix TEdit, but it is not just that, but the safe way to manipulate any string received from the user. It is the same as using AnsiString/AnsiChar when the input is string (unicode), you are at risk of generating an unexpected string. To clarify the problem, follow an example on TEdit: 1) Select a TEdit, press Windows key +. to open the emoji window 2) Select for example the "White man raising his hand" which is represented by 7 characters, that is, 14 bytes) 3) Proceed: Example string manipulation: In a string manipulation it is very common, for example, to take x first characters, so suppose I want to take the first 8 chars: S := S.Substring(0, 8); But if S is "πŸ™‹πŸ»β€β™‚οΈπŸ™‹πŸ»β€β™‚οΈ", which incredibly has 14 chars, and which is the same as: S := #55357 + #56907 + #55356 + #57339 + #8205 + #9794 + #65039 + #55357 + #56907 + #55356 + #57339 + #8205 + #9794 + #65039; When I give the substring (0, 8), the result will be: S := #55357 + #56907 + #55356 + #57339 + #8205 + #9794 + #65039 + #55357; Which is represented by: πŸ™‹πŸ»β€β™‚οΈοΏ½ But a Substring (1, 7) would be even worse in this case: The problem is very clear and a modern application, mainly of chat, has to know how to deal with it.
  2. Wrong! Actually porting the C# code will be laborious and will require maintenance as the unicode is changed. The best solution at this point is to use apis: Windows - DWriteTextAnalyze Android - GraphemeCharsLength := JString.codePointAt(Index); iOS - CFStringGetRangeOfComposedCharactersAtIndex
  3. All manipulations of strings received by user input should consider each element and not each individual character. This is basically why delphi TEdit does not work properly with these kind of emojis (just try adding one and pressing backspace that you will see part of problem). In short, when you don't consider this, you risk breaking a string into a position in the middle of a Grapheme, creating a malformed string. As I said, this iteration is essential, Embarcadero should implement this natively to work cross-platform just like C # did. The best thing to do at this point is to port the C # code.
  4. Embarcadero should create a class based on C# TextElementEnumerator, which does exactly this.
  5. The delphi string is an implementation of UTF-16 in which the "normal" graphic characters corresponding to 1 Char (2 bytes), but having others graphic characters being represented by 2 Chars (4 bytes), the so-called surrogate pair, (like the emoji πŸ™). And in this case we need to check if the char IsSurrogate, to know that it is a graphic character of 2 Chars (4 bytes). But the problem is that utf-16 is not limited to a maximum of 4 bytes for a graphic character, in fact it already predicts that a graphic character can have up to 14 bytes for future implementations, and today most of the emojis already occupy at least 8 bytes (like the emoji πŸ™πŸ» <- light version). This is a problem, because delphi only handles the graphic character with the possibility of being 2 bytes or 4 bytes, and is often converting the graphic character or string to UCS4Char or UCS4String respectively, to treat everyone as being 4 bytes. So, how do you know the actual size of each graphic character in a string?
  6. Apparently simple, but in practice nothing trivial, and with nothing on the internet about this, I decided to do a brief tutorial to master the Android system bars. https://github.com/viniciusfbb/fmx_tutorials/tree/master/delphi_android_system_bars/
  7. vfbb

    Delphi Rio 10.3.2 : iOS Custom Font

    Just a tip: it is not mandatory to place the .ttf file in the project folder, you can put it in a subfolder then add that subfolder in "Search path"
  8. vfbb

    Waiting for multiple threads

    This problem is very common because without proper care the threads end in a different order than the units. The rule to avoid this is: each unit that creates each thread has to guarantee that the thread it created will be canceled and completely terminated until the finalization of the unit. How to do this? There are several possibilities, I will quote one: 1) Create a way to cancel each thread (it is almost always possible through a simple Boolean + TEvent.SetEvent, but each case must be evaluated) 2) Create a unique TEvent to signal the end of the thread; Just run the thread code in a try finaly FFinishEvent.SetEvent; 3) At the end of the unit, cancel the thread, and give FFinishEvent.WaitFor;
  9. Have you tried to see if there are any more exception or information debugging the IDE? Open some bpl then Run> Parameters... > Host Application "C:\Program Files (x86)\Embarcadero\Studio\21.0\bin\bds.exe" > Save > press F9 Then new instance of delphi will be created in debug mode, then you can reproduce the error in that delphi instance and you may have more information about the problem.
  10. vfbb

    iOS push notification http/2

    You can use Firebase Cloud Messaging instead. There are some examples of FCM with delphi in github.
  11. vfbb

    Nneed a mentor

    It was a pleasure to help you πŸ˜‰
  12. vfbb

    Android 11 Support in 10.4.2?

    I'm not going to talk about delphi 10.4.2 because I still have 10.4.1. But on sdk, you don't need to use this Embarcadero tool, it is almost always a version behind. Ideally, you should install Android Studio on your own, open it and Configure> SDK Manager and install (download) the latest sdk, get the directory and configure it in your Delphi Options > Deployment > SDK Manager> Android
  13. Virtual interfaces: to create an object that support an interface in run time. See System.Rtti.TVirtualInterface
  14. Sometimes I come across some delphi language enhancements that are undocumented or are poorly documented. In the last few years docwiki has improved a lot, but there are still undocumented cases, such as accessing an item in an array just by declaring a property, without any method: TipGeolocation = record private FCoordinates: array[0..1] of Double; public property Latitude: Double read FCoordinates[0] write FCoordinates[0]; property Longitude: Double read FCoordinates[1] write FCoordinates[1]; end; Share here any enhancements to the delphi language that you have discovered but are not documented.
  15. Although I don't particularly like this design, you can make a descendant of TInterfacedPersistent, your class will not be arc and will be able to implement interfaces. TBaseFrame = class(TInterfacedPersistent)