Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 12/11/18 in Posts

  1. Pointers can be really helpful, especially they can improve performance and readability, but they are also dangerous. I spent nearly a day tracking down the reason why the code a former colleague wrote about 5 years ago all of a sudden led to access violations. The code used to work fine, the problem only surfaced when I changed the size of a record. Consider this code ... https://blog.dummzeuch.de/2018/12/11/pointers-are-dangerous/
  2. Clément

    Pointers are dangerous

    Pointers are part of the package. I use them for performance and low memory footprint especially when dealing with low level code (bytes, records or low level TCP communication). The gain pointers bring to the table is worth the risk.
  3. Arnaud Bouchez

    Pointers are dangerous

    FastMM4, in FullDebugMode is able to track such pointer problems. I always use it, and also the FPC's Heaptrc unit (compile with -gl) which can find some other problems. I use pointers only when the code needs it, mainly for performance reasons. Otherwise, high-level structures like classes or dynamic arrays are just enough.
  4. Kryvich

    Pointers are dangerous

    I would prefer it like this: with const Ptr = @SomeArray[SomeStructure.SomeIndex] do begin // Inline constant declaration with type inference Ptr.bla := 5; Ptr.blub := 10; end; @Rollo62 Not only. Using a temporary variable can optimize the binary code.
  5. Attila Kovacs

    Pointers are dangerous

    *Read: The code used to work by accident.
  6. The DDevExtensions 2.85 and the DFMCheck 1.6 are now available for Delphi 10.3 Rio. DDevExtensions Changelog Added: Support for Delphi 10.3 Rio Added: Use Unit dialog option “Every unit on a single line” Improved: UnitSelector Dialog in Delphi 2009 opens much faster Fixed: Structure-View search dropdown had a max height of 2 items Downloads
  7. I've just released the next version of OmniPascal. It's coming with support for the inherited keyword, type helpers and inline variables. http://blog.omnipascal.com/omnipascal-0-17-0-inherited-keyword-type-helpers-and-inline-variables/
  8. santiago

    Build time with 10.3 almost doubled

    @Attila Kovacs With theming disabled the problem does not ocurr. Since I do not need to move the IDE to another monitor frequently it is not a big problem. At least I know what causes it and how to easily workaround it.
  9. jbg

    Unresponsive IDE and massive memory leaks with RIO

    You can get rid of the failing CreateFile calls by using the attached IDEFixPack development snapshot. But you shouldn't come anywhere near the Win64 or Android compiler if it is installed. Only the Win32 compiler and IDE patches are already working (including the compiler directory cache that eliminates the unnecessary CreateFile calls). You can ignore the error messages during the splash screen that tell you that Win64 and Android patches couldn't be applied. IDEFixPackD103RegDev_not_even_alpha.7z
  10. Kryvich

    What does TDataSet.CopyFields do?

    @Uwe Raabe Of course, https://quality.embarcadero.com/browse/RSP-22946
  11. Can trap and do things with the URL before navigation in OnShouldStartLoadWithRequest (should work correctly in Delphi 10.3 Rio in theory): https://stackoverflow.com/questions/23416086/callback-delphi-function-from-twebbrowser-by-javascript-on-delphi-xe6-for-all-pl Can modify the settings of the Android WebView here (copy the file to your project and edit) FMX.WebBrowser.Android.pas constructor TAndroidWebBrowserService.Create; var LayoutParams: JRelativeLayout_LayoutParams; begin FWebView := TJWebBrowser.JavaClass.init(TAndroidHelper.Activity); FWebView.getSettings.setJavaScriptEnabled(True); FListener := TWebBrowserListener.Create(Self); FWebView.SetWebViewListener(FListener); FFocusChangeListener := TFocusChangeListener.Create(Self); FWebView.setOnFocusChangeListener(FFocusChangeListener); FWebView.getSettings.setGeolocationEnabled(True); FWebView.getSettings.setAppCacheEnabled(True); FWebView.getSettings.setDatabaseEnabled(True); FWebView.getSettings.setDomStorageEnabled(True); FWebView.getSettings.setBuiltInZoomControls(True); FWebView.getSettings.setDisplayZoomControls(False); FWebViewContainer := TJRelativeLayout.JavaClass.init(TAndroidHelper.Context); FChildrenContainer := TJRelativeLayout.JavaClass.init(TAndroidHelper.Context); LayoutParams := TJRelativeLayout_LayoutParams.JavaClass.init(TJViewGroup_LayoutParams.JavaClass.MATCH_PARENT, TJViewGroup_LayoutParams.JavaClass.MATCH_PARENT); FWebViewContainer.addView(FWebView, LayoutParams); LayoutParams := TJRelativeLayout_LayoutParams.JavaClass.init(TJViewGroup_LayoutParams.JavaClass.MATCH_PARENT, TJViewGroup_LayoutParams.JavaClass.MATCH_PARENT); FWebViewContainer.addView(FChildrenContainer, LayoutParams); SetEnableCaching(True); end;
  12. Bjørn Larsen

    How to add FireDAC Datamodule as per the demo?

    Hi, Have you made sure that your unit is listed under uses and included in the filter that is specified in the AddApplication procedure? FEngine.AddApplication('DefaultApp', '/default', [ 'Server.*']); -- Bjørn
  13. Uwe Raabe

    Pointers are dangerous

    That would work for classes, but fails for records. Introducing a record variable will give you a copy of the array element for your changes. The original array element will stay unchanged. A valid alternative would be a record method like SetBlaBlub(5, 10) which directly manipulates the underlying record. This might even benefit the readability.
  14. dummzeuch

    Pointers are dangerous

    I consider this Ptr := @SomeArray[SomeStructure.SomeIndex]; Ptr.bla := 5; Ptr.blub := 10; // and 10 more lines like this as more readable than SomeArray[SomeStructure.SomeIndex].bla := 5; SomeArray[SomeStructure.SomeIndex].blub := 10; // and 10 more lines like this Of course we could always use WITH instead. 😉 Or we could use a list with objects where the pointer is implicit, but then we'd need a lot of boilerplate code. I would have written it differerently, but this is legacy code which I'd rather touch as little as possible (because it will hopefully become redundant shortly).
  15. Sherlock

    Pointers are dangerous

    Aside from performance I have never considered pointers to be an improvement for readability, it's something that's messed up in my brain I guess. And the way it was taught back in the day: Calling it "pointer arithmetic" really did not help understanding the simple things that are going on there. Luckily there is no syntactical need for pointers in Delphi anymore. Been living free of ^ and @ for years now. Of course sometimes some API smuggles in PBytes or PChars, but its nicely encapsulated.
  16. David Heffernan

    Shellexecute cmd.exe with spaces

    Pointless to ask ShellExecute to create a cmd process to in turn create another process. Create the other process directly. This is the source of all your problems.
×