Unit rtool

Uses
Classes, Interfaces, Objects and Records
Types
Variables

Description

rtool contains 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 GetTimeSeparator: Char;
function UpdateToDecimalSeparator(const s: string): string;
function UpdateToDateSeparator(const s: string): string;
function UpdateToTimeSeparator(const s: string): string;
function RemoveThousandSeparator(const s: string): string;
function CleanString(const s, CharsToRemove: string): string;
function CleanLastEOL(const s: string): string;
function CleanNumericString(const s: string): string;
function CleanDateTimeString(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; DatePartOnly: Boolean): TDateTime;
function DateTimeToFormattedStr(ADateTime: TDateTime; Format: string; TimeOnly: Boolean = false): string;
function StrToDateEx(Text: string; var AsDate: TDateTime; Default: TDateTime; MinDate: TDateTime = 0; MaxDate: TDateTime = 0): Boolean;
function GetThemeServices: TCustomStyleServices;
function GetStyleFontColor(AColor: TColor; AStyleFont: TStyleFont): TColor;
function GetStyleBkColor(AColor: TColor; AStyleColor: TStyleColor = scGrid): TColor;
function GetThemeEnabled: Boolean;
function GetStyleSystemColor(AColor: TColor): TColor;
function GetStyleFontColor_LabelText(AColor: TColor): TColor;
function GetStyleFontColor_ButtonText(AColor: TColor; Disabled: Boolean = false): TColor;
function GetStyleFontColor_ComboBox(AColor: TColor): TColor;
function GetStyleFontColor_ListBox(AColor: TColor; Selected: Boolean = false): TColor;
function GetStyleFontColor_GridText(AColor: TColor; Fixed: Boolean = false; Hot: Boolean = false; Pressed: Boolean = false): 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: string; ShortCut: Word; 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); overload;
procedure UseFontFormatParams(AFont: TFont; Param: string; var NormalStyleDefined: Boolean); overload;
procedure UpdateAlignmentFromAlignmentDefault(var Alignment: TAlignment; AlignmentDefault: TAlignmentDefault);
procedure UpdateFontStylesFromFontStylesDefault(var FontStyles: TFontStyles; FontStylesDefault: TFontStylesDefault);
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;

converts WideString with specified codePage to AnsiString

function StringToWideString(const s: AnsiString; codePage: Word): WideString;

converts AnsiString with specified codePage to WideString

function GetDecimalSeparator: Char;

provides decimal separator setting in RAD version independent way

function GetThousandSeparator: Char;

provides thousand separator setting in RAD version independent way

function GetDateSeparator: Char;

provides date separator setting in RAD version independent way

function GetTimeSeparator: Char;

provides time separator setting in RAD version independent way

function UpdateToDecimalSeparator(const s: string): string;

update string representing numeric value with any separators to string with current separators

function UpdateToDateSeparator(const s: string): string;

update string representing date value with any separators to string with current date separator

function UpdateToTimeSeparator(const s: string): string;

update string representing time value with any separators to string with current time separator

function RemoveThousandSeparator(const s: string): string;

remove thousand separator from teh input string

function CleanString(const s, CharsToRemove: string): string;

remove specified characters from the input string

function CleanLastEOL(const s: string): string;

remove end of line (10 or 13) from the input string

function CleanNumericString(const s: string): string;

remove space, white spaces, tabs and end of line from the input string

function CleanDateTimeString(const s: string): string;

remove space, white spaces, tabs and end of line from the input string

function ScanFormattedDateTime(DateTimeStr, Format: string; var ADate: TDateTime): Boolean; overload;

Converts the given string to a date and time value. Input 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). System FormatSettings is used

function ScanFormattedDateTime(DateTimeStr, Format: string; var ADate: TDateTime; const FormatSettings: TFormatSettings): Boolean; overload;

Converts the given string to a date and time value. Input 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). Specific FormatSettings is used

function FormattedStrToDateTimeDef(DateTimeStr, Format: string; Default: TDateTime; DatePartOnly: Boolean): TDateTime;

Converts the given string to a date and time value. Standard StrToDateTimeDef is used if Format is empty, in other case ScanFormattedDateTime is used

function DateTimeToFormattedStr(ADateTime: TDateTime; Format: string; TimeOnly: Boolean = false): string;

Converts Date, Time or DateTime to string according format (if provided) or according to DateTime value

