Rx VCL Utilities

RX Library

UNIT VCLUtils

Constant
WaitCursor

Type
TFillDirection
TVertAlignment

Routines
ActivatePrevInstance
ActivateWindow
AllocMemo
AnsiUpperFirstChar
AssignBitmapCell
CenterControl
CenterWindow
ChangeBitmapColor
CompareMem
CopyParentImage
CreateBitmapFromIcon
CreateTwoColorsBrushPattern
DefineCursor
Delay
DialogUnitsToPixelsX
DialogUnitsToPixelsY
DrawBitmapRectTransparent
DrawBitmapTransparent
DrawCellBitmap
DrawCellText
DrawInvertFrame
FreeMemo
FreeUnusedOLE
GetEnvVar
GetMemoSize
GradientFillRect
HeightOf
HugeDec
HugeInc
HugeMove
HugeOffset
KillMessage
LoadAniCursor
LoadDLL
MakeBitMap
MakeBitMapId
MakeIcon
MakeIconId
MakeModuleBitMap
MakeModuleIcon
MergeForm
MinimizeText
MsgBox
NotImplemented
PaintInverseRect
PixelsToDialogUnitsX
PixelsToDialogUnitsY
PointInPolyRgn
PointInRect
RegisterServer
ResourceNotFound
ShadeRect
SplitCommandLine
StartWait
StopWait
WidthOf
LoadAniCursor
LoadDLL
MakeBitmap
MakeBitmapID
MakeIcon
MakeIconID
MakeModuleBitmap
MakeModuleIcon
MergeForm
MinimizeText
MsgBox
NotImplemented
PaintInverseRect
PixelsToDialogUnitsX
PixelsToDialogUnitsY
PointInPolyRgn
PointInRect
RegisterServer
ResourceNotFound
ShadeRect
SplitCommandLine
StartWait
StopWait
WidthOf
Win32Check


Const WaitCursor
Declaration: WaitCursor: TCursor = crHourGlass;

This defines the default wait cursor as the hour glass.


Type TFillDirection
Declaration: TFillDirection = (fdTopToBottom, fdBottomToTop, fdLeftToRight, fdRightToLeft);

TFillDirection defines the possible values of the Direction parameter for GradientFillRect procedure.


Type TVertAlignment
Declaration: TVertAlignment = (vaTopJustify, vaCenter, vaBottomJustify);

TVertAlignment is a set of values for the VertAlign parameter of the DrawCellText procedure.


Routine ActivatePrevInstance
Declaration: function ActivatePrevInstance(const MainFormClass, ATitle: string): Boolean;

