

Rollo62
Members-
Content Count
1909 -
Joined
-
Last visited
-
Days Won
23
Everything posted by Rollo62
-
Guidance on FreeAndNil for Delphi noob
Rollo62 replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
Sorry, if this was misunderstanding as an advice. It was searching for use cases of FreeAndNil, to help debugging such issues. And sometimes I have to solve problems which comes unexpected, by external influences, where I have little information and influence about. Ok, maybe there are ways to identify and encapsule these issues better, but most of the time they came a little out of the blue. -
Guidance on FreeAndNil for Delphi noob
Rollo62 replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
I just find some time to present an alternative solution, without FreeAndNil, as example with an cancellation token, it could probably look like this, which is more work to do. But the basic problem stays the same, that the cause of the blocking cannot be cancelled. It cannot be allowed to wait forever, after free, so the destroy must compromise somehow. I am not sure, if touching the cancellation token variable on a freed object causes the same issues, I would guess. Perhaps the interfaced token variable preserves the handle accessible, so that it will be safe to touch it within the freed class, but I won't bet on this. So in which places a FreeAndNil should be used then, only in global variables ( don't shoot the messenger ) 🙂 There must be good use cases for FreeAndNil anywhere. type ICancellationToken = interface ['{8C3A7E13-7C12-4F4F-92F5-DA1111111111}'] function GetCancelled: Boolean; procedure Cancel; property Cancelled: Boolean read GetCancelled; end; TCancellationToken = class(TInterfacedObject, ICancellationToken) private FCancelled: Boolean; public function GetCancelled: Boolean; procedure Cancel; end; function TCancellationToken.GetCancelled: Boolean; begin Result := FCancelled; end; procedure TCancellationToken.Cancel; begin FCancelled := True; end; ... type TMyClass = class private FCancellationToken: ICancellationToken; public constructor Create; destructor Destroy; override; procedure StartAsyncTask; end; constructor TMyClass.Create; begin inherited Create; FCancellationToken := TCancellationToken.Create; end; destructor TMyClass.Destroy; begin // Signal the cancellation FCancellationToken.Cancel; // Perhaps a wait mechanism implementation here, if needed, but exactly this is not always possible ??? inherited Destroy; end; procedure TMyClass.StartAsyncTask; begin TTask.Run( procedure begin // Example: Loop until cancellation while not FCancellationToken.Cancelled do begin // Simulation of blocking, regularily checking for cancellation. Exactly this might not alwys be possible. Sleep(100); end; if FCancellationToken.Cancelled then begin // Task is cancelled Exit; end; TThread.Synchronize(nil, procedure begin // Callback-Code Writeln('Task finished gracefully.'); end); end); end; -
Guidance on FreeAndNil for Delphi noob
Rollo62 replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
Ok, I'm open for your proposals If you got very sporadic AV on some customers devices and you are not able to reproduce that or to find any hints .... Sometimes a fast solution is needed, when a complete rewrite is currently not possible in time and you're unsure about the root cause. Of course I like to solve things once and forever too, and I only try to find possible use cases for the FreeandNil, which I have seen before. -
Guidance on FreeAndNil for Delphi noob
Rollo62 replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
Yes, but from my experience, this helps to REDUCE the risk of AV's, in case of async processes, where you cannot safely cancel such async operation, because its not directly under your control. Another example could be a call inside from an anonymous method, how can you canel that, if the class it freed? -
Guidance on FreeAndNil for Delphi noob
Rollo62 replied to Paul Dardeau's topic in RTL and Delphi Object Pascal
To make this discussion less academic: I like to use FreeAndNil in places, where Async callbacks may occur. For example like this (roughly hacked example, excuse typos): type TMyClass = class private FMyVar : TStringList; // The problematic object FMyCallback : TProc; public constructor Create; destructor Destroy; override; procedure Conf_Callback(const AProc: TProc); procedure DoOnCallback; end; constructor TMyClass.Create; begin inherited Create; FMyVar := TStringList.Create; FMyCallback := nil; end; destructor TMyClass.Destroy; begin FreeAndNil( FMyVar ); // Free the object and prevent further calling it FMyCallback := nil; inherited Destroy; end; procedure TMyClass.Conf_Callback(const AProc: TProc); begin FMyCallback := AProc; end; procedure TMyClass.DoOnCallback; begin if not Assigned(FMyVar) then begin DoLogThisIssue; // Logging the rare problem Exit; //<== GUARD end; FMyVar.Add( 'Hello'); // Using an existing object, which is protected by FreeAndNil end; In cases where TMyClass is already freed, but pending async functions might still call the DoOnCallback function. If this happens, the guard may REDUCE THE RISK of an sporadic AV, probably. I know, the arguments against this are, that this should never happen and I should rewrite the code calling DoOnCallback in the first place. But in reality, I see these things might happen, especially in highly async, undetermined, not well testable situations, which will result in unwanted AV's, but where this situation only happens very rarely of system dependent. In that case I prefer to have at least an AV prevention, over having some kind of other issues in the app ( this is of course not a banking app ). At least I'm able to debug or log these rare situations in the guard. I would think of like these two categories: # High critical apps: Either you need a perfect stable, reliable and high-security app ( like banking, high security authentication, database, airplane control, etc. ) # Uncritical apps : Or you have an relative uncritical app, where its more important to not annoy customers by rare crashes, where you can try to catch such issues by logging. -
Looking but not finding...
Rollo62 replied to Rick_Delphi's topic in Job Opportunities / Coder for Hire
Unfortunately, they wont use Delphi, do they? -
Thanks for the info. From what I understood, these components came as binary package only, which would be a no-go for me. Can you confirm this, or am I interpreting their specs falsely?
-
I usually look into market surveys, which phones or brands were selling best https://www.heise.de/news/Smartphone-Markt-hat-sich-2024-erholt-chinesische-Marken-legen-zu-10241291.html#nav_marktanteile__1 Then you have a chance that you are testing on whats your clients are using most. Google Pixel is perhaps the best, most modern and best supported Android phone, which helps to be state-of-the-art, but its market share is quite low still.
-
Thanks, I know the OrangePi company, I will check that board. Thats a reasonable price, if so much variation in prices exists, its good to have a recommendation like yours.
-
@tomye Thanks, thats a very interesting project. That makes Rockchip an interesting option, when it comes to neural networks. I assume that you run this project under Android. There are at least some boards in the market that come with Android naturally, are these boards supported by Delphi out-of-the-box, like a Samsung or Pixel phone, or do we need special drivers or other measures, drivers or modules to make it compatible? Maybe you can tell us also something about the hardware you used too, which would be needed to run that smoothly? I assume a Firefly board would be a good choice, but it seems also to be quite costly, about 200 -300 USD. https://en.t-firefly.com/doc/download/207.html While a Radxa Rock 5A is available from 22 USD, I would expect from the data that it has NPU too, perhaps there are some drawbacks for that price. https://radxa.com/products/rock5/5a/ I have not checked where the differences in detail are, I assume both support the NPU in the same way, but I'm not an Rockchip expert. Maybe there are subtle differences in the Rockchip model code, which lead to biggers differences, which CPU model will be the most promising? Do you have recommendations for some capable Rockchip boards for testing, maybe there are many other boards than the two above, which are newer and more powerful, I'm not aware of.
-
PasLibVLC? https://stackoverflow.com/questions/36567287/delphi-paslibvlc-use-without-installing-vlc-player
-
What new features would you like to see in Delphi 13?
Rollo62 replied to PeterPanettone's topic in Delphi IDE and APIs
What features are most wanted: Under all platforms (Win32, Win64, Macos, iOS, Android, Linux, ...) I would wish to have - A debug experience, that is reliable and shows and behaves consistently under all platforms - A rock solid debugging function, with at least breakpoint, step-over, step-into ... likely the full feature set - A rock solid and consistent debug inspection view, with ability to show on mouseover or inspect, for all structures in the same way - A debug inspection view, that is able to decode all sub-structures of classes or records correctly and is fast and easy to access its underlaying members - A debug inspection view, that defaults to human readable data representation first, while there were options to watch single variables in many views. - A debug inspection view or watch, that can reliably switched between decimal or hex view at least (and even more integer/hex/string/byte array,pointer,... ) - A debug inspection view or watch, maybe on the breakpoint level, that can define the preferred view representation of the current session permanently, for all different views (hoover, inspect, watch,...) The Win32 behaviour is more or less the best reference so far, while other platforms are still not there. -
New Book Delphi Quality-Driven Development
Rollo62 replied to Dalija Prasnikar's topic in Tips / Blogs / Tutorials / Videos
Nice, now I have something very interesting to read in the next cold winter days The whole payment and download experience with PayHip was also extraordinary pleasing, I can recommend that. -
Does anyone know a delphi component that can play videos from a stream
Rollo62 replied to ToddFrankson's topic in VCL
This is interesting blog https://blogs.embarcadero.com/execute-scripts-and-view-source-with-tedgebrowser/ Perhaps this might work for showing videos, but there is also the possibility that certain Codecs or Plugins were missing, like HLS (.m3u8) : var HTMLContent: string; begin HTMLContent := '<!DOCTYPE html>' + '<html>' + '<body>' + '<video width="640" height="480" controls>' + //either local file '<source src="file:///C:/Pfad/zum/Video.mp4" type="video/mp4">' + //or stream '<source src="https://example.com/stream.m3u8" type="application/x-mpegURL">' + 'Dein Browser unterstützt das Video-Tag nicht.' + '</video>' + '</body>' + '</html>'; EdgeBrowser1.NavigateToString(HTMLContent); end; For accessing local files, there could be the need to add AdditionalBrowserArgument flags https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/working-with-local-content?tabs=dotnetcsharp#loading-local-content-by-navigating-to-a-file-url https://docwiki.embarcadero.com/Libraries/Athens//de/Vcl.Edge.TCustomEdgeBrowser.AdditionalBrowserArguments -
Loading a JPEG into FMX.TBitmap honoring EXIF orientation
Rollo62 replied to Alexander Halser's topic in FMX
Exactly, but if that doesn't set the value reliably, then you can use a second opinion by another internal sensor, or not? While you take that image in the phone, you could try to fix this, in your Android App. If you only read/export images from the Gallery and if you have no own Andoid App inbeteeen, then you have little chance. Still there could be the options to fix images, depending on device dependend information, e.g. Samsung S20 always needs 90° rotation, iPhone 14 doesn't need that. But such list will be huge and fragile and maybe also depends on specific mobile device settings. -
Loading a JPEG into FMX.TBitmap honoring EXIF orientation
Rollo62 replied to Alexander Halser's topic in FMX
This seems to be a general problem, that different phones may behave differently. https://stackoverflow.com/questions/13245556/exif-orientation-tag-value-always-0-for-image-taken-with-portrait-camera-app-and?utm_source=chatgpt.com I have seen this issue in Samsung too. Maybe a solution would be, to manually verify and correct the EXIF data based on the real orientation data of the phone ( measured by the tilt-sensor ), and not alone rely on what samsung tells you. -
Wordpress upload media
Rollo62 replied to George Bairaktaris's topic in ICS - Internet Component Suite
I tested that some years ago, not sure if that still works. https://github.com/Embarcadero/wordpress-rest-api-client -
TakePhotoAction crashes android app and starts again on xiaomi Android 12
Rollo62 replied to fisipjm's topic in FMX
I'm not sure, if that is still true on modern phones with modern OS, the examples were quite old, from the era before permission discussions perhaps. I would generally recommend to request permission before touching any camera part, that cost not much, and will be considered as good behaviour to ask the user before touching dangerous parts. -
Perhaps, but I assume if there is already one custom control, then its very likely that there are several custom components units too, like MyCustomCalendar.pas MyCustomThis.pas MyCustomThat.pas wouldn't it be cleaner to combine the registration for the designer in a common registration unit? MyCustomReg.pas procedure Register; begin RegisterComponents('My Delphi Tools', [TMyCustomCalendar, TMyCustomThis, TMyCustomThat]); end; Just saying, I haven't looked too deep into this, its also fine as-is.
-
TL;DR; You should consider to separate the combined unit into separate designtime and runtime units. procedure Register; begin RegisterComponents('My Delphi Tools', [TMyCustomCalendar]); end;
-
Yes, that is strange. I never tried to get a runtime permission for a "normal" permission, but I had expected that the IsPermissionGrant would also work in same way. Since it is not explicitely forbidden anywhere in the docs, at least I find no rule for that, maybe the best place to logically derive this from is here: https://source.android.com/docs/core/permissions/runtime_perms?hl=en It states more or less, that the runtime expressios are intended for >= dangerous permissions, from this we could logically deduct that "normal" permissions doesn't need (or better doesn't allow) such requests. Negative logic is sometimes confusing ...
-
Aaaah, I see. Its a new business model, using AI for writing poor code, that students will have to correct in their exams. Thats how AI can be perfectly used, you will be incredible rich soon
-
You could ask me too, thats cheaper
-
I do ( 3rd from left )
-
Isn't that a little discriminatory towards other pets? Write a haiku about cats and dogs Whiskers meet wet nose, Silent grace and joyful bark, Peace beneath the sun.