Unit rtool

Uses
Classes, Interfaces, Objects and Records
Types
Variables

Description

rtool is set of variety functions (strings, datetimes, forms, cursor, printers, system routines).

Updated version compatible with Delphi2010+.

Overview

Functions and Procedures

function WideStringToString(const ws: WideString; codePage: Word): AnsiString;
function StringToWideString(const s: AnsiString; codePage: Word): WideString;
function GetDecimalSeparator: Char;
function GetThousandSeparator: Char;
function GetDateSeparator: Char;
function UpdateToDecimalSeparator(const s: string): string;
function RemoveThousandSeparator(const s: string): string;
function ScanFormattedDateTime(DateTimeStr, Format: string; var ADate: TDateTime): Boolean; overload;
function ScanFormattedDateTime(DateTimeStr, Format: string; var ADate: TDateTime; const FormatSettings: TFormatSettings): Boolean; overload;
function FormattedStrToDateTimeDef(DateTimeStr, Format: string; Default: TDateTime): TDateTime;
function DateTimeToFormattedStr(ADateTime: TDateTime; Format: string; TimeOnly: boolean = false): string;
function GetThemeServices: TCustomStyleServices;
function GetStyleFontColor(AColor: TColor; AStyleFont: TStyleFont): TColor;
function GetStyleBkColor(AColor: TColor; AStyleColor: TStyleColor = scGrid): TColor;
function GetThemeEnabled: Boolean;
function GetStyleFontColor_LabelText(AColor: TColor): TColor;
function GetStyleFontColor_ButtonText(AColor: TColor): TColor;
function GetStyleFontColor_ButtonTextDisabled(AColor: TColor): TColor;
function GetStyleFontColor_ComboBox(AColor: TColor): TColor;
function GetStyleFontColor_ListBox(AColor: TColor): TColor;
function GetStyleFontColor_ListBoxSelected(AColor: TColor): TColor;
function GetStyleFontColor_GridText(AColor: TColor): TColor;
function GetStyleBkColor_GradientBase(AColor: TColor): TColor;
function GetStyleBkColor_ComboBox(AColor: TColor): TColor;
function GetStyleBkColor_ListBox(AColor: TColor): TColor;
function GetStyleBkColor_Grid(AColor: TColor): TColor;
function GetStyleColor_GridCellBorder(AColor: TColor): TColor;
function GetHotTrackCoord(HotTrack: THotTrackCellInfo): TGridCoord;
procedure SetHotTrackCoord(var HotTrack: THotTrackCellInfo; X, Y: integer); overload;
procedure SetHotTrackCoord(var HotTrack: THotTrackCellInfo; GridCoord: TGridCoord); overload;
function CheckHotTrackCoord(HotTrack: THotTrackCellInfo; X, Y: integer): Boolean; overload;
function CheckHotTrackCoord(HotTrack: THotTrackCellInfo; GridCoord: TGridCoord): Boolean; overload;
procedure DPI_SetFontHeight(AFont: TFont);
procedure DPI_ScaleFontHeight(AFont: TFont; M, D: integer); overload;
procedure DPI_ScaleFontHeight(AFont: TFont; ScaleRatio: double); overload;
function DPI_ScaleSize(Size: integer): integer;
function FillStrL(const s: string; By: Char; Len: integer): string;
function FillStrR(const s: string; By: Char; Len: integer): string;
function AnsiPosEx(const Substr, s: string; From: integer = 1; CaseSensitive: Boolean = false): integer;
function FindStrPart(const s, Separator: string; Sequence: byte; CaseSensitive: Boolean = false): string;
function RemoveStrPart(var s: string; const Separator: string; CaseSensitive: Boolean = false): string;
function FindStrFromTo(const SubstrStart, SubstrStop, s: string; CaseSensitive: Boolean = false; ExtractSubstrStart: Boolean = false): string;
function ClearStr(const Substr, s: string; CaseSensitive: Boolean = false): string;
function ReplaceStr(const OldSubstr, NewSubstr, s: string; All: Boolean = true; CaseSensitive: Boolean = false): string;
function ReplaceStrFromTo(const OldSubstrStart, OldSubstrStop, NewSubstr, s: string; ReplaceSubstrStop: Boolean = true; All: Boolean = true; CaseSensitive: Boolean = false): string;
procedure AddToSepList(var List: string; const StrToAdd: string; const Sep: string = ', ');
function ContainWholeWord(const Substr, s: string; Separators: TSysCharSet; StartPos: integer = 0): Boolean;
function ExistsInSepList(const Substr, s: string; Separator: string; TrimSpaces: Boolean = true): Boolean;
function VarToString(PointToVar: Pointer; LengthVar: integer): string;
function StringToVar(PointToVar: Pointer; LengthVar: integer; s: string): Boolean;
function GetLine(const StrList: string; Index: integer): string;
function SetLine(const StrList, Line: string; Index: integer): string;
function IntToStr0(Int: integer; Len: integer): string;
function CreateF(const FormClass: TFormClass; var Ref; AddToFormList: Boolean = true): Boolean;
function FreeF(var Ref): Boolean;
function CreateShowFM(const FormClass: TFormClass; var Ref): integer;
procedure CreateShowF(const FormClass: TFormClass; var Ref);
procedure FreeAllF;
function GetActiveOwner: TComponent;
procedure FocusNextControl(Form: TForm);
function ShowWinHelp(Form: TForm; Command: Word; Data: integer; var CallHelp: Boolean): Boolean;
function ShowExtHelp(Form: TForm; Command: Word; Data: integer; var CallHelp: Boolean): Boolean;
function CreateMenuItem(Owner: TComponent; Caption: string; Tag: integer; OnClick: TNotifyEvent): TMenuItem; overload;
function CreateMenuItem(Owner: TComponent; Caption, Hint: string; ShortCut: Word; Tag, ImageIndex: integer; OnClick: TNotifyEvent; Action: TAction): TMenuItem; overload;
procedure DefineEditPopupMenuItems(PM: TPopupMenu; OnClick: TNotifyEvent);
procedure RaiseErr(ErrDesc: string);
function ChCursor(const TypCursor: TCursor): TCursor;
function WCursor: TCursor;
function NCursor: TCursor;
function SQLCursor: TCursor;
procedure SetProgressBar(PB: TProgressBar; APos, Max: integer);
function ProcMouseWheel(var WheelDelta: integer; var Key: Word): Boolean;
function NegBool(var b: Boolean): Boolean;
function NegMenuItem(Item: TMenuItem): Boolean;
function NegCheckBox(Box: TCheckBox): Boolean;
function RunFileSimple(const FileName: string): THandle;
function RunFile(const FileName, Params, DefaultDir: string; ShowCmd: integer; ShowErr: Boolean = true): THandle;
function PrintFileSimple(const FileName: string): THandle;
function PrintFile(const FileName, Params, DefaultDir: string; ShowCmd: integer): THandle;
function MoveListBox(L: TListBox; old, new: integer): Boolean;
function MoveCheckListBox(L: TCheckListBox; old, new: integer): Boolean;
function SortNum(List: TStringList; Index1, Index2: integer): integer;
function SortDate(List: TStringList; Index1, Index2: integer): integer;
function AddItemIfNotExist(List: TStrings; Text: string): Boolean;
procedure GetPrinterNames(List: TStrings);
function GetDefaultPrinterName: string;
function SetDefaultPrinter(const PrinterName: String; SendInfoMsg: Boolean): Boolean;
procedure SetupPrinterDlg(const PrinterName: String);
function GetTempDirectory: string; deprecated 'use GetTempDir instead';
function GetTempDir: string;
function GetSystemDir(FolderType: integer): string;
function GetAppPath: string; deprecated 'use GetAppDir instead';
function GetAppDir: string;
function SetEndOfPath(const Path: string): string;
procedure UseFontFormatParams(AFont: TFont; Param: string);
function IsBitSet(const AValueToCheck, ABitIndex: integer): Boolean;
function SetBit(const AValueToAlter, ABitIndex: integer): integer;
function ResetBit(const AValueToAlter, ABitIndex: integer): integer;