ActivatePrevInstance function allows you to stop your application from being running more than one instance under Windows. It causes the application to detect another instance at startup and when found, terminates the second instance and tries to activate the original instance of your application. ActivatePrevInstance find the top-level window whose class name and window name match the specified strings and, when found, activate this window and returns True. Typically, you can use name of class of main application form as MainFormClass parameter. ATitle parameter specifies the window name (the window's title). If this parameter is empty string, all window names match. Also you can use 'TApplication' as MainFormClass parameter and Application.Title as ATitle parameter. It's recomended however to use the main form class name so it can be more unique for Windows.
You can call this function in project source (in .DPR-file) of your application.

ActivatePrevInstance example:
You can call ActivatePrevInstance in project source file (DPR) to stop your application from being running more than one instance under Windows:

begin
__if ActivatePrevInstance(TRxMainProjectForm.ClassName, '') then
____Exit;
__Application.CreateForm(TRxMainProjectForm, RxMainProjectForm);
__{ create other forms }
__Application.Run;
end;


Routine ActivateWindow
Declaration: procedure ActivateWindow(Wnd: HWnd);

The ActivateWindow function activates a window and forces the thread that created the window into the foreground. An application should call ActivateWindow if it wants to put itself into the foreground.

If window specified by Wnd handle is hidden, then ActivateWindow displays the window. If the window is minimized ActivateWindow restores it to its original size and position.

ActivateWindow example:
ActivateWindow(Wnd);


Routine AllocMemo
Declaration: function AllocMemo(Size: Longint): Pointer;

AllocMemo allocates a block of the given Size on the heap. Each byte in the allocated buffer is set to zero. To dispose the buffer, use the FreeMemo procedure.

AllocMemo example:
var
__P: Pointer;
begin
__P := AllocMemo(128000);
__try
____{ use memory }
__finally
____FreeMemo(P);
__end;
end;


Routine AnsiUpperFirstChar
Declaration: function AnsiUpperFirstChar(const S: string): string;

This returns the string, processed with the first letter in uppercase, all other letters in lowercase, using ANSI character set.

AnsiUpperFirstChar example:
ClientName := AnsiUpperFirstChar(ClientName);


Routine AssignBitmapCell
Declaration: procedure AssignBitmapCell(Source: TGraphic; Dest: TBitmap; Cols, Rows, Index: Integer);

AssignBitmapCell example:

Next code fragment loads standard Windows "box" images, cut cell from it and assign selected bitmap to Glyph property of TSpeedButton component:

var
__Bmp, Checks: TBitmap;
begin
__Bmp := TBitmap.Create;
__Checks := MakeModuleBitmap(0, PChar(32759));
__try
____{...}
____AssignBitmapCell(Checks, Bmp, 4, 3, 1);
____SpeedButton1.Glyph := Bmp;
____{...}
__finally
____Bmp.Free;
____Checks.Free;
__end;
end;


Routine CenterControl
Declaration: procedure CenterControl(Control: TControl);

This procedure centers the given window control over its parent. If the control is a form, it is centered over the screen. If the control is a MDI-child form, it is centered over the main application MDI-form. It ensures that the window is entirely within the visible screen.

CenterControl example:
procedure TForm1.FormResize(Sender: TObject);
begin
__CenterControl(Memo1);
end;


Routine CenterWindow
Declaration: procedure CenterWindow(Wnd: HWnd);

This function centers the given window Wnd over the screen. It ensures that the window is entirely within the visible screen.

CenterWindow example:
CenterWindow(Form1.Hanle);


Routine ChangeBitmapColor
Declaration: function ChangeBitmapColor(Bitmap: TBitmap; Color, NewColor: TColor): TBitmap;

The function ChangeBitmapColour changes the colour inside the bitmap to the corresponding NewColor.

ChangeBitmapColor example:
var
__Bmp1, Bmp2: TBitmap;
begin
__{...}
__Bmp2 := ChangeBitmapColor(Bmp1, clOlive, clSilver);
__try
____Bmp1.Assign(Bmp2);
__finally
____Bmp2.Free;
__end;
end;


Routine CompareMem
Declaration: function CompareMem(fpBlock1, fpBlock2: Pointer; Size: Integer): Boolean; assembler;

CompareMem performs a binary compare of Size bytes of memory referenced by fpBlock1 to that of fpBlock2. CompareMem returns True if the memory referenced by fpBlock1 is identical to that of fpBlock2.

CompareMem example:

if CompareMem(fp1, fp2, 1024) then
begin
__{ ... }
end;


Routine CopyParentImage
Declaration: procedure CopyParentImage(Control: TControl; Dest: TCanvas);

CopyParentImage copies the image contained within the control to a tCanvas.

> CopyParentImage example:

procedure TMyControl.Paint;
begin
__Canvas.FillRect(Bounds(0, 0, Width, Height));
__{ copy image from parent and back-level controls }
__CopyParentImage(Self, Canvas);
__DrawBitmapTransparent(Canvas, 0, 0, FImage, FImage.TransparentColor);
end;


Routine CreateBitmapFromIcon
Declaration: function CreateBitmapFromIcon(Icon: TIcon; BackColor: TColor): TBitmap;

CreateBitMapFromIcon, as it's name implies, creates a bitmap from an icon. The BackColour is important because there is no bitmap equivalent of the colour "transparent".

> CreateBitmapFromIcon example:
var
__Bmp: TBitmap;
begin
__Bmp := CreateBitmapFromIcon(Form1.Icon, clSilver);
__try
____{ use bitmap }
__finally
____Bmp.Free;
__end;
end;


Routine CreateTwoColorsBrushPattern
Declaration: function CreateTwoColorsBrushPattern(Color1, Color2: TColor): TBitmap;

CreateTwoColoursBrushPattern, as it's name implies, creates a b

> CreateTwoColorsBrushPattern example:

var
__Bmp: TBitmap;
begin
__Bmp := CreateTwoColorsBrushPattern(clBtnFace, clWhite);
__try
____Canvas.Brush.Bitmap := Bmp;
____{ ... }
__finally
____Bmp.Free;
__end;
end;


Routine DefineCursor
Declaration: function DefineCursor(Instance: THandle; ResID: PChar): TCursor;

DefineCursor function loads the specified cursor resource from the executable (.EXE or .DLL) file associated with an specified instance and assign a unique index. Returns the new index. ResID parameter points to a null-terminated string that contains the name of the cursor resource to be loaded. Alternatively, this parameter can consist of the resource identifier in the low-order word and zero in the high-order word. The MakeIntResource function can also be used to create this value. If the specified resource can not be found, DefineCursor raises an EResNotFound exception. To use DefineCursor, just call it and assign the return value to a component's Cursor property.

In 32-bit version DefineCursor searches for the specified cursor resource in this sequence:

1. Resources of RT_CURSOR (standard Windows cursors) type.

2. Resources of RT_ANICURSOR (animated cursors) type.

> DefineCursor example:

constructor TDrawingComponent.Create(Owner: TComponent);
begin
inherited Create(Owner);
Cursor := DefineCursor(HInstance, 'CUR_MYCURSOR');
end;


Routine Delay
Declaration: procedure Delay(MSecs: Longint);

Delays a specified number (MSecs) of milliseconds.

> Delay example:

StartWait;
try
__Delay(1000);
finally
__StopWait;
end;


Routine DialogUnitsToPixelsX
Declaration: function DialogUnitsToPixelsX(DlgUnits: Word): Word;

Convert dialog units to pixels in horizontal direction.
The dialog box base units used by Windows to create dialog boxes.

> DialogUnitsToPixelsX example:
X := DialogUnitsToPixelsX(X);


Routine DialogUnitsToPixelsY
Declaration: function DialogUnitsToPixelsY(DlgUnits: Word): Word;

Convert dialog units to pixels in vertical direction. The dialog box base units used by Windows to create dialog boxes.

> DialogUnitsToPixelsY example:

Y := DialogUnitsToPixelsY(Y);


Routine DrawBitmapRectTransparent
Declaration: procedure DrawBitmapRectTransparent(Dest: TCanvas; DstX, DstY: Integer; SrcRect: TRect; Bitmap: TBitmap; TransparentColor: TColor);

DrawBitmapRectTransparent paints the rectangular part (specified by SrcRect parameter) of bitmap specified by the Bitmap parameter on the canvas Dest at the location given by the coordinates (DstX, DstY). TransparentColor determines which color of the bitmap is to be transparent when the bitmap is drawn.

To draw whole bitmap image transparency use DrawBitmapTransparent procedure.

> DrawBitmapRectTransparent example:

var
__Bmp: TBitmap;
begin
__Bmp := Image1.Picture.Bitmap;
__DrawBitmapRectTransparent(PaintBox1.Canvas, 10, 10,
__Rect(0, 0, Bmp.Width div 2, Bmp.Height div 2), Bmp, clOlive);
end;


Routine DrawBitmapTransparent
Declaration: procedure DrawBitmapTransparent(Dest: TCanvas; DstX, DstY: Integer; Bitmap: TBitmap; TransparentColor: TColor);

DrawBitmapTransparent paints the bitmap specified by the Bitmap parameter on the canvas Dest at the location given by the coordinates (DstX, DstY). TransparentColor determines which color of the bitmap is to be transparent when the bitmap is drawn. To render only part of bitmap use DrawBitmapRectTransparent procedure.

> DrawBitmapTransparent example:

var
__Bmp: TBitmap;
begin
__Bmp := Image1.Picture.Bitmap;
__DrawBitmapTransparent(PaintBox1.Canvas, 10, 10, Bmp, clOlive);
end;


Routine DrawCellBitmap
Declaration: procedure DrawCellBitmap(Control: TCustomControl; ACol, ARow: Longint; Bmp: TBitmap; Rect: TRect);

DrawBitmap draws a bitmap Bmp onto Control (assumed as DrawGrid) with ACol and ARow as it's specifier. The bitmap occupies the space Rect.

> DrawCellBitmap example:

procedure TForm1.Grid1DrawCell(Sender: TObject; Col, Row: Longint; Rect: TRect; State: TGridDrawState);
var
Bmp: TBitmap;
begin
Bmp := GetCellBitmap(Col, Row);
if Bmp <> nil then
DrawCellBitmap(Grid1, Col, Row, Bmp, Rect);
end;


Routine DrawCellText
Declaration: procedure DrawCellText(Control: TCustomControl; ACol, ARow: Longint; const S: string; const ARect: TRect; Align: TAlignment; VertAlign: TVertAlignment);

DrawCellText draws the text (const s : string) inside the TDrawGrid, with parameter ACol (Column) and ARow (row) inside ARect with specified Horizontal Alignment Align and Vertical Alignment VertAlign.

DrawCellText example:

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; Col, Row: Longint; Rect: TRect; State: TGridDrawState);
begin
__if (Row >= 0) then
__begin
____DrawCellText(Sender as TDrawGrid, Col, Row,
____GetCellText(Row), Rect, taLeftJustify, vaCenter);
__end;
end;


