Thursday, 18 June 2020

D&D in Delphi source code?

- or does your device support Phone, Tablet or Elf?!




While looking through some of the RTL source code, in the quest for the "Tablet" mode (see my previous post from yesterday) - I stumbled upon the TDeviceInfo.TDeviceClass enum.


So my small application has just listed the ID and the name of the TDeviceClass enum, for my old Surface Pro - together with one I added for fun. The one I added has a strange TDeviceClass value.

Following that is the full list of named enum values of TDeviceInfo.TDeviceClass - notice the last 3.


Maybe D&D does not refer to Dungeons & Dragons, but DeviceInfos & DeviceClasses.... well someone had fun at some point of time sneaking them in, and I hope that Embarcadero does not plan to remove those extra "classes" - since the might break backwards compatibility - with my newly added Rincewind deviceInfo :D

Just a small silly finding I wanted share - nothing useful - but no post without code :)

uses
  System.Devices,
  System.TypInfo;

procedure TForm1.Button1Click(Sender: TObject);
var
  s: TSize;
begin
  // Let us add a silly device
  s.cx := 100;
  s.cy := 100;
  TDeviceInfo.AddDevice(TDeviceInfo.TDeviceClass.Wizard, 'Rincewind', s, s, pfLinux, 96);
  // Let us see what are known
  Memo1.Lines.Add('-- Known devices: Name and Class');
  for var d: Integer := 0 to TDeviceInfo.DeviceCount-1 do
    Memo1.Lines.Add(TDeviceInfo.Devices[d].ID+' - '+
      GetEnumName(TypeInfo(TDeviceInfo.TDeviceClass), ord(TDeviceInfo.Devices[d].DeviceClass)));
  // Let us see possible value of a TDeviceClass
  Memo1.Lines.Add('');
  Memo1.Lines.Add('-- TDeviceClass enums:');
  for var i: TDeviceInfo.TDeviceClass :=
    Low(TDeviceInfo.TDeviceClass) to High(TDeviceInfo.TDeviceClass) do
      Memo1.Lines.Add(GetEnumName(TypeInfo(TDeviceInfo.TDeviceClass), ord(i)));
end;

Enjoy

Update: Brian Long has already mentioned this in #24 of his beatiful blong #Delphi25 post here - which I originally missed.

Another update: Jim McKeeth informed me that the official DocWiki now does included the "Fantasy devices": https://docwiki.embarcadero.com/Libraries/en/System.Devices.TDeviceInfo.TDeviceClass with proper description :) Thanks Jim.

Elf

Tiny being with pointed ears.

Dwarf

Short being that dwells in mountains and is associated with smithing, mining and crafting.

Wizard

Being who practices magic, also known as magician or mage.


BTW: I used the DNDC font from famfonts.com

No comments:

Post a Comment