Jump to content

Lars Fosdal

Administrators
  • Content Count

    3303
  • Joined

  • Last visited

  • Days Won

    110

Everything posted by Lars Fosdal

  1. Lars Fosdal

    Memo scrolling to the bottom ... sometimes

    ah no - dang - I missed that it was Android. Moved the post again.
  2. Lars Fosdal

    Memo scrolling to the bottom ... sometimes

    No worries. I moved it to VCL. What if you try: SendMessage(Memo1.Handle, EM_SCROLLCARET, 0, 0); instead of the goto/scrollto ?
  3. Lars Fosdal

    Memo scrolling to the bottom ... sometimes

    Is there any difference in behaviour if you SetFocus GoToTextBegin ScrollToTop instead? Can you reproduce the problem in a minimal app?
  4. Edit: I rewrote this on my blog: https://larsfosdal.blog/2019/10/31/demystifying-pointers-in-delphi/ Having a general understanding of how memory and addressing works, helps a bit for pointers. Learning assembler gives you that knowledge, but there are simpler ways to think about it. A pointer is a memory location that contains the address to the actual data you want Think of a street with houses. Make a list of the houses and their addresses. This is a list of pointers. Each pointer leads to the actual house it refers to. As you move through the list and follow each pointer, you can visit each house. Street of houses (i.e. your blocks of data, 1Kb each) 10k 11k 12k 13k 14K +------------+------------+------------+------------+------------+ |Apple |Pear | |Banana |Orange | | H1 | H2 | | H3 | H4 | | | | | | | +------------+------------+------------+------------+------------+ Your list of addresses (aka 4 byte pointers) is stored at memory address 100k var ptrlist: array[0..3] of pointer; assuming the list has been initialized with the correct addresses ptrlist[0] 100k contains 10k ptrlist[1] 100k+4 contains 11k ptrlist[2] 100k+8 contains 13k ptrlist[3] 100k+12 contains 14k for var ix := 0 to Length(ptrlist) - 1 do begin here, ptrlist[ix] = 10k,11k,13k,14k, and ptrlist[ix]^ = whatever value that is stored in the respective house the pointer addresses f.x. ptrlist[1] contains 11k (and that value is stored at 100k+4, and ptrlist[1]^ points to 'Pear', i.e. whatever is stored from address 11k Why the empty house? To exemplify that your list of pointers may be a consecutive array or linked list, but the data each pointer points to does not necessarily need to be consecutive. Now, if you address ptrlist[4] - you are out of bounds on the pointer list, and if you are so "lucky" that the address @ptrlist[4] (which is 100k+16) is not inaccesible, then ptrlist[4]^ will point you to whatever random value that pointer contains,, and most likely give you an access violation, or for sure - point you to data you are not meant to visit.
  5. I have a class type that I call a GridSet, and I use RTTI to match object prop names with DB field names (and attributes for overrides) for multi-row datasets, I build a list of property setters that are ordered the way the fields exist in the DB, for all the fields that exist both in the data set and the object and then I simply loop that list row by row when loading the dataset. I also have an attribute driven variation of filling a GridSet that builds the field definitions dynamically from the DataSet - so that I basically can fill the GridSet from any query, and display it in my GridView class, which attaches to a TAdvStringGrid and sets up the grid purely in code with the various event handlers for sorting and filtering. Hence I can show the result of any query in a grid with one line of code - no visual design required. The benefit of declaring the fields in a gridset, is that I can specify nicer titles, max widths, hints, etc.
  6. Consider this pseudo code uses Rest.Json; TDateClass = class private FHasDate: TDateTime; FNoDate: TDateTIme; public constructor Create; property HasDate: TDateTime read FHasDate write FHasDate; property NoDate: TDateTime read FNoDate write FNoDate; end; constructor TDateClass.Create; begin HasDate := Now; NoDate := 0; end; var Json: String; DateClass: TDateClass; begin DateClass := TDateClass.Create; Json := TJson.ObjectToJsonString(Self, [joIgnoreEmptyStrings, joIgnoreEmptyArrays, joDateIsUTC, joDateFormatISO8601]); which results in the Json string looking like { "HasDate":"2019-02-14T06:09:00.000Z", "NoDate":"1899-12-30T00:00:00.000Z", } while the ideal result would be { "HasDate":"2019-02-14T06:09:00.000Z", } Q:Is there a way to make TDateTime properties with a zero value be output as an empty string - and hence be stripped?
  7. I guess we've avoided the problem since we only have used Zulu timestamps. "departureDate":"2019-10-28T06:00:00.000Z", The problem is at the bottom of procedure DecodeISO8601Time in System.DateUtils- That is where the assumption is made that there will always be a time separator if there is a minutes section AHourOffset := StrToInt(LOffsetSign + GetNextDTComp(P, PE, InvOffset, TimeString, 2)); AMinuteOffset:= StrToInt(LOffsetSign + GetNextDTComp(P, PE, '00', STimeSeparator, True, True, InvOffset, TimeString, 2)); Please make a QP.
  8. @Attilla, from the theorist side if a time zome colon is mandatory in a ISO8601 date, then the problem is really that php API, isn't it? While if a colon is optional, the Delphi implementation of the conversion seems lacking, hence a QP would be a starting point. From the more practical side - Is using class based Json conversion out of the question? - Would pre-processing be an option to correct for the format deviation, f.x. by reg.exp searching for the dddd-dd-ddTdd:dd:dd+dddd and injecting the missing colon
  9. Lars Fosdal

    SetFocus issue

    Is it just me, or does it seem to be slightly different behavior for Focus and BringToFront in Windows 10 1809 and later? I've had several experiences with Application modal windows popping up behind the main window, and it has not only been my own Delphi apps. Starting a Delphi App in the IDE for debugging, would leave the app running behind the BDS now and then. I've had MSSQL Server Management Studio 17.x become unusable with a popup locked behind its main window when left running overnight, on several occasions.
  10. Lars Fosdal

    Parsing Google Search Results redux

    I've been wondering about those... Where do I download/install these? Can't see them in GetIt.
  11. Lars Fosdal

    HEIC library

    Sorry, no idea. This was courtesy of Google search, but judging from the description, it should be a reasonably standard plugin for WIC, so the indentifiers should be discoverable through the WIC interfacees.
  12. Lars Fosdal

    HEIC library

    https://www.copytrans.net/copytransheic/ installs a driver for Windows Imaging Component that allows conversion with WIC and is, as far as I can tell, free.
  13. Lars Fosdal

    LiveBinding at runtime

    We already had something else doing the job for us, so we had no need to transition to it. The fragile bit can be only be eliminated when we get a NameOf compiler magic function.
  14. Lars Fosdal

    Interesting article about dying languages

    Jack of all trades, master of none - seems to be my modus operandi, which is more or less the same as sucking equally at everything 😉
  15. Lars Fosdal

    LiveBinding at runtime

    Live bindings were dead to me after a short test. Fragile and slow was not a winning combo.
  16. It probably disappeared when they introduced TListHelper. GetList returns arrayofT(FListHelper.FItems);
  17. Lars Fosdal

    Azure Key Vault support

    Feel free to vote for https://quality.embarcadero.com/browse/RSP-26400 if you need Azure Key Vault support for your Delphi/C++Builder projects.
  18. Lars Fosdal

    How to get Linux installed?

    It is truly tragic that Linux is not available for the Pro SKU. It should even have been in the Community version IMO. Imagine the potential plethora of code coming from open source projects.
  19. Lars Fosdal

    Interesting article about dying languages

    https://larsfosdal.blog/2019/10/10/most-popular-programming-languages-1965-2019/ Stumbled on a nice video showing the rise and fall of Pascal and Delphi. That said, like Cobol, Delphi will take a looong time disappearing.
  20. Lars Fosdal

    Add a system-menu item to all applications?

    Adulthood is overrated.
  21. The output of the test app below surprised me. Can someone point me to the documentation that says that if a static class method calls a virtual class method, only the base class virtual method will be called, and not the override? TParent.HasOverride: I said no to overrides TParent.HasOverride Static: I said no to overrides TChild.HasOverride: I haz overridez TChild.HasOverride Static: I said no to overrides Press Enter: program StaticClassMethodCallingVirtualClassMethod; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; type TParent = class public class function OverrideMe: Boolean; virtual; class function HasOverride: string; class function HasOverrideStatic: string; static; class procedure Test<T: TParent, constructor>; end; TChild = class(TParent) public class function OverrideMe: Boolean; override; end; { TParent } class function TParent.HasOverride: string; begin if OverrideMe then Result := 'I haz overridez' else Result := 'I said no to overrides'; end; class function TParent.HasOverrideStatic: string; begin if OverrideMe then Result := 'I haz overridez' else Result := 'I said no to overrides'; end; class function TParent.OverrideMe: Boolean; begin Result := False; end; class procedure TParent.Test<T>; begin Writeln(T.ClassName, '.HasOverride: '^I^I, T.HasOverride); Writeln(T.ClassName, '.HasOverride Static: '^I, T.HasOverrideStatic); end; { TChild } class function TChild.OverrideMe: Boolean; begin Result := True; end; begin try try TParent.Test<TParent>; TParent.Test<TChild>; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; finally Write('Press Enter: '); Readln; end; end.
  22. < wishful > I keep running into cases where I have to manually duplicate the name of a constant to register it for lookup, or associate the constant with a numeric ID which then is used for the lookup. Either method means double book keeping and is error prone. Some of it would be nicely handled by having a compiler magic NameOf method that could give me name of a constant, field or property as a string at compile time. In other cases it would have been awesome to be able to enumerate a class or a record and get the declared constant names, types and values. This particularly goes for types I want to document for f.x. a JsonRPC API. Instead, I have to manually emit that information, constant for constant, which means someone will eventually forget to do that. If only the compiler gods where listening... < / wishful >
  23. OK, that makes sense. But - it is a bit of a pitfall, since you can call virtual methods from the static one - and not get a warning about it.
  24. https://community.idera.com/developer-tools/b/blog/posts/gm-update?utm_source=Article&utm_medium=email&utm_content=Article-190924-GMUpdate See also Jim's blog https://community.idera.com/developer-tools/b/blog/posts/the-future-of-codecentral
  25. I considered XMLDoc, but compile and runtime validation won out.
×