Routine DrawInvertFrame
Declaration: procedure DrawInvertFrame(ScreenRect: TRect; Width: Integer);

DrawInvertFrame draws a rectangular frame in the screen by performing a logical XOR operation on the color values for each pixel of the rectangle's frame. Because DrawInvertFrame uses an XOR function, calling it a second time while specifying the same rectangle removes the inverted rectangle from the screen. ScreenRect parameter contains the logical coordinates of the rectangle in the screen coordinates (relative to the upper-left corner of the screen). Width parameter specifies the width of the frame in pixels.

> DrawInvertFrame example:

var
__P: TPoint;
__R: TRect;
begin
__P := Panel1.ClientToScreen(Point(0, 0));
__R := Bounds(P.X, P.Y, Panel1.Width, Panel1.Height);
__DrawInvertFrame(R, 3); { Show invert frame }
__{ ... }
__DrawInvertFrame(R, 3); { Hide invert frame }
end;


Routine FreeMemo
Declaration: procedure FreeMemo(var fpBlock: Pointer);

The FreeMemo procedure disposes of a dynamic variable. fpBlock is a variable of any pointer type
previously assigned by the AllocMemo function.

> FreeMemo example:

var
__P: Pointer;
begin
__P := AllocMemo(128000);
__try
____{ use memory }
__finally
____FreeMemo(P);
__end;
end;


