-
Content Count
1123 -
Joined
-
Last visited
-
Days Won
99
Dalija Prasnikar last won the day on February 15
Dalija Prasnikar had the most liked content!
Community Reputation
1447 ExcellentTechnical Information
-
Delphi-Version
Delphi 11 Alexandria
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
Yes, but the new 64-bit compiler is about compiler bitness, not platform. That means that compiler is no longer 32-bit process and can use all available memory on the system.
-
Guidance on FreeAndNil for Delphi noob
Dalija Prasnikar replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
Of course, but plenty of code doesn't have that. -
Guidance on FreeAndNil for Delphi noob
Dalija Prasnikar replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
For me it is about code intent. FreeAndNil implies reusable variables and more complex instance lifetime. Free implies the opposite. -
Guidance on FreeAndNil for Delphi noob
Dalija Prasnikar replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
No. I remember seeing such code, but I cannot tell you the exact place. It is hard to find them because in most places RTL, VCL, and FMX use FreeAndNil when it is not needed at all or for lazy initialized/reusable variables. -
Guidance on FreeAndNil for Delphi noob
Dalija Prasnikar replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
Because it is a plague Reusing is the one scenario. Another scenario which you can see in very complex destructors which are part of some deep class hierarchy. It is not to prevent concurrency issues (because it can't prevent those), but it is used to prevent accessing already released fields during more complex cleanup. In such cases it must be paired with is Assigned checks. But this is rarely needed outside frameworks like VCL and FMX (and even there it is used in many places where it is not needed at all). -
Guidance on FreeAndNil for Delphi noob
Dalija Prasnikar replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
procedure TMyClass.StartAsyncTask; var LCancellationToken: ... begin // capture this local variable instead of field in anoanymous methods LCancellationToken := FCancelaltionToken; ... TThread.Synchronize(nil, procedure begin if LCancellationToken.Cancelled then Exit; // Callback-Code Writeln('Task finished gracefully.'); end); @Rollo62 Use the above approach to avoid capturing Self. You also need to check once again whether task was canceled when you synchronize, before you touch anything from TMyClass. also this will only work if the code that runs within the task does not touch anything from the class. If you can't avoid that you need to store task in field and wait for its completion before you destroy object. -
Guidance on FreeAndNil for Delphi noob
Dalija Prasnikar replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
If the callback runs in the background thread then FreeAndNil will not make the difference. In other words, your guard is not guarding anything. The FMyVar could be released after callback passes the Assigned check. You would need a different mechanism to protect your variable and make sure it is still alive while callback runs. The whole idea that your object which is still used while there may be pending async code running is a serious design flaw. I am not sure how easy would be to fix that code (I expect it is more complex in real life scenario), but you have a problem here. There are different mechanisms that can protect your instance, but which one is the most suitable will depend on other code and context that you haven't mentioned here. You can find some ideas at https://github.com/dalijap/nx-horizon look at how TCountdownEvent is used. another one is in https://github.com/dalijap/code-delphi-async/tree/master/Part6/35.2 GUI Cleanup but that one will work only if the TMyClass instance belongs to main thread. Of course, those are not the only solutions, just something to get you started. I haven't mentioned the most obvious one (waiting for the background thread to finish, before you release TMyClass instance, but I guess that this is not an option here or you would probably use it already. -
Guidance on FreeAndNil for Delphi noob
Dalija Prasnikar replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
FreeAndNil is something that you will need to use rarely (it might depend on the kind of code you are writing). In places where your code needs it logically it will be obvious that you need it and everywhere else you can use Free. The point that FreeAndNil can help you avoid errors and mistakes is full of holes. First, simple access after Free is usually easy to catch either by looking at the code (local variables) or by using memory manager in debug mode or other specialized tools. Next, FreeAndNil nils only single reference to the object instance. If you have multiple ones you will still have to deal with dangling pointers and you will need to learn how to use previously mentioned tools. Most of the problems with memory management in Delphi are caused by having multiple references to single manually managed object instance as such code is more complex. This is exactly the place where FreeAndNil cannot help you, but where using it will give you false sense of security. Another reason against using it everywhere, is that it obscures the code intent. Logically, FreeAndNil means that variable will be reused and this is important information. If you use it everywhere, you will have mush harder time reading the code and understanding its intent. And code which is harder to understand is also harder to maintain in the long run. Of course, that can be solved with comments, but then you will have to use them everywhere or you will never know whether some comment is missing somewhere. Manual memory management requires some discipline. thinking about the code you are writing enforces the discipline and makes you a better programmer. Taking the "easy" path where you will slap FreeAndNill everywhere just so you can avoid accidental mistakes and thinking is going to cost you at some point. Many existing codebases where it is used everywhere cannot be easily migrated to not using it as it can be hard to determine where it is needed and where it is not (except for local variables) and they need to continue using it indefinitely in all places, as the only thing worse than using FreeAndNil everywhere is using it randomly. Consistence in code is the king. In my codebase I have less than 50 places where I am using FreeAndNil (I cannot tell the exact amount as I have many smaller projects and it is not easy searching through them as some contain fixed VCL code which uses FreeAndAil a lot, so I cannot easily count usage in my files only) One of the advantages of being a new Delphi developer is that you don't have a lot of existing code where FreeAndNil was used in places where it is not needed and now is the right time for you to decide whether you want to pollute your code with FreeAndNil and stick with it forever or not. -
New Book Delphi Quality-Driven Development
Dalija Prasnikar replied to Dalija Prasnikar's topic in Tips / Blogs / Tutorials / Videos
Maybe it was some glitch. There were other people from Italy who successfully purchased. If there is some problem with the method of payment, you would have to contact PayHip directly as they are handling that part and I cannot help with this. https://payhip.com/ I was just told that they occasionally have some glitches (where it gives you error on purchase, but there should be button try again and usually that is enough to go through) -
New Book Delphi Quality-Driven Development
Dalija Prasnikar posted a topic in Tips / Blogs / Tutorials / Videos
This year, on February 14th, Delphi celebrates its 30th birthday. Over the past three decades, Delphi has proven to be a robust and versatile development environment, empowering developers to build high-performance applications with ease across multiple platforms: Windows, Linux, Android, iOS, and macOS. As we commemorate this milestone, I am also introducing a new book to help guide you into Delphi's fourth decade: Delphi Quality-Driven Development - A practical guide to testing and writing testable code. Useful to lone developers and vast teams alike, this book aims to demonstrate a variety of essential practices and techniques for making high-quality, testable code. There is a 25% sale going on until the end of February for the Delphi Quality-Driven Development ebook, and there you can also get an additional discount on other books if you add them to your order. https://dalija.prasnikar.info/delphiqdd/index.html To all my fellow Delphi developers: May your code compile quickly, your memory be manageable, and your code testable. -
inheritance Ensuring Consistent Base Interface Implementation in Delphi Class Hierarchy
Dalija Prasnikar replied to bravesofts's topic in Algorithms, Data Structures and Class Design
Please show the code that actually exhibits the problem. The code you posted (if we ignore the fact that you are missing procedure keyword in your method declarations) works the way you want it to work.- 14 replies
-
- code reuse
- class hierarchy
- (and 3 more)
-
Strict type checking for tObject.
Dalija Prasnikar replied to A.M. Hoornweg's topic in RTL and Delphi Object Pascal
Another more elaborate example that will show why is compiler strictness for var parameter necessary, and why without it we could easily and unintentionally write the code that can corrupt memory otherwise Pass the Dog, Get the Cat -
When it comes to mobile development you cannot count on that kind of stability. Not because of Delphi, but because of platforms. android and iOS get new OS version every year, often with drastic changes in some workflows and features. They also expect that you frequently update your application and make it compatible with new OS versions (old applications still run, but if you don't make an update in two years period applications will not be available to users with new OS versions - this is just example, there are variants of what exactly happens in each particular case). Those OS changes also require changes in Delphi toolset and sometimes additions in code. How drastic depends on the each particular change. This is valid for all mobile development toolsets, and is nothing Delphi specific. But, this also means that you will have to keep current with new Delphi releases and you cannot stick using some old Delphi version for too long after new one gets out.
-
Yes, things have changed significantly for the better. However, there are still some pain points (more specifically debugging, especially on iOS as Apple keeps throwing curved balls) Main difference is that ARC was being source of significant performance issues on mobile platforms. I have done extensive investigations at the time, and by doing slight modifications in FMX code I was able to significantly improve performance. Used optimizations were covered in my blog posts: https://dalijap.blogspot.com/2018/01/optimizing-arc-with-unsafe-references.html https://dalijap.blogspot.com/2018/01/optimizing-arc-hard-way.html https://dalijap.blogspot.com/2018/03/optimizing-arc-weakness-of-weak.html Even though there is no ARC compiler, above articles are still valid when dealing with interfaces in Delphi. Removing ARC compiler was not the only performance improvement. Next one was introduction of Skia library in Delphi 12, which gives better performance on mobile platforms. It is not perfect and depending on the project it is not necessarily working better on the desktop FMX applications, but it is easily configurable, so different rendering methods can be used depending on the platform. Another pain point was using 3rd party frameworks on both Android and iOS, and this has also been significantly improved in the meantime. Overall, plenty of bugs have been fixed in the meantime (of course, that does not mean there are no new bugs), but things are way better than they were at the early beginnings. Most importantly people are successfully using Delphi for writing Android and iOS applications. You can find one such example here: Whether Delphi is the best option for some project that is another question and it can really depend on the project. The best option would be putting down all the tech your app needs to interact with and what are basic features you need to support. After you have tall that listed you can make a demo app to see whether you can easily incorporate all that you need across various tools and platforms. Only after doing that you will be able to tell which one will be the best for the project. And at the end, the grass is not greener on the other side. For development Delphi is much more stable platform than some others. It does not have some fancy features language wise, but its UI frameworks are very stable. Over the years, both Google and Apple made significant shifts in their native frameworks that required extensive code refactoring (yes, you can still use the old ways, but it still requires a lot of work to keep up with changes). If you are looking for cross-platform tool, then situation is not too much different.
-
Google Signin Firebase for Store doesn't work
Dalija Prasnikar replied to Massimiliano S's topic in Cross-platform
If you are using App Bundles and Play Store Signing, then you need to add SHA-1 fingerprint from the Google Play Console as Google will use different certificate for signing from the ones in your keystores. See: https://developers.google.com/android/guides/client-auth