function StrToDateEx(Text: string; var AsDate: TDateTime; Default: TDateTime; MinDate: TDateTime = 0; MaxDate: TDateTime = 0): Boolean;

Converts Text to Date with limits, current month is used if day only is entered

function GetThemeServices: TCustomStyleServices;

return TCustomStyleServices for RAD version XE2+

function GetStyleFontColor(AColor: TColor; AStyleFont: TStyleFont): TColor;

return font color for provided TStyleFont, if style is not active then return provided AColor, for RAD version XE2+

function GetStyleBkColor(AColor: TColor; AStyleColor: TStyleColor = scGrid): TColor;

return background color for provided TStyleColor, if style is not active then return provided AColor, for RAD version XE2+

function GetThemeEnabled: Boolean;

return is Theme/Style is active (RAD version independent)

function GetStyleSystemColor(AColor: TColor): TColor;
 
function GetStyleFontColor_LabelText(AColor: TColor): TColor;

return TLabel font color for active style or AColor if style is not used (RAD version independent)

function GetStyleFontColor_ButtonText(AColor: TColor; Disabled: Boolean = false): TColor;

return TButton font color for active style or AColor if style is not used (RAD version independent)

function GetStyleFontColor_ComboBox(AColor: TColor): TColor;

return TComboBox font color for active style or AColor if style is not used (RAD version independent)

function GetStyleFontColor_ListBox(AColor: TColor; Selected: Boolean = false): TColor;

return TListBox font color for active style or AColor if style is not used (RAD version independent)

function GetStyleFontColor_GridText(AColor: TColor; Fixed: Boolean = false; Hot: Boolean = false; Pressed: Boolean = false): TColor;

return TGrid text font color for active style or AColor if style is not used (RAD version independent)

function GetStyleBkColor_GradientBase(AColor: TColor): TColor;

return Gradient base background color for active style or AColor if style is not used (RAD version independent)

function GetStyleBkColor_ComboBox(AColor: TColor): TColor;

return TComboBox background color for active style or AColor if style is not used (RAD version independent)

function GetStyleBkColor_ListBox(AColor: TColor): TColor;

return TListBox background color for active style or AColor if style is not used (RAD version independent)

function GetStyleBkColor_Grid(AColor: TColor): TColor;

return TGrid background color for active style or AColor if style is not used (RAD version independent)

function GetStyleColor_GridCellBorder(AColor: TColor): TColor;

return TGrid border background color for active style or AColor if style is not used (RAD version independent)

function GetHotTrackCoord(HotTrack: THotTrackCellInfo): TGridCoord;

return TGridCoord from THotTrackCellInfo (RAD version independent)

procedure SetHotTrackCoord(var HotTrack: THotTrackCellInfo; X, Y: integer); overload;

set THotTrackCellInfo from X, Y (RAD version independent)

procedure SetHotTrackCoord(var HotTrack: THotTrackCellInfo; GridCoord: TGridCoord); overload;

set THotTrackCellInfo from TGridCoord (RAD version independent)

function CheckHotTrackCoord(HotTrack: THotTrackCellInfo; X, Y: integer): Boolean; overload;

compare THotTrackCellInfo with X, Y (RAD version independent)

function CheckHotTrackCoord(HotTrack: THotTrackCellInfo; GridCoord: TGridCoord): Boolean; overload;

compare THotTrackCellInfo with TGridCoord (RAD version independent)

procedure DPI_SetFontHeight(AFont: TFont);

set default font height

procedure DPI_ScaleFontHeight(AFont: TFont; M, D: integer); overload;

scale current font height

procedure DPI_ScaleFontHeight(AFont: TFont; ScaleRatio: double); overload;

scale current font height

function DPI_ScaleSize(Size: integer): integer;

scale default size

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;

create a form instance (if not already assigned) and add it to the CreatedFormAdrList

function FreeF(var Ref): Boolean;

free a form instance (if already assigned) and remove it from the CreatedFormAdrList

function CreateShowFM(const FormClass: TFormClass; var Ref): integer;

create a form instance (if not already assigned), update to normal (not minimized) and not hidden and show as modal, then free a form instance if it was created before

procedure CreateShowF(const FormClass: TFormClass; var Ref);

create a form instance (if not already assigned), update to normal (not minimized) show as non-modal

procedure FreeAllF;

free all forms from the CreatedFormAdrList, it means created by CreateF function

function GetActiveOwner: TComponent;

returns active form if exist, in other case returns Application

procedure FocusNextControl(Form: TForm);