Routine FreeUnusedOLE
Declaration: procedure FreeUnusedOLE;

This procedure unloads OLE DLL's in 32-bit Delphi versions. You can unload unused OLE DLL's when you don't use OLE libraries in your application. Be sure that your project does not calling any OLE functions and does not using Variant types before calling this procedure!

> FreeUnusedOLE example:

program Project1;
uses Forms, VCLUtils, Main in 'MAIN.PAS' {MainForm};

{$R *.RES}

begin
__FreeUnusedOLE;
__Application.CreateForm(TMainForm, MainForm);
__Application.Run;
end;


Routine GetEnvVar
Declaration: function GetEnvVar(const VarName: string): string;

Returns a string value of a specified environment variable.

> GetEnvVar example:

uses SysUtils, Dialogs, VCLUtils;
var EnvVar: string;

begin
__EnvVar := GetEnvVar('TEMP');
__ShowMessage(Format('Path of the temporary file is currently: %s', [EnvVar]));
end.


Routine GetMemoSize
Declaration: function GetMemoSize(fpBlock: Pointer): Longint;

The GetMemoSize function retrieves the current size, in bytes, of the specified dynamic variable. fpBlock is a variable of any pointer type previously assigned by the AllocMemo function.

> GetMemoSize example:

var P: Pointer; S: Longint;

