Jump to content

Kryvich

Members
  • Content Count

    407
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by Kryvich

  1. You're right. We can compare the squares of distances: checkDistance2 := Sqr(checkDistance); ... dist2 := Sqr(X1-X2) + Sqr(Y1-Y2); if dist2 < checkDistance2 then .....
  2. @Lars Fosdal Sorry I cannot help you with it. I tried the attribute [JsonReflectAttribute(ctObject???,rtObject???,TArrayElementInterceptor)] but there is no a converter/reverter type that accepts values of any type: strings, numbers, and objects. Perhaps you may need to create a descendant of TJSONUnMarshal to handle all the options. It would be great if Embarcadero improves JSON support and allow to convert other types to a custom record if this record can take values of other types: type TSwitch = class private FSwitch: Boolean; public property Switch: Boolean read FSwitch write FSwitch; end; TArrayElement = record private FValue: Variant; public class operator Implicit(const Value: Integer): TArrayElement; class operator Implicit(const Value: string): TArrayElement; class operator Implicit(const Value: TSwitch): TArrayElement; end;
  3. @Schokohase In fact RTTI is generated for types declared in a DPR file. But it is not findable by TRttiContext.FindType(AQualifiedName: string). In the Delphi help for the function FindType it is written: But there is no information what types have qualified names. And only in System.Rtti.pas I found this comment: @Lars Fosdal Unfortunately, this will not work for the Variant type without additional processing. You can try to declare a custom reverter for an element of the inner array.
  4. @Schokohase It worked, thanks! Can you explain why?
  5. May be TMessageArray = array of array of Variant; ? program TestJson; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, REST.Json; const JsonData = '{' + ' "message": [' + ' [ 0, "a text" ],' + ' [ 1 ],' + ' [ 1, { "switch": true } ],' + ' [ 2, "text one", "text line two" ]' + ' ]' + '}'; type TMessageArray = array of array of Variant; TJsonMessage = class private Fmessage: TMessageArray; public property message: TMessageArray read FMessage write FMessage; end; var Message: TJsonMessage; begin try if TypeInfo(TJsonMessage) = nil then Writeln('No RTTI for ', TJsonMessage.ClassName); Message := TJson.JsonToObject<TJsonMessage>(JsonData); Writeln('Length = ', Length(Message.message)); Message.Free; except on E: Exception do begin Writeln(E.ClassName, ': ', E.Message); Readln; end; end; end. I tried this option, but my test application gives the exception: "Exception class EConversionError with message 'Internal: Cannot instantiate type TestJson.TJsonMessage'.". I still do not understand why.
  6. Having access to source files of the project perhaps it would be easier to extract all the necessary information from the source code using DelphiAST or similar parser.
  7. I've checked this function in 10.2.3 and 10.3, and it works identically in both cases. When I set a text size = 125%, the app shows 1.25. Windows 7 64 bit. Demo app is attached. TestGetScreenScale.zip
  8. Kryvich

    IDE Fix pack for Rio

    Delphi 10.3 with IDE Fix Pack dev 2018-12-11-2343, Compiler Speed Pack x86 / x64 dev 2018-12-11-2343 -- 05 min 53 sec. :) IDE Fix Pack is an IDE package that I always installed the very first when switching to a new version of Delphi.
  9. Kryvich

    What does TDataSet.CopyFields do?

    @Uwe Raabe Of course, https://quality.embarcadero.com/browse/RSP-22946
  10. Kryvich

    What does TDataSet.CopyFields do?

    @Dany Marmur No, it does not work. You can see for yourself: I have prepared a test application with 2 in-memory datasets and 2 nested datasets (see TestCopyFields.zip in the attachment). Values of fields of the nested dataset are not copied: But if you copy the Data.DB.pas to the application's folder and make the modification I suggested, it works: I think Embarcadero never tested this feature. Honestly, I myself learned about nested data sets only today. TestCopyFields.zip
  11. Kryvich

    What does TDataSet.CopyFields do?

    @Dany Marmur I would say the else section is for fields that are not inherited from TDataSetField.
  12. Kryvich

    Pointers are dangerous

    @dummzeuch There could be a warning: "The pointer ptr1 to an element of the array arr is invalid after its reallocation by the function SetLength". There is a plenty of static code analyzer for Delphi - https://stackoverflow.com/questions/532986/are-there-any-static-code-analysis-tools-for-delphi-pascal. But I do not know one that catches this error. It would be great to have a utility for Delphi similar to PVS Studio.
  13. 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.
  14. Kryvich

    Pointers are dangerous

    A good case for a static code analyzer.
  15. Kryvich

    What does TDataSet.CopyFields do?

    Looking at the function code, I would say that it copies the field values of the current record from the source data set to another data set. It also copies records of all nested data sets. But I think there is a bug in their code: instead of CopyFields(TDataSetField(DestField).NestedDataSet); should be TDataSetField(DestField).NestedDataSet.CopyFields(TDataSetField(SourceField).NestedDataSet); Not tested yet.
  16. Kryvich

    Units design

    I would go with Example A. But exclude not used utility units from uses clauses of your units. Error Insight does not like conditionally compiled blocks, especially in the definitions of types and classes.
  17. According to the Delphi roadmap: High DPI IDE support is planned for 10.3.x.
  18. Kryvich

    RttiMethod Invoke (invalid class typecast)

    procedure Run is a method of object, not a class method. So you need an object instance to call the method.
  19. Kryvich

    IDE Fix pack for Rio

    Well, I'm sure Andreas Hausladen could improve the result for 10.3 anyway.
  20. Kryvich

    Delphi 10.3

    Delphi 10.3 Rio is out so please add Delphi 10.3 to the profile.
  21. Kryvich

    IDE Fix pack for Rio

    I measured a time to build the camera_shake.dpr project from TERRA-Engine framework in Delphi 10.2.3 and Delphi 10.3. TERRA Engine is a complex cross-platform engine, known for its cyclic unit references, and freezes in IDE. Camera_shake.dpr project build time, Windows 32-bit platform: Delphi 10.2.3 with IDE Fix Pack 6.3.1, Compiler Speed Pack x86 / x64 6.3.1 -- 06 min 59 sec. Delphi 10.3 -- 06 min 33 sec. I measured the time on my phone manually, so there may be some error.
  22. As you know, modern Delphi versions add the RTTI information to the executable file. RTTI gives you the opportunity to do incredible things in your application. But it is not always necessary. You can disable RTTI in your application by adding the following lines to each unit: {$WEAKLINKRTTI ON} {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} But to completely disable RTTI, you need to add these lines to used RTL units too, and rebuild the project. How much will the size of the executable file decrease? Well, I checked it on small utilities from the Delphi Localizer project, and here is the result: kdlscan.exe was 742400 bytes, now 360448 bytes, -51% lngupdate.exe was 727040 bytes, now 282112 bytes, -61% (!!!) The smaller size of an executable file means that the file is read twice as fast from disk. In addition, the processor is more likely to be able to fully fit your utility into its cache. You can give other reasons why this makes sense.
  23. Once I make a utility that the user ran from a network drive. Moreover, it was launched many times during the day to process incoming documents. Then they asked me to make the EXE file as small as possible to speed up the processing. Removing RTTI from the executable file has greatly accelerated the workflow.
  24. @KodeZwerg First, read the remark from Stefan Glienke above. Advanced RTTI available in Delphi since version 2010. So applications compiled in Delphi 5 do not contain it. Yes it is. You can find the complete list of units contained in your application in the PACKAGEINFO resource in your executable file. Use a resource viewer to access it, for ex. Restorator. There is BuildWinRTL.dproj in source\rtl. You can copy the RTL folder to your work folder, inject the code to disable RTTI in every used PAS file, check Search path and Unit output directory (instead of "$(BDSCOMMONDIR)\lib\$(Platform)" you can set "..\lib\$(Platform)"), check build configuration (Release, Win32) and rebuild the BuildWinRTL project. You'll find DCU files in the lib\Win32 folder. In case you use any other VCL units and third-party libraries you should inject the code in every PAS file of these libraries too, to remove RTTI completely. Copy the used VCL units to a separate folder in your working folder, do not modify the files in the Source folder of Delphi. Make sure your application’s search path for the Release build configuration points to the recompiled DCU files of RTL, and to modified PAS files of VCL. Now you are ready to compile your application without RTTI.
  25. Kryvich

    Releasing memory devoted to arrays

    @Gary Mugford The assignment "VPP := 0;" right before the second assignment you can delete. Actually the compiler must generate a hint: H2077 Value assigned to 'VPP' never used. Check the Messages view after compilation: there may be other hints and warnings. You can ensure that the fields have proper values by inserting assertions right before the assignment: Assert((fieldByName('Parm1').AsFloat >= 0.00002) and (fieldByName('Parm1').AsFloat <= 20), 'Bad Parm1 value: ' + fieldByName('Parm1').AsString); Assert((fieldByName('ParmBV').AsFloat >= 200) and (fieldByName('ParmBV').AsFloat <= 500), 'Bad ParmBV value: ' + fieldByName('ParmBV').AsString); I myself often use assertions at the beginning of a method to make sure that input parameters are correct. You can leave them in the code, because assertions usually do not affect performance of an application.
×