View UCombSort.pas
unit UCombSort;
interface
{$IF RTLVersion <= 20.00}
{$MESSAGE ERROR 'Need Delphi 2010 or later'}
{$IFEND}
uses
{$IF RTLVersion >= 23.00}
View Open PDF via DDE for Reader 10 or later.pas
unit Unit2;
interface
uses
{$IF RTLVersion >= 23.00}
Winapi.Windows, System.SysUtils, System.Win.Registry, System.AnsiStrings,
Vcl.DdeMan;
{$ELSE}
Windows, SysUtils, Registry, {$IFDEF UNICODE}AnsiStrings, {$ENDIF}DdeMan;
View Class helper unit.pas
unit Unit2;
interface
uses
Unit3;
type
TFooHelper = class helper for TFoo
public
View How to determine Windows is server SKU
function IsWindowsServer: Boolean;
var
OSVI: TOSVersionInfoEx;
ConditionMask: UInt64;
begin
FillChar(OSVI,SizeOf(TOSVersionInfoEX),0);
OSVI.dwOSVersionInfoSize := SizeOf(OSVI);
OSVI.wProductType := VER_NT_WORKSTATION;
View Population counting (hamming weight)
unit Unit2;
interface
function PopulationCount(Value: UInt8): Integer; overload;
function PopulationCount(Value: UInt16): Integer; overload;
function PopulationCount(Value: UInt32): Integer; overload;
function PopulationCount(Value: UInt64): Integer; overload;
View Implement set type based sub-range type over 256 ordinalities
unit Unit3;
interface
uses
{$IF CompilerVersion >= 23.0}
System.SysUtils;
{$ELSE}
SysUtils;
{$IFEND}
View Implement set type based enumeration over 256 ordinalities
unit Unit2;
interface
uses
{$IF CompilerVersion >= 23.0}
System.SysUtils;
{$ELSE}
SysUtils;
{$IFEND}
View Implement IfThen by generics and advanced record
type
&IF = record
class function &Then<T>(AValue: Boolean; AThen: T; AElse: T): T; static; inline;
end;
class function &IF.&Then<T>(AValue: Boolean; AThen: T; AElse: T): T;
begin
if AValue then
begin
Result := AThen;
View Enumerate serial ports with friendly name (C++)
#include <windows.h>
#include <setupapi.h>
#include <System.hpp>
void __fastcall GetCommPortsWithName(std::vector<std::pair<int,String> >& CommPorts)
{
GUID Guid;
DWORD RequiredSize = 0;
if (!SetupDiClassGuidsFromName(_TEXT("Ports"),&Guid,1,&RequiredSize)) {
View Enumerate serial ports with friendly name
{ Setup APIs }
type
{ HDEVINFO }
HDEVINFO = THandle;
{$EXTERNALSYM HDEVINFO}
{ SP_DEVINFO_DATA }
SP_DEVINFO_DATA = packed record
cbSize: DWORD;
ClassGuid: TGUID;