begin
__P := AllocMemo(128000);
__try
____{ use memory }
____S := GetMemoSize(P);
____{ ... }
__finally
____FreeMemo(P);
end;
end;


Routine GradientFillRect
Declaration: procedure GradientFillRect(Canvas: TCanvas; Rect: TRect; BeginColor, EndColor: TColor; Direction: TFillDirection; Colors: Byte);

GradientFillRect procedure displays a rectangle Rect on a Canvas with a color pattern that blends from one choosen color BeginColor to another color EndColor. Colors parameter determines the number of color bands that are painted between the starting and ending colors. The valid range for Colors is 1 to 255. Direction parameter determines whether the gradient is horizontal or vertical.

GradientFillRect example:

procedure TForm1.FormPaint(Sender: TObject);
begin
__GradientFillRect(Canvas, ClientRect, clBlue, clBlack, fdTopToBottom, 255);
end;
{...}

procedure TForm1.FormResize(Sender: TObject);
begin
__Invalidate;
end;


Routine HeightOf
Declaration: function HeightOf(R: TRect): Integer;

Retrieves the vertical size (height) of the specified rectangle R in pixels.

HeightOf example:
H := HeightOf(Rect);


Routine HugeDec
Declaration: procedure HugeDec(var HugePtr: Pointer; Amount: Longint);

Decrement a huge pointer.

HugeDec example:
var P: Pointer; L: Longint;
{...}
HugeDec(P, L);
{...}


Routine HugeInc
Declaration: procedure HugeInc(var HugePtr: Pointer; Amount: Longint);

Increment a huge pointer.

HugeInc example:
var
__P: Pointer;
__L: Longint;
__{...}
__HugeInc(P, L);
__{...}


Routine HugeMove
Declaration: procedure HugeMove(Base: Pointer; Dst, Src, Size: Longint);

Copy memory from Src to Dst, copying Size units from Base+Src to Base+Dst. The reason to separate the Base pointer from the Dst and Src indexes is to easily compare the indexes to see what direction to copy, without having to muck about with normalizing segments. Offsets and the size are in longwords, for convenience, but you need to convert them to short words, in case the code is running on a 286 machine, which does not support the movsd instruction, just movsw.

HugeMove example:
var
__P: Pointer;
__L: Longint;

begin
__{...}
__L := 1024 * 82; {82 K}
__HugeMove(P, 0, L, L);
__{...}
end;


Routine HugeOffset
Declaration: function HugeOffset(HugePtr: Pointer; Amount: Longint): Pointer;

Add an offset to a huge pointer and return the result.

> HugeOffset example:
P := HugeOffset(P, L);


Routine KillMessage
Declaration: procedure KillMessage(Wnd: HWnd; Msg: Cardinal);

KillMessage deletes the requested message Msg from the window message queue, but throw back any WM_QUIT messages that PeekMessage standard Windows function may also return.

> KillMessage example:
KillMessage(Form1.Handle, Msg.Message);


Routine LoadAniCursor
Declaration: function LoadAniCursor(Instance: THandle; ResID: PChar): HCursor;

The LoadAniCursor function loads the specified animated cursor resource from the executable (.EXE or .DLL) file associated with the specified application instance. Instance parameter identifies an instance of the module whose executable file contains the animated cursor to be loaded. ResID parameter points to a null-terminated string that contains the name of the animated cursor resource (RT_ANICURSOR type) to be loaded. Alternatively, this parameter can consist of the resource identifier in the low-order word and zero in the high-order word. The MakeIntResource function can also be used to create this value. If the function succeeds, the return value is the handle of the newly loaded animated cursor. If the function fails, the return value is 0 (zero).

> LoadAniCursor example:
var Cur: HCursor;
begin
__{...}
__Cur := LoadAniCursor(hInstance, 'CUR_COIN');
__if Cur = 0 then
____{ error loading cursor }
__else
____Screen.Cursors[200] := Cur;
__{...}
end;


Routine LoadDLL
Declaration: function LoadDLL(const LibName: string): THandle;

The LoadDLL function loads the specified library module. Returns the instance handle of the loaded library module if the function is successful. Otherwise, an EOutOfResources exception is raised.

