Jump to content

Lars Fosdal

Administrators
  • Content Count

    3504
  • Joined

  • Last visited

  • Days Won

    115

Everything posted by Lars Fosdal

  1. Lars Fosdal

    Delphi Version Numbers

    https://blog.dummzeuch.de/2014/04/17/determine-the-delphi-installation-directory-from-a-batch-file/ gives some clues. IMO, the versioning variations border on ridiculous.
  2. It quite often doesn't work. I blame the debugger. One thing that helps a little, is to make sure that you switch the active thread to the one where you expect the break - but it is no guarantee.
  3. We use frame/form inheritance for look and feel for some dialogs - but it is indeed a PITA.
  4. Lars Fosdal

    GetIt

    VSCode is ok for files sizes within what is normal for source code. If you have source files that are megabytes of data, VSCode is not your biggest problem. VSCode does not compile projects. It is an editor. Any compilation is done by an external compiler. The VSCode + plugin updates are seamless and recovers your workspace in the exact same state as you had before the update - even including unsaved files. Why would you postpone an update to an editor? Comparing VS with VSCode is apples and oranges. Of course any VSCode plugin will only be as good as the developer or team behind it - just like plugins and components for any IDE.
  5. Lars Fosdal

    More performance Stringgrid sorting algorithm help

    I like inline declarations with their scope limitations. I particularly like the inline declaration of loop variables with type inference. I do not like the leaks inline declared variables can cause with captures. https://quality.embarcadero.com/browse/RSP-29564
  6. I was pondering on what I could do to simplify doing ad-hoc queries and minimize the scaffolding code required, so I came up with this. Note that this code was yanked from one of our units, and hence is not directly runnable as it is missing some functions, and the code that sets up the connection, etc. - but it should give you the general gist of it works. It is not pretty nor perfect, but it works, and if there are glaring mistakes or potential problems, I expect you will tell me all about them 🙂 unit SomeUnit; type RUser = record id: Integer; name: string; displayname: string; end; implementation procedure TSomeClass.ListThoseUsers(const aDB: TDatabase); var Users: TArray<RUser>; begin Users := DB.SelectArray<RUser>('select id, name, displayname from v_users'); // Do whatever you need to do with the user list here end; I am pretty sure that you can create records with fields of types that will cause the TValue conversion to fail horribly, but this deals fine with the basic types as well as enumerated types. Note that the record type needs to be declared in the unit's interface section to get the proper RTTI. Doing a test run from at home to a database server in Trondheim, 700km away - the logs showed SelectArray<SomeUnit.RUser>("select Id, Name, DisplayName from v_users") returned 161 rows in 0:00,024 24 ms is not blisteringly fast, but acceptable. function TDatabase.SelectArray<T>(const sSQL: String): TArray<T>; var Info: String; StopWatch: TStopWatch; Query: TFDQuery; Retry: Boolean; FieldName, RetryMsg: string; rType: TRTTIType; RecField: TArray<TRTTIField>; DBField: TArray<TField>; fx, rx, rc: Integer; begin Retry := False; repeat if Connect then try if Retry then RetryMsg := '#RETRY ' else RetryMsg := ''; StopWatch := TStopWatch.StartNew; rtype := TRTTIContext.Create.GetType(TypeInfo(T)); Info := RetryMsg + 'SelectArray<'+rtype.QualifiedName+'>("' + sSQL+ '") '; Query := TFDQuery.Create(nil); Query.Connection := Connection; Query.ResourceOptions.ParamCreate := False; Query.FetchOptions.Mode := fmAll; Query.FetchOptions.Unidirectional := Unidirectional; Query.SQL.Text := sSQL; try Query.Open; rc := Query.RecordCount; if (Query.FieldCount >= 1) and (rc > 1) then begin RecField := rtype.GetFields; // Fetch field list from record type SetLength(DBField, Length(RecField)); try // Lookup record fields in database result set. Will raise exception if field not found for fx := Low(RecField) to High(RecField) do begin FieldName := RecField[fx].Name; DBField[fx] := Query.FieldByName(FieldName); end; except on E: Exception do begin Info := Info + ' - Field ' + rType.QualifiedName + '.' + FieldName + ' was not found in result set.'; raise; end; end; // for each row in the result set SetLength(Result, rc); for rx := 0 to rc - 1 do begin for fx := Low(RecField) to High(RecField) // for each field in the record, transfer row field to record field do begin if RecField[fx].FieldType.TypeKind = tkEnumeration then RecField[fx].SetValue(@Result[rx], TValue.FromOrdinal(RecField[fx].FieldType.Handle, DBField[fx].AsInteger)) else RecField[fx].SetValue(@Result[rx], TValue.FromVariant(DBField[fx].Value)); end; Query.Next; end; if DebugLogging then DebugOut(Info + ' returned ' + rc.ToString + ' rows in ' + TimeSpanToStr(StopWatch.Elapsed)); end else begin SetLength(Result, 0); end; finally Query.Free; end; Retry := False; except on DBE:EFDDBEngineException do begin LogDBException(DBE, Info, Retry); if not Retry then RAISE; end; on E:Exception do begin LogException(E, Info); RAISE; end; end else raise EDbConnectionFailure.Create(Info + ' DB Error: Could not connect.'); until not Retry; end;
  7. Lars Fosdal

    GetIt

    GUI Design? Not so much, except from SVG fiddling. Mostly PowerShell programming and debugging. Many other languages support debugging in VSCode. Then there is searching in source code. Make a workspace, add your source code folder(s), add the source directories for Delphi and third party code. Search in files, search in current file, highlight selected text. Awesome. My point was originally focused on the ease of upgrade of the IDE and it's plug-ins.
  8. Lars Fosdal

    GetIt

    Off topic is my modus operandi, it seems.
  9. Lars Fosdal

    GetIt

    I was being overly polite.
  10. Lars Fosdal

    GetIt

    Lots of Py support in VSCode too.
  11. Lars Fosdal

    GetIt

    Whenever I am in VSCode, I am looking at the Delphi IDE and sighing. Its age is starting to show.
  12. As ORMs go, this one would be veeery light weight.
  13. Shift-F7 - Trace to Next Source Line
  14. For us, it is typically third party systems that deal with production handling, i.e. whenever something is labeled with a serial number and/or a weight, - or added, removed or repositioned in some robotic storage system, or a laboratory system changes the approval status of a production batch. The WMS needs to know what is where, in what condition, at all times. The architecture is over a decade old, and if redesigned from bottom up today - probably none of the involved parties would have direct access to the DB. None of our software uses data-aware components.
  15. Lars Fosdal

    remove ExplicitXxxx properties

    I freaking loathe those explicit... props. Whoever introduced them should have had all their key caps removed.
  16. Lars Fosdal

    Unit scope names in IDE - possible 2+ lines?

    I didn't know that shortcut, but for me it also woke up the Intel gfx settings. As you said, you can disable the hotkeys in that app - and suddenly, Ctrl+Alt+F12 drops down the opened unit list. Thanks, man!
  17. Lars Fosdal

    Unit scope names in IDE - possible 2+ lines?

    There is also that little drop down at the right end of the unit tabs. Otherwise, Ctrl+F12 is nice as well.
  18. @Attila Kovacs The SPs often contain business logic, validation/sanitation, state change logging, queueing to signaling mechanisms, etc. - and can be called from multiple external systems. With a lot of concurrent actors, transactional integrity is a challenge.
  19. @Jacek Laskowski We don't do direct insert/update/delete operations from the client software - but have to explicitly call stored procs instead. Client does not have rights to do inserts/updates - and may only call a specific set of database routines.
  20. @Attila Kovacs - ORMs are nice, but this project didn't use one.
  21. Nice one, Uwe! I see I am late to the show 🙂
  22. Lars Fosdal

    UCS4StringToWideString broken?

    @A.M. Hoornweg Being a bit pedantic now, but you would save the QA and developers quite a bit of work if your example was a complete console program.
  23. Lars Fosdal

    Variation of FormatDateTime(

    @Ian Branch - I deleted the post. It was mostly off topic, which seems to be my default modus operandi
  24. Lars Fosdal

    Is variable value kept after For.. in ... do loop?

    Yeah... you are not the only one.
×