Constants

rcEditSep = 0;
rcEditUndo = 1;
rcEditCut = 2;
rcEditCopy = 3;
rcEditPaste = 4;
rcEditDelete = 5;
rcEditSelectAll = 10;
rcEditFind = 11;
rcEditFindNext = 12;
rcEditSelectFont = 13;
rcMemoWordWrap = 20;
rcMemoLoadFile = 21;
rcMemoSaveFile = 22;

Description

Functions and Procedures

function WideStringToString(const ws: WideString; codePage: Word): AnsiString;
 
function StringToWideString(const s: AnsiString; codePage: Word): WideString;
 
function GetDecimalSeparator: Char;
 
function GetThousandSeparator: Char;
 
function GetDateSeparator: Char;
 
function UpdateToDecimalSeparator(const s: string): string;
 
function RemoveThousandSeparator(const s: string): string;
 
function ScanFormattedDateTime(DateTimeStr, Format: string; var ADate: TDateTime): Boolean; overload;

ScanFormattedDateTime converts the given string to a date and time value. The string can contain a date, date followed by a time or time only. The date and time parts is decoded according to given Format string (same specifiers as for StrToDateTime is used so can be used as reverse function of StrToDateTime)

function ScanFormattedDateTime(DateTimeStr, Format: string; var ADate: TDateTime; const FormatSettings: TFormatSettings): Boolean; overload;
 