LoadDLL example:

{$IFDEF WIN32}
TUHandle := LoadDLL('TUTIL32.DLL');
{$ELSE}
TUHandle := LoadDLL('TUTILITY.DLL');
{$ENDIF}


Routine MakeBitmap
Declaration: function MakeBitmap(ResID: PChar): TBitmap;

MakeBitmap instantiates a bitmap object (TBitmap), and loads the specified bitmap resource from an application's executable file. Specify the resource to be loaded as the value of ResID. When you no longer need the bitmap, call it's Destory destructor to free it. If the function fails, the return value is Nil.

MakeBitmap example:

var
__Bmp: TBitmap;
begin
__Bmp := MakeBitmap('MY_BITMAP');
__try
____{ use bitmap }
__finally
____Bmp.Free;
__end;
end;


Routine MakeBitmapID
Declaration: function MakeBitmapID(ResID: Word): TBitmap;

MakeBitmapID instantiates a bitmap object (TBitmap), and loads the specified bitmap resource from an application's executable file. Specify the resource to be loaded as the value of ResID. When you no longer need the bitmap, call it's Destory destructor to free it. If the function fails, the return value is Nil.

MakeBitmapID example:

const ResID = 23012;
var Bmp: TBitmap;
begin
__Bmp := MakeBitmapID(ResID);
__try
____{ use bitmap }
__finally
____Bmp.Free;
__end;
end;


Routine MakeIcon
Declaration: function MakeIcon(ResID: PChar): TIcon;

MakeIcon instantiates an icon object (TIcon), and loads the specified icon resource from an application's executable file. Specify the resource to be loaded as the value of ResID. When you no longer need the icon, call it's Destory destructor to free it. If the function fails, the return value is Nil.

> MakeIcon example:

var
__Ico: TIcon;
begin
__Ico := MakeIcon('MY_ICON');
__try
____{ use icon }
__finally
____Ico.Free;
__end;
end;


Routine MakeIconID
Declaration: function MakeIconID(ResID: Word): TIcon;

MakeIconID instantiates an icon object (TIcon), and loads the specified icon resource from an application's executable file. Specify the resource to be loaded as the value of ResID. When you no longer need the icon, call it's Destory destructor to free it. If the function fails, the return value is Nil.

MakeIconID example:
const ResID = 23012;
var
__Ico: TIcon;
begin
__Ico := MakeIconID(ResID);
__try
____{ use icon }
__finally
____Ico.Free;
en
__d;
end;


Routine MakeModuleBitmap
Declaration: function MakeModuleBitmap(Module: THandle; ResID: PChar): TBitmap;

MakeModuleBitmap instantiates a bitmap object (TBitmap), and loads the specified bitmap resource from a module's executable file. Specify the resource to be loaded as the value of ResID which points to a null-terminated string that contains the name of the bitmap resource to be loaded. Alternatively, this parameter can consist of the resource identifier in the low-order word and zero in the high-order word. The MakeIntResource function can be used to create this value. Module parameter identifies the instance of the module whose executable file contains the bitmap to be loaded.

When you no longer need the bitmap, call it's Destory destructor to free it.

An application can use the MakeModuleBitmap function to access the predefined bitmaps used by the Windows API. To do so, the application must set the Module parameter to zero. If the function fails, the return value is Nil.

MakeModuleBitmap example:
var Bmp: TBitmap;

begin
__Bmp := MakeModuleBitmap(0, PChar(32759)); { check box image }
__try
____{ use bitmap }
__finally
____Bmp.Free;
__end;
end;


Routine MakeModuleIcon
Declaration: function MakeModuleIcon(Module: THandle; ResID: PChar): TIcon;

MakeModuleIcon instantiates an icon object (TIcon), and loads the specified icon resource from a module's executable file. Specify the resource to be loaded as the value of ResID which points to a null-terminated string that contains the name of the icon resource to be loaded. Alternatively, this parameter can consist of the resource identifier in the low-order word and zero in the high-order word. The MakeIntResource function can be used to create this value. Module parameter identifies the instance of the module whose executable file contains the icon to be loaded. When you no longer need the icon, call it's Destory destructor to free it.