send message WM_NEXTDLGCTL to move focus to nest contral

function ShowWinHelp(Form: TForm; Command: Word; Data: integer; var CallHelp: Boolean): Boolean;

calls standard WinHelp procedure

function ShowExtHelp(Form: TForm; Command: Word; Data: integer; var CallHelp: Boolean): Boolean;

open file defined by Form.HelpFile (by associated application)

function CreateMenuItem(Owner: TComponent; Caption: string; Tag: integer; OnClick: TNotifyEvent): TMenuItem; overload;

create and return new menu item object with properties from params

function CreateMenuItem(Owner: TComponent; Caption: string; ShortCut: Word; Tag: integer; OnClick: TNotifyEvent): TMenuItem; overload;

create and return new menu item object with properties from params

function CreateMenuItem(Owner: TComponent; Caption, Hint: string; ShortCut: Word; Tag, ImageIndex: integer; OnClick: TNotifyEvent; Action: TAction): TMenuItem; overload;

create and return new menu item object with properties from params

procedure DefineEditPopupMenuItems(PM: TPopupMenu; OnClick: TNotifyEvent);

define standard popup menu list used for any edit components (undo, cut, copy, paste, select all, find, font, save, load)

procedure RaiseErr(ErrDesc: string);

universal raising error procedure

function ChCursor(const TypCursor: TCursor): TCursor;

set cursor to specified type and return previous cursor

function WCursor: TCursor;

set cursor to crHourGlass and return previous cursor

function NCursor: TCursor;

set cursor to crDefault and return previous cursor

function SQLCursor: TCursor;

set cursor to crSQLWait and return previous cursor

procedure SetProgressBar(PB: TProgressBar; APos, Max: integer);

update progress bar status (value)

function ProcMouseWheel(var WheelDelta: integer; var Key: Word): Boolean;

mouse actions

function NegBool(var b: Boolean): Boolean;

negate bool value and return a new value

function NegMenuItem(Item: TMenuItem): Boolean;

negate check value of the TMenuItem and return a new value

function NegCheckBox(Box: TCheckBox): Boolean;

negate check value of the TCheckBox and return a new value

function RunFileSimple(const FileName: string): THandle;

open document or run file

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

open document or run file

function PrintFileSimple(const FileName: string): THandle;

open and print document

function PrintFile(const FileName, Params, DefaultDir: string; ShowCmd: integer): THandle;

open and print document

function MoveListBox(L: TListBox; old, new: integer): Boolean;

move item in TListBox from old to new index

function MoveCheckListBox(L: TCheckListBox; old, new: integer): Boolean;

move item in TCheckListBox from old to new index

function SortNum(List: TStringList; Index1, Index2: integer): integer;

compare two numeric items from the List, used by TList.CustomSort

function SortDate(List: TStringList; Index1, Index2: integer): integer;

compare two date items from the List, used by TList.CustomSort

function AddItemIfNotExist(List: TStrings; Text: string): Boolean;

add item to List if not exist

procedure GetPrinterNames(List: TStrings);

fill list by printer names

function GetDefaultPrinterName: string;

return default printer name

function SetDefaultPrinter(const PrinterName: String; SendInfoMsg: Boolean): Boolean;

set default printer

procedure SetupPrinterDlg(const PrinterName: String);

show printer dialog

function GetTempDirectory: string; deprecated 'use GetTempDir instead';

Warning: this symbol is deprecated: use GetTempDir instead

Get temporary directory deprecated 'use GetTempDir instead'

function GetTempDir: string;

Get temporary directory

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); overload;

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

procedure UseFontFormatParams(AFont: TFont; Param: string; var NormalStyleDefined: Boolean); overload;
 
procedure UpdateAlignmentFromAlignmentDefault(var Alignment: TAlignment; AlignmentDefault: TAlignmentDefault);

update Alignment setting according to TAlignmentDefault setting

procedure UpdateFontStylesFromFontStylesDefault(var FontStyles: TFontStyles; FontStylesDefault: TFontStylesDefault);

update FontStyle setting according to TFontStylesDefault setting

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

check if ABitIndex is set in AValueToCheck

function SetBit(const AValueToAlter, ABitIndex: integer): integer;

set ABitIndex in AValueToAlter

function ResetBit(const AValueToAlter, ABitIndex: integer): integer;

reset ABitIndex in AValueToAlter

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

Jan 2021


Generated by PasDoc 0.15.0.