function FormattedStrToDateTimeDef(DateTimeStr, Format: string; Default: TDateTime): TDateTime;
 
function DateTimeToFormattedStr(ADateTime: TDateTime; Format: string; TimeOnly: boolean = false): string;
 
function GetThemeServices: TCustomStyleServices;

Support for Themes and Style - get StyleService and used Font and Background colors for specific components

function GetStyleFontColor(AColor: TColor; AStyleFont: TStyleFont): TColor;
 
function GetStyleBkColor(AColor: TColor; AStyleColor: TStyleColor = scGrid): TColor;
 
function GetThemeEnabled: Boolean;
 
function GetStyleFontColor_LabelText(AColor: TColor): TColor;
 
function GetStyleFontColor_ButtonText(AColor: TColor): TColor;
 
function GetStyleFontColor_ButtonTextDisabled(AColor: TColor): TColor;
 
function GetStyleFontColor_ComboBox(AColor: TColor): TColor;
 
function GetStyleFontColor_ListBox(AColor: TColor): TColor;
 
function GetStyleFontColor_ListBoxSelected(AColor: TColor): TColor;
 
function GetStyleFontColor_GridText(AColor: TColor): TColor;
 
function GetStyleBkColor_GradientBase(AColor: TColor): TColor;
 
function GetStyleBkColor_ComboBox(AColor: TColor): TColor;
 
function GetStyleBkColor_ListBox(AColor: TColor): TColor;
 
function GetStyleBkColor_Grid(AColor: TColor): TColor;
 
function GetStyleColor_GridCellBorder(AColor: TColor): TColor;
 
function GetHotTrackCoord(HotTrack: THotTrackCellInfo): TGridCoord;
 
procedure SetHotTrackCoord(var HotTrack: THotTrackCellInfo; X, Y: integer); overload;
 
procedure SetHotTrackCoord(var HotTrack: THotTrackCellInfo; GridCoord: TGridCoord); overload;
 
function CheckHotTrackCoord(HotTrack: THotTrackCellInfo; X, Y: integer): Boolean; overload;
 
function CheckHotTrackCoord(HotTrack: THotTrackCellInfo; GridCoord: TGridCoord): Boolean; overload;
 
procedure DPI_SetFontHeight(AFont: TFont);

DPi + scale

procedure DPI_ScaleFontHeight(AFont: TFont; M, D: integer); overload;
 
procedure DPI_ScaleFontHeight(AFont: TFont; ScaleRatio: double); overload;
 
function DPI_ScaleSize(Size: integer): integer;
 
function FillStrL(const s: string; By: Char; Len: integer): string;

fill str from left

function FillStrR(const s: string; By: Char; Len: integer): string;

fill str from right

function AnsiPosEx(const Substr, s: string; From: integer = 1; CaseSensitive: Boolean = false): integer;

find substring from start position

function FindStrPart(const s, Separator: string; Sequence: byte; CaseSensitive: Boolean = false): string;

find index-th part of input string separated by separator

function RemoveStrPart(var s: string; const Separator: string; CaseSensitive: Boolean = false): string;

find first part of input string separated by separator, return it and remove from input

function FindStrFromTo(const SubstrStart, SubstrStop, s: string; CaseSensitive: Boolean = false; ExtractSubstrStart: Boolean = false): string;

find part of input string identificated by StartStr and StopStr

function ClearStr(const Substr, s: string; CaseSensitive: Boolean = false): string;

clear all substr from str

function ReplaceStr(const OldSubstr, NewSubstr, s: string; All: Boolean = true; CaseSensitive: Boolean = false): string;

replace oldSubStr by newSubStr in s

function ReplaceStrFromTo(const OldSubstrStart, OldSubstrStop, NewSubstr, s: string; ReplaceSubstrStop: Boolean = true; All: Boolean = true; CaseSensitive: Boolean = false): string;

replace oldSubStr identificated by StartStr and StopStr by newSubStr in s

procedure AddToSepList(var List: string; const StrToAdd: string; const Sep: string = ', ');

add string to separated list

function ContainWholeWord(const Substr, s: string; Separators: TSysCharSet; StartPos: integer = 0): Boolean;

check if string is wholeword = separated from other string by any chars from separators

function ExistsInSepList(const Substr, s: string; Separator: string; TrimSpaces: Boolean = true): Boolean;

check if string is wholeword = items are separated from by separator

function VarToString(PointToVar: Pointer; LengthVar: integer): string;

conversion variable to string (for saving in BLOB)

function StringToVar(PointToVar: Pointer; LengthVar: integer; s: string): Boolean;

conversion string to variable

function GetLine(const StrList: string; Index: integer): string;

get one line from string separated by EOL