An application can use the MakeModuleIcon function to access the predefined icons used by the Windows API. To do so, the application must set the Module parameter to zero and the ResID parameter to one of the following values:

IDI_APPLICATION, IDI_ASTERISK, IDI_EXCLAMATION, IDI_HAND, IDI_QUESTION, IDI_WINLOGO (Win95 or NT 4.0 or higher).

If the function fails, the return value is Nil.

MakeModuleIcon example:
var
__Ico: TIcon;
__Module: THandle;
begin
__Module := LoadLibrary('MY_RES.DLL');
__if Module >= HINSTANCE_ERROR then
__try
____Ico := MakeModuleIcon(Module, MakeIntResource(2));
____try
______{ use icon }
____finally
______Ico.Free;
____end;
__finally
____FreeLibrary(Module);
__end;
end;


Routine MergeForm
Declaration: procedure MergeForm(AControl: TWinControl; AForm: TForm; Align: TAlign; Show: Boolean);

MergeForm merges a form with a NoteBook page.

MergeForm example:
MergeForm(TPage(Notebook.Pages.Objects[0]), TMyForm.Create(Application), alClient, True);


Routine MinimizeText
Declaration: function MinimizeText(const Text: string; Canvas: TCanvas; MaxWidth: Integer): string;

MinimimizeText returns a text string for display purposes, adding ellipses if necessary to maintain a length limit. Call MinimizeText to ensure that a text string fits in the alloted display space. If the text string passed as the Text parameter is longer than MaxWidth pixels when written to the canvas specified by the Canvas parameter, MinimizeText will remove last characters of the string and replace them by ellipses ('...') in order to shorten the resulting string.

MinimizeText example:
{...}
Form1.Canvas.TextRect(Rect, Rect.Left, Rect.Top,
MinimizeText(S, Form1.Canvas, WidthOf(Rect)));
{...}


Routine MsgBox
Declaration: function MsgBox(const Caption, Text: string; Flags: Integer): Integer;

The MsgBox function creates, displays, and operates a message box. This is a wrapper for standard Windows function MessageBox.

MsgBox example:
if MsgBox(Application.Title, 'Continue?', MB_YESNO + MB_ICONSTOP) = mrYes then
begin
__{ ... }
end;


Routine NotImplemented
Declaration: procedure NotImplemented;

NotImplemented, as it's name implies, specifies that the code inside a particular procedure implemented is "not implemented yet."

In other words, the NotImplemented procedure shows a messagebox stating 'Not Implemented Yet'.

NotImplemented example:
procedure TForm1.SaveClick(Sender: TObject);
begin
__NotImplemented;
end;


Routine PaintInverseRect
Declaration: procedure PaintInverseRect(RectOrg, RectEnd: TPoint);

The PaintInverseRect function inverts a rectangle in a screen device context by performing a logical NOT operation on the color values for each pixel in the rectangle's interior. RectOrg and RectEnd parameters contain the logical coordinates of the rectangle in the screen coordinates (relative to the upper-left corner of the screen).

PaintInverseRect example:
Invert and restore Widows screen:
__PaintInversRect(Point(0, 0), Point(Screen.Width, Screen.Height));
__Delay(2000);
__PaintInversRect(Point(0, 0), Point(Screen.Width, Screen.Height));


Routine PixelsToDialogUnitsX
Declaration: function PixelsToDialogUnitsX(PixUnits: Word): Word;

Convert pixels to dialog units in horizontal direction. The dialog box base units used by Windows to create dialog boxes.

PixelsToDialogUnitsX example:
__X := PixelsToDialogUnitsX(X);


Routine PixelsToDialogUnitsY
Declaration: function PixelsToDialogUnitsY(PixUnits: Word): Word;

Convert pixels to dialog units in vertical direction. The dialog box base units used by Windows to create dialog boxes.

PixelsToDialogUnitsY example:
__Y := PixelsToDialogUnitsY(Y);


Routine PointInPolyRgn
Declaration: function PointInPolyRgn(const P: TPoint; const Points: array of TPoint): Boolean;

