Jump to content

rgdawson

Members
  • Content Count

    8
  • Joined

  • Last visited

Everything posted by rgdawson

  1. Nick Hodges excellent book, "Coding in Delphi", gave some interesting ideas about creating Sqlite classes and interfaces, then anonymous methods, then enumerators. I am ever mindful of the idiom, "just because you can doesn't mean you should", but I decided to experiment. Below are some examples and what I am asking is, what looks best to you? I started with Yuri Plashenkov's simple Sqlite classes (https://github.com/plashenkov/SQLite3-Delphi-FPC) I converted the classes into interfaces which gives me Pattern 1 below. Then I added some functions that take advantage of anonymous methods and that gives me Pattern 2. Then I added enumerators and that gives me Pattern 3. {...} var SQL: string; Stmt: ISQlite3Statement; Name: string; Age: integer; begin SQL := 'SELECT Name,' + ' Age'+ ' FROM People'; {Pattern 1: using interfaces...} Stmt := DB.Prepare(SQL); while Stmt.Step = SQLITE_ROW do begin Name := Stmt.ColumnText(0); Age := Stmt.ColumnInt(1); {...} end; {Pattern 2: adding anonomous methods...} DB.FetchAll(SQL, procedure(Stmt: ISqlite3Statement) begin Name := Stmt.Column[0].AsText; Age := Stmt.Column[1].AsInt; {...} end); {Pattern 3: adding enumerator...} for Stmt in DB.Prepare(SQL) do begin Name := Stmt.Column[0]; {this uses class operator Implicit to call .AsText} Age := Stmt.Column[1]; {this uses class operator Implicit to call .AsInt} {...} end; I have also been considering the idea of style with respect to the Sqlite functions .ColumnText() and .ColumnInt() etc. For example instead of .ColumnText(0), I could have .Column[0].AsText, or using "Implicit" , just .Column[0], .Column[1] etc where .AsText, .AsInt, etc is called implicitly. Many of you folks on this forum are the most brilliant I am aware of, and I have learned a ton over the years reading your stuff here, on Stack Overflow, in your books, and in your code. Someday, I'll retire and someone will have to take over this code and I want it to be straight forward looking, easy to read and understand. Which would you say is preferable? R Greg Dawson
  2. Nice, good points. After implementing a block of code all different ways and then just staring at it for awhile, I also decided Pattern 2 seems best. Sometimes, you don't really know until you try it with real code. Using the anonymous method pattern for the fetch loop code makes it easier to just plainly see that database fetching is going on and just seems more elegant. As for getting column/field data, pattern 3, using implicit, indeed, made the code harder to read and contextualize. Then, your three little lines of code there are all good ideas, too, which I intend to implement. Thanks.
  3. rgdawson

    Delphi 11.3 is available now!

    Thanks for that tip. I didn't know about that function. I just used MulDiv, which I guess is what that function does. Geewiz, how many times have I implemented something only because I did not know it already existed somewhere within the depths of the VCL/RTL already.
  4. rgdawson

    Delphi 11.3 is available now!

    Another thing I noticed was that the Vcl StringGrids were improved to now DPI scale the gridlines thickness, so for example at 200%, your gridlines will be two pixels in width. I happened to have an app with several ownerdraw string grids that do custom stuff with column widths that assumed the gridline width was 1 and all that broke. So that might be something to look out for, cuz it was not obvious to me at first.
  5. rgdawson

    Delphi 11.3 is available now!

    Been working with 11.3 since it came out. Very smooth upgrade from 11.2. My other observations are: As before, using inline variables seems to break certain code refactoring functions like Rename Variable, which I like to use more than I like inline variables, so I don't use inline variables. The new editor feature that highlights words that you select where visible elsewhere in the editor causes the editor to scroll unexpectedly if you are using folding, which I do, so I had to disable that feature. LSP does not seem to fail anymore. Control-Click jumps in the editor don't stop working near as often as before, but still do sometimes. In that case I use Ctrl-G or I reboot the IDE. The compiler is fast as blazes as far as I am concerned. When I was young, I learned guitar by practicing during compiles, haha. Nowadays compiling 100,000 lines of code takes only a few seconds. I just frickin' love Delphi. I am very happy it exists.
  6. rgdawson

    Change 'DPI awareness' on runtime

    When creating DPI-Aware application you must take care when locating/sizing controls in code to adjust for the current DPI. Buttons appearing off-screen sounds like that sort of problem. For example, Button.Left := MulDiv(X, Monitor.PixelsPerInch, 96), instead of Button.Left := X; You will use MulDiv alot when making DPI-Aware apps.
  7. rgdawson

    TEdgeBrowser - Any successful deployments and updates?

    I deploy WebView2 in an MS Store App. Prior, I bundled Chromium Embedded Framework. Webview2 is a wonderful thing. I originally used the built-in TEdgeBrowser, but I switched to Webview4Delphi as it is far more complete. I highly recommend WebView4Delphi (Free and Open Source, and lots of examples). Installation is rarely required these days, but my app will detect if not installed and install it on the fly using the small downloadable bootstrap installer which I embed in my app along with the WebView2Loader.dll. Automatic installation was tricky at first since, at the time, admin privileges were needed and a Store App does not have that and users may not be able to elevate. But then Microsoft made it so that the installer will allow Per-User install and then magically convert it to a Per-System install on the next system update. But, as I say, it is hard to find a system that does not already have Webview/Edge installed these days. TEdgeBrowser will suffice unless you are doing advanced stuff. I am doing some advanced stuff like injecting javascript, sending data from the web page to my app, intercepting keystrokes, security stuff, reading headers and such and TEdgeBrowser was missing those interfaces and I had to write them myself which was a pain. WebView4Delphi is far more complete. In switching from CEF to WebView my app package shrunk from about 200MB to about 15MB. And I can rely on the OS to keep everything up to date for me. With about 40,000 installs of my app, I have had zero problems.
  8. rgdawson

    The Delphi 11.2 release thread

    Upgraded my two machines from Delphi 11.1 to 11.2 (No Android. No IOs. No Linux). Web Install, keeping registry settings. Issues I noticed so far are: Both machines have GExperts Add-in. I usually always disable GExperts before using GetIt or reinstalling, or anything that will restart the IDE, as it always causes a crash on restart. On the first machine I forgot and I got an error message. I rebooted and no lasting issues. Library path for 64-bit was reset to defaults. I did have to reinstall my GetIt packages (in my case, Konopka Signature VCL Controls and LockBox) Refactoring is still broken if your code declares inline variables. I use Refactor | Rename a lot, but this does not work in files that have inline variables, so I can’t/don’t use inline variables. Please Embarcadero, fix this. It has been years. My code executables grew slightly, not enough to care. Previous issue that was in 11.1 with changing Build Group configuration is fixed. My custom toolbar buttons were retained for once.
×