function SetLine(const StrList, Line: string; Index: integer): string;

set one line in string separated by EOL

function IntToStr0(Int: integer; Len: integer): string;

conversion int to str with 0 on left side

function CreateF(const FormClass: TFormClass; var Ref; AddToFormList: Boolean = true): Boolean;

form actions

function FreeF(var Ref): Boolean;
 
function CreateShowFM(const FormClass: TFormClass; var Ref): integer;
 
procedure CreateShowF(const FormClass: TFormClass; var Ref);
 
procedure FreeAllF;
 
function GetActiveOwner: TComponent;
 
procedure FocusNextControl(Form: TForm);
 
function ShowWinHelp(Form: TForm; Command: Word; Data: integer; var CallHelp: Boolean): Boolean;
 
function ShowExtHelp(Form: TForm; Command: Word; Data: integer; var CallHelp: Boolean): Boolean;
 
function CreateMenuItem(Owner: TComponent; Caption: string; Tag: integer; OnClick: TNotifyEvent): TMenuItem; overload;

create and return new menu item with properties from params

function CreateMenuItem(Owner: TComponent; Caption, Hint: string; ShortCut: Word; Tag, ImageIndex: integer; OnClick: TNotifyEvent; Action: TAction): TMenuItem; overload;
 
procedure DefineEditPopupMenuItems(PM: TPopupMenu; OnClick: TNotifyEvent);
 
procedure RaiseErr(ErrDesc: string);

universal raising error procedure

function ChCursor(const TypCursor: TCursor): TCursor;

cursor actions

function WCursor: TCursor;
 
function NCursor: TCursor;
 
function SQLCursor: TCursor;
 
procedure SetProgressBar(PB: TProgressBar; APos, Max: integer);
 
function ProcMouseWheel(var WheelDelta: integer; var Key: Word): Boolean;

mouse actions

function NegBool(var b: Boolean): Boolean;

negate actions

function NegMenuItem(Item: TMenuItem): Boolean;
 
function NegCheckBox(Box: TCheckBox): Boolean;
 
function RunFileSimple(const FileName: string): THandle;

open document or run file

function RunFile(const FileName, Params, DefaultDir: string; ShowCmd: integer; ShowErr: Boolean = true): THandle;
 
function PrintFileSimple(const FileName: string): THandle;

open and print document

function PrintFile(const FileName, Params, DefaultDir: string; ShowCmd: integer): THandle;
 
function MoveListBox(L: TListBox; old, new: integer): Boolean;

listbox actions

function MoveCheckListBox(L: TCheckListBox; old, new: integer): Boolean;
 
function SortNum(List: TStringList; Index1, Index2: integer): integer;
 
function SortDate(List: TStringList; Index1, Index2: integer): integer;
 
function AddItemIfNotExist(List: TStrings; Text: string): Boolean;
 
procedure GetPrinterNames(List: TStrings);

printer functions

function GetDefaultPrinterName: string;
 
function SetDefaultPrinter(const PrinterName: String; SendInfoMsg: Boolean): Boolean;
 
procedure SetupPrinterDlg(const PrinterName: String);
 
function GetTempDirectory: string; deprecated 'use GetTempDir instead';

Warning: this symbol is deprecated: use GetTempDir instead

Get temporary directory

function GetTempDir: string;
 
function GetSystemDir(FolderType: integer): string;

returns special directory in system according parameter FolderType, see ShlObj for list of values

function GetAppPath: string; deprecated 'use GetAppDir instead';

Warning: this symbol is deprecated: use GetAppDir instead

return path of exe program

function GetAppDir: string;

return path of exe program

function SetEndOfPath(const Path: string): string;

set end of the Path with backslash

procedure UseFontFormatParams(AFont: TFont; Param: string);

set font style, color and size according Param string: N=normal B=bold I=italic U=underline Red, Blue = color $00xxxxxx = color 8, 9, 10, 12, 14 ... = size

function IsBitSet(const AValueToCheck, ABitIndex: integer): Boolean;
 
function SetBit(const AValueToAlter, ABitIndex: integer): integer;
 
function ResetBit(const AValueToAlter, ABitIndex: integer): integer;
 

Constants

rcEditSep = 0;
 
rcEditUndo = 1;
 
rcEditCut = 2;
 
rcEditCopy = 3;
 
rcEditPaste = 4;
 
rcEditDelete = 5;
 
rcEditSelectAll = 10;
 
rcEditFind = 11;
 
rcEditFindNext = 12;
 
rcEditSelectFont = 13;
 
rcMemoWordWrap = 20;
 
rcMemoLoadFile = 21;
 
rcMemoSaveFile = 22;
 

Author

Created

Nov 2005

Last Modified

Apr 2020


Generated by PasDoc 0.15.0.