Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 08/27/21 in all areas

  1. Vincent Parrett

    thread-safe ways to call REST APIs in parallel

    This sort of task looks like something that OmniThreadLibrary would handle - but does require some study to get right (worthwhile imho). I created a wrapper over it's async/await feature that might be useful https://github.com/VSoftTechnologies/VSoft.Awaitable (depends on https://github.com/VSoftTechnologies/VSoft.CancellationToken and omnithread) An extremly naive example (with no queueing or thread limiting) - will probably not compile as mostly hand typed/copypasta 😉 with some details omitted for brevity. var RequestsInFlight : integer = 0; CancelTokenSource : ICancellationTokenSource; procedure DoRequest(const cancelToken : ICancellationToken; const param1 : string) var LParam1 : string; begin LParam1 := param1; //local for capture Inc(RequestsInFlight); TAsync.Configure<string>( function (const cancelToken : ICancellationToken) : string var restclient : TWhateverclient; begin //run rest request here //check cancelToken.IsCancelled or use the cancelToken.Handle with waitformultipleobjects etc restclient := TWhateverclient.Create; try result := restclient.Execute(); finally restclient.free; end end, token); ) .OnException( procedure (const e : Exception) begin //log error end) .OnCancellation( procedure begin //clean up end) .Await( procedure (const value : string) begin Dec(RequestsInFlight); //use result - runs in the calling thread. end); end; procedure StartRequests(const cancelToken : ICancellationToken) begin //Start the requests. for i := 0 to RequestCount - do ExecuteRequest(cancelToken, RequestParams[i]); //monitor requests inflight to know when it's done. end; procedure StopRequests; begin CancelTokenSource.Cancel; end; The cancellation part requires that your rest client supports cancelling requests somehow. Hope that helps.
  2. corneliusdavid

    Replace default code template?

    Why not simply use one of the oldest features of Delphi, The Object Repository? Not only can you store a pre-designed Form Template for reuse but you can create an application and store the whole application as a Project Template. In your case, the project would simply be a single-file .DPR. Here's an old YouTube Video that explains how to use the Object Repository--the latter half demonstrates project templates.
  3. vfbb

    Skia4Delphi

    Website: github.com/viniciusfbb/skia4delphi Skia4Delphi is a cross-platform 2D graphics API for Delphi based on Google's Skia Graphics Library (skia.org). Google's Skia Graphics Library serves as the graphics engine for Google Chrome and Chrome OS, Android, Flutter, Xamarin, Mozilla Firefox and Firefox OS, and many other products. Skia provides a more robust Canvas, being very fast and very stable, with hundreds of features for drawing 2D graphics, in addition to a text shaping engine designed to render texts in the most diverse languages with right-to-left support (such as the Persian language), full support for loading SVG files, support for creating PDF files, support for rendering Lottie files (verotized animations created in Adobe After Effects), integration with the GPU, among countless other cool features. Skia's idea is similar to Firemonkey's, the same codebase used in an OS will work the same on other platforms. It is also possible to design using the CPU in independent background threads. Skia also has native codecs, of course if you don't use the SKCodec class, when loading an encoded image it will give priority to using the platform's native codec, but it is possible to use its codec, for example for jpeg files it uses libjpeg-turbo and for png files libpng which maybe in certain environments may perform better than native. See some examples: Advanced shapes Advanced text rendering / shaping Svg Lottie files And much more...
  4. Der schöne Günther

    We use DUnitX and it discovers all our silly mistakes before release

    Excessively writing unit tests for new parts, but not using code coverage tools for the whole project. More than 50% of our code is 10-20 years old and simply cannot be tested. Yes, I have read Working Effectively with Legacy Code by Michael C. Feathers (goodreads.com), how to get out of this. But ain't nobody got time for that.
  5. I tried https://github.com/DelphiCodeCoverage/DelphiCodeCoverage and it's pretty good
  6. dwrbudr

    Skia4Delphi

    The skottie player demo using check.json doesn't correctly draw the image. See the black rugged edge border when the circle is being painted. Instead of using TWICBitmap, I've switched to 32bit TBitmap and created the TSKSurface like this: LSurface := TSKSurface.MakeRasterDirect(TSKImageInfo.Create( fBitmap.Width, fBitmap.Height, TSKColorType.BGRA8888), fBitmap.ScanLine[fBitmap.Height - 1], BytesPerScanLine(fBitmap.Width, 32, 32)); LSurface.Canvas.Clear(TAlphaColors.Null); FAnimation.Render(LSurface.Canvas, fDestRect); //flip the image since the DIB is bottom-up orientaded StretchBlt(fBitmap.Canvas.Handle, 0, 0, fBitmap.Width, fBitmap.Height, fBitmap.Canvas.Handle, 0, fBitmap.Height - 1, fBitmap.Width, -fBitmap.Height, SRCCOPY); Now all seem OK and the border is not rugged, not sure whtat's wrong with TWICBitmap. Check the border of the images below.
  7. @Rollo62 I've just uploaded to Image32's SourceForge repository another update to the SVG reader. The changes are primarily in anticipation of future animation but they should also allow you to dynamically change (most) element properties including fill and stroke colors, opacity etc. https://sourceforge.net/p/image32/code/ci/master/tree/source/ Example: procedure ChangeNearBlackPenToNavy(element: TElement); var i: integer; dd: TDrawData; begin if (element.DrawData.strokeColor <> clInvalid) and (element.DrawData.strokeColor <> clNone32) and (RgbToHsl(element.DrawData.strokeColor).lum < 5) then begin dd := element.DrawData; dd.strokeColor := clNavy32; element.DrawData := dd; end; //recursively call all children for i := 0 to element.ChildCount -1 do ChangeNearBlackPenToNavy(element[i]); end; //and to use the above procedure begin if not svgReader.LoadFromFile(fn) then Exit; //edit the loaded SVG elements ChangeNearBlackPenToNavy(svgReader.RootElement); //draw the edited SVG elements svgReader.DrawImage(ImagePanel.Image, true); end;
  8. y2nd66

    Anybody changing FileVersion directly in dproj file?

    I'm also using a custom solution. IOTAIDENotifier = interface(IOTANotifier) ['{E052204F-ECE9-11D1-AB19-00C04FB16FB3}'] { This procedure is called for many various file operations within the IDE } procedure FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean); { This function is called immediately before the compiler is invoked. Set Cancel to True to cancel the compile } procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); overload; { This procedure is called immediately following a compile. Succeeded will be true if the compile was successful } procedure AfterCompile(Succeeded: Boolean); overload; end; I set "Include version information in project" and "Do not change build number" for "All configurations - All platforms". Then I manage the values for the compilations at the convenience of my personal settings.
  9. Clément

    Anybody changing FileVersion directly in dproj file?

    I'm also using a custom solution. I found .DProj format very messy. Once I have my project version set I can't loose it. It messes my updates to sites and customer updates. My solution generates a .RC and compiles it to .RES with data I store in a .INI file. The .RES is included in the .DPR manually only once. My builds have the same information and the built number is incremented always correctly. I run the "versioninfo interface" from the Tools menu. Very handy
  10. DPStano

    Anybody changing FileVersion directly in dproj file?

    it's one of the reasons, next one is that xml(dproj) is one of the worst formats when you have to rebase branch and resolve conflict, and borland/embarcadero moved it to another level, delphi it is constantly changing dproj (switch to debug build -> dproj changes -> switch back and it changes even more, add a new file and you have like thousands new changes and so on) so we stripped all ballast(90%) from dproj and locked it for changes and we separated version info to own rc but version info section has to have the same encoding as defined inside https://docs.microsoft.com/en-us/windows/win32/menurc/stringfileinfo-block and we were constantly changing it from utf-8 to win1250 and back, fields like company name and the product description were almost always broken ... so we switched to simple powershell script that makes everything that we need in the right encoding all the time and it has to take version info from somewhere and dpr was good candidate for it couse it already contained header with similar info...
  11. DPStano

    Anybody changing FileVersion directly in dproj file?

    we have even hard rule to not commit dproj ... delphi modifies dproj without reason, and it's really annoying to resolve conflicts all the time, we created simple script in PowerShell that runs before build and creates resources with version info based on a custom comment in dpr like program Test; {@FileVersion=2.0.0} {@FileDescription=} {@InternalName=} {@Comments=} {@CompanyName=} {@LegalCopyright=} {@LegalTrademarks=} {@OriginalFilename=} {@PrivateBuild=} {@ProductName=@InternalName} {@ProductVersion=@FileVersion} uses
  12. Fr0sT.Brutal

    Replace default code template?

    Alternative could be Ctrl-A, Delete, "cons", Space + predefined code template named "cons" with the contents you want.
  13. Can't expect 'em to implement a new feature in under 5 years now..
  14. Dalija Prasnikar

    thread-safe ways to call REST APIs in parallel

    Creating separate objects would be my preferred approach, they are not that heavy to have significant impact on performance. ExecuteAsync is .... I have no words for describing it... maybe some people would like it, but for me it is useless addition. If you want to run rest it in the background thread simplest code is to just run the whole thing in background thread and then synchronize only if you need to synchronize some piece of code. With Execute you get clean code under your control where it is obvious what runs where and how you need to handle things, with ExecuteAsync you first need to learn how to use it properly. I would forget about it as it does not offer any advantages. I am glad if it helped to give you some insight, because I was confused about what you are aiming at. You can ask only very specific questions on Stack Overflow. For instance your initial question here would be definitely off topic on Stack Overflow. If you can create some minimal code example something in line what I have posted here as example, then you can aske whether you are doing it correctly and whether it is thread safe. It is also good to point to specific parts of the code you are not sure about. When it comes to thread safety it depends on the actual code and sometimes people don't add enough code. On the other hand adding too much code is also a problem because it is harder to get clear picture id there is plenty of code. For instance, if you need to populate UI, you don't need to show 50+ lines of UI related code. One is enough. The quality of answers also very much depends on the quality of the question. If answering requires a lot of guessing you will less likely get good answers. Few lines of code speak better than words 🙂 Don't describe your code, write it - even if it is just a rough concept. Then build the rest of the explanation on top of that.
  15. Dave Nottage

    Audio recording rises access violation on IOS 13.5.1

    Is there a value for NSMicrophoneUsageDescription in the Project Options, like this? If not, you'll need to add it, by right-clicking on the grid, click Add Key, enter NSMicrophoneUsageDescription as the name, click OK, then provide a value for it.
×