Utils library

Delphi and C++ Builder utilities library.
  • available for Delphi/C++ Builder 7 - 10.4 and Lazarus 2.0.10
  • source code included in registered version
  • royalty free distribution in applications

Library API

function Catenate(const S1, S2: string; const Separator: string = ', '): string;
function Catenate(List: TStrings; Separator: Char): string;
procedure Split(const Text: string; Delimiter: Char; List: TStrings);
function ToHex(Value: TByteDynArray; const Separator: string = ', '): string;
function CalcCrc16(Data: PByte; Count: Integer): UInt16;
function CalcCrc32(Data: PByte; Count: Integer): UInt32;
function BytesToHex(const Bytes: TBytes; Separator: Char = ':'): string;
function BytesToHex(const Bytes: TBytes; From, Count: Integer; Separator: Char = ':'): string;
function BytesToHexReverse(const Bytes: TBytes; Separator: Char = ':'): string;
function BytesToHexReverse(const Bytes: TBytes; From, Count: Integer; Separator: Char = ':'): string;

{$ifdef ANDROID}

function ApiVersion: Integer;
function ToByteArray(JavaArray: TJavaArray): TArray;
function ToJavaByteArray(ByteArray: TArray): TJavaArray;
function BytesToHex(Bytes: TJavaArray; Separator: Char = ':'): string;
function BytesToHexReverse(Bytes: TJavaArray; Separator: Char = ':'): string;
procedure Play(Tone, Volume: Integer);
procedure Play(Tone, Volume, DurationMs: Integer);
function BitmapToJBitmap(Bitmap: TBitmap): JBitmap;
function JBitmapToBitmap(Bitmap: JBitmap): TBitmap;
function RGBtoBGR(const C: TAlphaColor): TAlphaColor;

// Text To Speech

type
  TTextToSpeechInitEvent = procedure (Sender: TObject; Status: Integer) of object;

  TTextToSpeech = class
    constructor Create(OnInit: TTextToSpeechInitEvent);
    procedure Speak(const Text: string);
    property TextToSpeech: JTextToSpeech read;
  end;

// Speech Recognition

type
  TSpeechRecognitionErrorEvent = procedure (Sender: TObject; Error: Integer) of object;
  TSpeechRecognitionResultsEvent = procedure (Sender: TObject; Results: TArray) of object;

  TSpeechRecognizer = class
    constructor Create;
    procedure StartListening(Intent: JIntent);
    property SpeechRecognizer: JSpeechRecognizer read;
    property OnBeginningOfSpeech: TNotifyEvent read write;
    property OnEndOfSpeech: TNotifyEvent read write;
    property OnError: TSpeechRecognitionErrorEvent read write;
    property OnReadyForSpeech: TNotifyEvent read write;
    property OnResults: TSpeechRecognitionResultsEvent read write;
    class function CreateIntent: JIntent;
    class property IsRecognitionAvailable: Boolean read;
  end;

// Audio

type
  TAudioManager = class
    constructor Create;
    property AudioManager: JAudioManager read;
    property Volume: Integer read write;
  end;

// Ringtone

type
  TRingtoneType = (rtAlarm, rtNotification, rtRingtone);

  TRingtone = class
    constructor Create(RingtoneType: TRingtoneType);
    procedure Play;
    procedure Stop;
    property IsPlaying: Boolean read;
    property Ringtone: JRingtone read;
  end;

// Sensor

type
  TSensorManager = class
    constructor Create;
    property Manager: JSensorManager read;
    property SensorCount: Integer read;
    property Sensors[Index: Integer]: TSensor read;
    property SensorNames: TArray read;
  end;

  TSensorAccuracyChangedEvent = procedure (Sender: TObject; Accuracy: Integer) of object;
  TSensorChangedEvent = procedure (Sender: TObject; Event: TSensorEvent) of object;

  TSensor = class
    function Start(SamplingPeriodUs: Integer): Boolean;
    procedure Stop;

    property AdditionalInfoSupported: Boolean read;
    property FifoMaxEventCount: Integer read;
    property FifoReservedEventCount: Integer read;
    property Id: Integer read;
    property IsDynamicSensor: Boolean read;
    property IsWakeUpSensor: Boolean read;
    property Manager: TSensorManager read;
    property MaxDelay: Integer read;
    property MaximumRange: Single read;
    property MinDelay: Integer read;
    property Name: string read;
    property Power: Single read;
    property ReportingMode: Integer read;
    property Resolution: Single read;
    property Sensor: JSensor read;
    property StringType: string read;
    property Vendor: string read;
    property Version: Integer read;

    property OnAccuracyChanged: TSensorAccuracyChangedEvent read write;
    property OnChanged: TSensorChangedEvent read write;
  end;

  TSensorEvent = class
    property Accuracy: Integer read;
    property Event: JSensorEvent read;
    property TimeStamp: Int64 read;
    property Values: TArray read;
  end;

// Vibrator

type
  TVibrator = class
    constructor Create;
    procedure Vibrate(Milliseconds: Int64);
    procedure Cancel;

    property HasVibrator: Boolean read;
    property Vibrator: JVibrator read;
  end;
{$endif ANDROID}

{$ifdef MSWINDOWS}

const
  NewLine = #$d#$a;

