Jump to content

Kryvich

Members
  • Content Count

    179
  • Joined

  • Last visited

  • Days Won

    5

Kryvich last won the day on November 18 2018

Kryvich had the most liked content!

Community Reputation

56 Excellent

1 Follower

Technical Information

  • Delphi-Version
    Delphi Community Edition

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Kryvich

    Test Bits in a Byte

    @haentschman It's always better to have named constants instead of numbers. Say you want to swap 2nd and 6th bits in some structure's field. Then you need to scan all your program and check all places where these bits are used. But if you used an enumeration from the start, you just swap these bits in the declaration: type TMyEnum = (mb0, mb5, mb2, mb3, mb4, mb1, mb6, mb7); Of course instead of mb0, mb1 etc. should be really meaningful names, without numbers.
  2. Kryvich

    Test Bits in a Byte

    You can write it as If ((b and $01) > 0) or ((b and $08) > 0) or ((b and $80) > 0) then ... Or you can create an enumeration and use meaningful names for each bit. type TMyEnum = (mb0, mb1, mb2, mb3, mb4, mb5, mb6, mb7); TMyBits = set of TMyEnum; // = Byte in size function Test: Byte; var mbs: TMyBits; begin mbs := [mb0, mb3, mb7]; Byte(mbs) := $89; // It's equivalent of mbs := [mb0, mb3, mb7]; if mbs * [mb0, mb3, mb7] <> [] then // If one of bit is set ;//... if mbs * [mb0, mb3, mb7] = [mb0, mb3, mb7] then // If all 3 bits are set ;//... if mbs - [mb0, mb3, mb7] = [] then // If no other bits are set ;//... Include(mbs, mb1); // Set 2nd bit mbs := mbs - [mb3, mb7]; // Unset 4th and 8th bit //etc... Result := Byte(mbs); end; It's always better to deal with clearly named typed variables and constants.
  3. Kryvich

    Recompile Delphi RIO RTL/VCL?

    @A.M. Hoornweg In newer Delphi versions you must put the $RTTI directive on each library unit. This is the main difference from XE. @Rollo62 I brought some statistics for my applications here:
  4. Kryvich

    Am I using IF correctly?

    I would write it as localVar := ParameterValue; if localVar = None then localVar := DefaultValue; Presume that ParameterValue is assigned in most cases, then DefaultValue will not be accessed in most cases.
  5. Kryvich

    Recompile Delphi RIO RTL/VCL?

    Perhaps this will help:
  6. https://stackoverflow.com/questions/2113182/fillchar-but-for-integer-cardinal
  7. Kryvich

    Block windows access

    Using the Group Policy Editor it is possible to prevent users from accessing to Ctrl-Alt-Del options. https://ccm.net/faq/41738-how-to-prevent-users-from-accessing-the-task-manager
  8. You're right. We can compare the squares of distances: checkDistance2 := Sqr(checkDistance); ... dist2 := Sqr(X1-X2) + Sqr(Y1-Y2); if dist2 < checkDistance2 then .....
  9. @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;
  10. @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.
  11. @Schokohase It worked, thanks! Can you explain why?
  12. 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.
  13. 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.
  14. 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
  15. 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.
×