Jump to content

Tommi Prami

Members
  • Content Count

    503
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by Tommi Prami

  1. Yellow, Seems that Delphis own routines are bit flaky. There has been bugs over years. Last problem I had was that TryISO8601ToDate will raise exception on string it can't parse. Will handle/eat the exception but not most optimal solution I think. By good,m I mean that handle nicely error cases, maybe has more options that Delphi version. Obviously very well tested. If also fast, I wouldn't complain. -Tee-
  2. Yellow, I have about following situation. FInstance is any TObject descendant and enum property can be any public or published Enum property, code must not link to hard coded enum type. procedure TMyThingy.SetEnumPropertyValue(const AValue: string); var LContext: TRttiContext; LRtttiType: TRttiType; LProperty: TRttiProperty; begin LContext := TRttiContext.Create; LRtttiType := LContext.GetType(FInstance.ClassType); LProperty := LRtttiType.GetProperty(FPropertyName); // Here I should convert lets say TMyEnum = (A, B, C) from string into the property value // if I call SetEnumPropertyValue('B') property FPropertyName from FInstance-object should be set. end; This should be quite simple, couple lines of code most likely. Could not find sample code that was good enough fit to get this to work, there usually was too much knowns, like enum type TMyEnum, This should be totally dynamic. Circled around this quite long time, just could not find the way to connect all the dots... -Tee-
  3. Have to try to remember that. Not used it too much. Thanks for helping! -Tee-
  4. This lead me one step closer. var LEnumValue: Integer; LEnumValue := GetEnumValue(LProperty.PropertyType.Handle, AValue); if (LEnumValue <> -1) and LProperty.IsWritable then LProperty.SetValue(FInstance, LEnumValue); With this I get the actual value, but setting the value does not work (More than less same code is used elsewhere and they work). It raises EInvalidCast with message 'Invalid class typecast'. Integer is correct value for the Enum, it is in between bounds. This slightly baffles me now.
  5. Oh, I forgot to mention that should work public properties also, I modify original, I still can... MAybe it is now more clear what I am after... -Tee-
  6. I think I explained myself poorly. That won't work because it depends on TypeInfo(TMyEnum) My code must not know/depend on the (hardcoded) type, it should be dynamic. Work with any given property, that is any type of Enum (some limitations may apply, but if works simple enums like one in example, it is OK).
  7. Apparently LAEL ("address calculator") can do multiply by 2, 4 and 8 very fast. Don't know anything about details, difference to other op codes etc... Subject starts from here, at C to llvm IR -> to asm : -Tee-
  8. That might be true, I should have it somewhere. Should read it again. I have only checked few specific things from it.
  9. https://towardsdatascience.com/34-faster-integer-to-string-conversion-algorithm-c72453d25352 To my understanding Delphi has bit different algorithm, but looking at "default implementation" mentioned article or one Delphi has, it is pretty complex beast in either case, and some what computationally heavy. Delphi has lookup tables and DivBy100() which I would guess it'll make it faster than the "default implementation". Not sure tough. lr_printer Github repo: https://github.com/tigranh/lr_printer -Tee-
  10. Tommi Prami

    Delphi 12.1 is available

    Mine did not. Restarting encountered into same dll-error, don't remember which dll it was. and did not take screnn shot etc. 😞 Coworker cant open IDE even after clean install... Freezes at the Splash Screen... -Tee-
  11. Tommi Prami

    Delphi 12.1 is available

    Remember to uninstall Parnassus-plugins before installing. Web Installer failed because forgot to uninstall them first. Had to make installer to clean all settings. Takes some time to get all settings as needed because of that. -Tee-
  12. Tommi Prami

    kuLibrary

    Could you instead of the site update all to the GitHUB, so it would be much easier and better place to public open source library. And keep it up there, and if needed link your own site to the GirHUB and maintain only that actyively. -Tee-
  13. No idea how it would be done, but for more than less static lookup list etc, this could be very good idea.
  14. Did not know that. Thanks for info... -Tee-
  15. Hello, I was pondering folowin situation, where there are easily quite many repeating code lines, and how to make int onew liner. var var LField1: TField; LField2: TField; LField3: TField; LField4: TField; begin LField1 := Query.FieldByName('FIELD1'); LField2 := Query.FieldByName('FIELD1'); LField3 := Query.FieldByName('FIELD1'); LField4 := Query.FieldByName('FIELD1'); // ... // Should be nice to have it like this InitField(Query, [LField1, LField2, LField3, LField4], ['FIELD1', 'FIELD2', 'FIELD3', 'FIELD4', ]); It would be easy to make local procedure, case by case with var parameters etc, but that would not be very elegant. What I mean by dynamic, is that it would handle any number of fields and field names, oas long as there are same number of them passed to the procedure.. Other case would be that could pass local variables and the routine would create those objects for me on single line.
  16. True, Calculating the sum was just placeholder of some calculation going on in the loop But very true, if can get sum forehand, would be smart to get it. -Tee-
  17. As Uwe explained...
  18. Depends of number of calls and fields. If 8 field 50 places, it would be from 400 -> 50 lines of code. I think it would be significant, Would be net win after first one. And would make the procedure way more clean, without initialization code in it.
  19. Does not work, know because I've tried that approach in the past, and retried your code and it does nothing. (outside of procedure, which is the important part), // usage var Field1, Field2, Field3, Field4: TField; begin Field1 := nil; // ... Field2, Field3, Field4 ConnectFields(Query, [ Field1, Field2, Field3, Field4], ['Field1', 'Field2', 'Field3', 'Field4']); // Fields star as they are in here, nil or not nil, doesnt matter... But eassy to check by nilling the fields becore and after call. Other problem in this tat compiler starts to complain about Fields are uninitialized. But that is separate issue...
  20. Nice could be done something like that,. but field names are not indexed, usually and after that it is just the same as the my original example I am trying to solve... But Not looking for workaround... -Tee-
  21. Yes... But totally different thing... And would have exact same problem. Would need to initialize variables for indexes by name. Constant magic number indexes leads to buggy code. I am looking for solution for getting fields, and also solution for other cases I could adapt it to. Getting fields is just one use case of this type of procedure I would like to use... -Tee-
  22. var LTotal: Double; LField1: TField; LField2: TField; LField3: TField; LField4: TField; begin LField1 := Query.FieldByName('FIELD1'); LField2 := Query.FieldByName('FIELD1'); LField3 := Query.FieldByName('FIELD1'); LField4 := Query.FieldByName('FIELD1'); Query.First; while not Query.Eof do begin LTotal := LTotal + LField1.AsFloat; // More stuff done with local field variables... Query.Next; end; In this case, TDataSet and TField are RTL stuff or their descendants... So implementation should be kind that works if I have no control over the API of the class.. -Tee-
  23. In this case I get the field usually when they are needed in the loop, or get rid of with-clause or something like that.
  24. Tommi Prami

    What new features would you like to see in Delphi 13?

    Even something like 1.5 pass compiler that would enable some functionality or extend existing would be cool to have... -Tee-
×