procedure ShowInfo(const Text: string; const Title: string = '');
procedure ShowError(const Text: string; const Title: string = '');
function ShowWarning(const Text: string; const Title: string = ''): Boolean;
function ShowQuestion(const Text: string; const Title: string = ''): Boolean;

// DAO Version

function Dao35Version: string;
function Dao36Version: string;
function AceDaoVersion: string;

// OS Version

function Kernel32Handle: HMODULE;
function ProcessorArchitecture: string;
function WindowsRelease: string;
function WindowsProductName: string;
function WindowsUBR: Integer;
procedure Version(var OperatingSystem, OperatingSystemVersion, Product, ServicePack, ServicePackVersion: string);

// Create GUID

function CreateGuid: TGUID;

// .NET Version

function DotNetVersion(const Version: string; var ServicePack, Release: Integer): string;

// Enum Drives

type
  TLogicalDrives = set of 'A'..'Z';

function LogicalDrives: TLogicalDrives;
function DriveType(Drive: Char): string;
function DriveInfo(Drive: Char; var VolumeName: string;
  var VolumeSerialNumber: Integer; var FileSystemName: string): Boolean;

// Enum Processes

function ProcessIDs: TIntegerDynArray;
function ProcessName(ProcessID: Integer): string;
function ProcessFileName(ProcessID: Integer): string;

// Folder Path

type
  TFolder = (
    foAdminTools,
    foAltStartup,
    foAppData,
    foBitBucket,
    foCdBurnArea,
    foCommonAdminTools,
    foCommonAltStartup,
    foCommonAppData,
    foCommonDesktopDirectory,
    foCommonDocuments,
    foCommonFavorites,
    foCommonMusic,
    foCommonOemLinks,
    foCommonPictures,
    foCommonPrograms,
    foCommonStartMenu,
    foCommonStartup,
    foCommonTemplates,
    foCommonVideo,
    foComputersNearMe,
    foConnections,
    foControls,
    foCookies,
    foDesktop,
    foDesktopDirectory,
    foDrives,
    foFavorites,
    foFonts,
    foHistory,
    foInternet,
    foInternetCache,
    foLocalAppData,
    foMyDocuments,
    foMyMusic,
    foMyPictures,
    foMyVideo,
    foNethood,
    foNetwork,
    foPersonal,
    foPrinters,
    foPrinthood,
    foProfile,
    foProgramFiles,
    foProgramFilesCommon,
    foProgramFilesCommonX86,
    foProgramFilesX86,
    foPrograms,
    foRecent,
    foResources,
    foResourcesLocalized,
    foSendTo,
    foStartMenu,
    foStartup,
    foSystem,
    foSystemX86,
    foTemplates,
    foWindows
  );

function FolderPath(Folder: TFolder): string;

// IP Address

function HostName: string;
function IpAddress(const HostName: string): string;
function IpAddresses(const HostName: string): TStringDynArray;

// MAC Address

type
  TMacAddress = array [0..5] of Byte;
  TMacAddresses = array of TMacAddress;

function MacAddresses: TMacAddresses;

// MDAC Detect

function MdacVersion: string;

// Memory Status

function MemoryStatus(var InUse: Integer; var PhysicalTotal, PhysicalFree,
  VirtualTotal, VirtualFree, PagingTotal, PagingFree: UInt64): Boolean;

// Monitor Off

procedure MonitorOff;

// Restart

procedure Restart;

// System Timing

function SystemTimes(var Idle, Kernel, User: Int64): Boolean;
function SystemTimeToString(Time: Int64): string;

// PATH Edit

const
  PathVariable = 'PATH';

function EnvironmentKey(CurrentUser: Boolean): string;
function GetEnvironmentVariable(const Name: string; CurrentUser: Boolean): string;
procedure SetEnvironmentVariable(const Name, Value: string; CurrentUser: Boolean);
procedure NotifyEnvironmentChange;

// Other

function GetMachineId: string;
{$endif MSWINDOWS}

{$ifdef MACOS}
type
  TSystemInfo = class
    constructor Create;
    property ActiveProcessorCount: Integer read;
    property FullUserName: string read;
    property HostName: string read;
    property OSVersion: string read;
    property OSVersionMajor: Integer read;
    property OSVersionMinor: Integer read;
    property OSVersionPatch: Integer read;
    property PhysicalMemory: Int64 read;
    property ProcessGuid: string read;
    property ProcessInfo: NSProcessInfo read;
    property ProcessName: string read;
    property ProcessorCount: Integer read;
    property SystemUptime: Double read;
    property UserName: string read;
    class property MachineUUID: string read;
    class property SerialNumber: string read;
  end;

function StrToStringRef(const S: string): CFStringRef;
function StringRefToStr(StringRef: CFStringRef): string;
{$endif MACOS}

{$ifdef IOS}
type
  TSystemInfo = class
    constructor Create;
    property ActiveProcessorCount: Integer read;
    property HostName: string read;
    property LowPowerModeEnabled: Boolean read;
    property OSVersion: string read;
    property OSVersionMajor: Integer read;
    property OSVersionMinor: Integer read;
    property OSVersionPatch: Integer read;
    property PhysicalMemory: Int64 read;
    property ProcessGuid: string read;
    property ProcessInfo: NSProcessInfo read;
    property ProcessName: string read;
    property ProcessorCount: Integer read;
    property SystemUptime: Double read;
  end;
{$endif IOS}
								

Download and order