The PointInRgn function determines whether the specified point is inside the specified region. If the specified point is in the region, the return value is True. Points parameter is an array of TPoint records that define the vertices of the polygon. The polygon is presumed closed. Each vertex can be specified only once.

PointInPolyRgn example:
with MyForm do
if PointInPolyRgn(Point(X, Y), [Point(Left, Top), Point(Left + Width, Top), Point(Left + Width div 2, Top + Height div 2)]) then
begin
__{ ... }
end;


Routine PointInRect
Declaration: function PointInRect(const P: TPoint; const R: TRect): Boolean;

The PointInRect function determines whether the specified point P lies within the specified rectangle R. A point is within a rectangle if it lies on the left or top side or is within all four sides. A point on the right or bottom side is considered outside the rectangle. If the specified point lies within the rectangle, the return value is True.

PointInRect example:
if PointInRect(Point(X, Y), Image1.ClientRect) then begin
{ ... }
end;


Routine RegisterServer
Declaration: function RegisterServer(const ModuleName: string): Boolean;

RegisterServer registers an OLE server.

RegisterServer example:
RegisterServer('cfx32.ocx');


Routine ResourceNotFound
Declaration: procedure ResourceNotFound(ResID: PChar);

ResourceNotFound triggers an exception 'Resource Not Found' with ResId identified (or shown) as the bad resource.

ResourceNotFound example:
procedure LoadCursorRes(ResID: PChar; AssignTo: TCursor);
var
__Handle: HCursor;
begin
__Handle := LoadCursor(hInstance, ResID);
__if Handle = 0 then
____ResourceNotFound(ResID)
__else
____Screen.Cursors[AssignTo] := Handle;
end;


Routine ShadeRect
Declaration: procedure ShadeRect(DC: HDC; const Rect: TRect);

ShadeRect the specified Rect (rectangle) area with parameter DC (Device to Context).

ShadeRect example:
ShadeRect(Canvas.Handle, ARect);


Routine SplitCommandLine
Declaration: procedure SplitCommandLine(const CmdLine: string; var ExeName, Params: string);

SplitCommandLine splits the commandline information presented to the program into the head (ExeName) and tail (Params).

SplitCommandLine example:

S := 'MYAPP.EXE "Parameter Name" -K -S';
SplitCommandLine(S, ExeName, Params);
{ here ExeName = 'MYAPP.EXE' Params = '"Parameter Name" -K -S' }


Routine StartWait
Declaration: procedure StartWait;

StartWait starts the waiting period. See also: StopWait

StartWait example:
StartWait; { set cursor to WaitCursor }
try
__{ ... }
__StartWait; { no effect }
__try
____{ ... }
__finally
____StopWait; { no effect }
__end;
__{ ... }
finally
__StopWait; { restore default cursor }
end;


Routine StopWait
Declaration: procedure StopWait;

StopWait stops the waiting period. See also: StartWait

StopWait example:
StartWait; { set cursor to WaitCursor }
try
__{ ... }
__StartWait; { no effect }
__try
____{ ... }
__finally
____StopWait; { no effect }
__end;
__{ ... }
finally
__StopWait; { restore default cursor }
end;


Routine WidthOf
Declaration: function WidthOf(R: TRect): Integer;

Retrieves the horizontal size (width) of the specified rectangle R in pixels.

WidthOf example:
W := WidthOf(Rect);


Routine Win32Check
Declaration: function Win32Check(RetVal: Bool): Bool;

Win32Check checks the return value of a Windows 32-bit API call and raises an appropriate exception when it indicates failure.

Call Win32Check with the return value of a Windows API call that returns a Boolean to indicate success or failure. If the Windows API function returns False (indicating failure), Win32Check raise an exception with message returned as

SysErrorMessage(GetLastError).

If the API function returns True, Win32Check returns True.

This function presents only in RX version for Delphi 2.0. In Delphi 3.0 such function presents in standard module SYSUTILS.PAS.

Win32Check example:
Win32Check(CreateDirectory('C:\myworld\private', nil));


Index Page | About | Download
Creation Date: 4 Feb 1998 | Last Update: 16 Mar 2000