UNIT AppUtils
Unit Overview:
GetDefaultIniName
GetDefaultIniRegKey
GetDefaultSection
GetUniqueFileNameInDir
InstantiateForm
DefCompanyName
RegUseAppTitle
AppBroadcast
FindForm
ReadFormPlacement
ReadFormPlacementReg
RestoreFormPlacement
RestoreGridLayout
RestoreGridLayoutReg
RestoreMDIChildren
RestoreMDIChildrenReg
SaveFormPlacement
SaveGridLayout
SaveGridLayoutReg
SaveMDIChildren
SaveMDIChildrenReg
ShowDialog
WriteFormPlacement
WriteFormPlacementReg
Const DefCompanyName
Declaration:
DefCompanyName: string = '';;
This variable uses by GetDefaultIniRegKey function to construct registry key used by TFormPlacement and TFormStorage components.
Const RegUseAppTitle
Declaration:
RegUseAppTitle: Boolean = False;;
This variable uses by GetDefaultIniRegKey function to construct registry key used by TFormPlacement and TFormStorage components.
Routine AppBroadcast
Declaration:
procedure AppBroadcast(Msg, wParam: Longint; lParam: Longint);
AppBroadcast sends a message Msg
to each of the forms of the application.
AppBroadcast example:
const CM_MYMESSAGE = WM_USER + 1;
begin
__...
__AppBroadcast(CM_MYMESSAGE, MyWParam, MyLParam);
__...
end;
Routine FindForm
Declaration: function
FindForm(FormClass: TFormClass): TForm;
FindForm returns the windowed Delphi's form whose class is identified by the specified class name FormClass. If FormClass is not the name of the class of an existing form, FindForm returns nil.
FindForm example:
begin
__F := FindForm(TMyForm);
__if F = nil then
____Application.CreateForm(TMyForm, F);
__with F do
__begin
____if WindowState = wsMinimized then
WindowState := wsNormal;
____Show;
__end;
end;
Routine FindShowForm
Declaration: function
FindShowForm(FormClass: TFormClass; const Caption: string):
TForm;
FindShowForm returns the windowed Delphi's form whose class is identified by the specified class name FormClass and (or) window caption passed as Caption. If FormClass is not the name of the class of an existing form, FindShowForm creates new form by calling Application.CreateForm. For found or created form the Show method is called.
FindShowForm example:
procedure MainForm.ShowFormItemClick(Sender: TObject);
begin
__FindShowForm(TForm1, '');
end;
Routine GetDefaultIniName
Declaration: function
GetDefaultIniName: string;
Returns the default name for the application initialization file (INI-file). Result string contains the name of the executable application with extension replaced by '.INI' and excluding path information. The result of GetDefaultIniName function can be passed as FileName parameter to the TIniFile constructor.
GetDefaultIniName example:
begin
__...
__IniFile :=
TIniFile.Create(GetDefaultIniName);
__...
end;
Routine GetDefaultIniRegKey
Declaration: function
GetDefaultIniRegKey: string;
Returns the default name for the
application registry key. Result string has next format:
"HKEY_CURRENT_USER\Software\" + <DefCompanyName\>
+ <application name>
DefCompanyName is global string variable, equal to empty string
by default. <application name> is application EXE-name
without extension when RegUseAppTitle is False (by default) and
is value of Application.Title property when RegUseAppTitle is
True. The result of GetDefaultIniRegKey function can be passed as
FileName parameter to the TRegIniFile constructor.
GetDefaultIniRegKey example:
begin
__...
__RegUseAppTitle := True;
__DefCompanyName := 'My Company';
__...
__RegIniFile :=
TRegIniFile.Create(GetDefaultIniRegKey);
__...
end;
Routine GetDefaultSection
Declaration: function
GetDefaultSection(Component: TComponent): string;
The function returns unique string for specified Component. This string can be used, for instance, as section name in the TIniFile (or TRegIniFile) object to store specific component's properties.
Kind of return value can be understand from function's text below:
function
GetDefaultSection(Component: TComponent): string;
var
__F: TCustomForm;
__Owner: TComponent;
begin
__if Component <> nil then
__begin
____if Component is TCustomForm then
______Result := Component.ClassName
____else begin
______Result := Component.Name;
______if Component is TControl then
______begin
________F := GetParentForm(TControl(Component));
________if F <> nil then
__________Result := F.ClassName + Result
________else begin
__________if TControl(Component).Parent <> nil
then
____________Result := TControl(Component).Parent.Name +
Result;
________end;
______end else
______begin
________Owner := Component.Owner;
________if Owner is TForm then
__________Result := Format('%s.%s', [Owner.ClassName,
Result]);
______end;
____end;
__end else
____Result := '';
end;
GetDefaultSection example:
var
__Ini: TIniFile;
__Sect: string;
begin
__...
__Sect := GetDefaultSection(Bevel1);
__with Bevel1 do
__begin
____Ini.WriteInteger(Sect, 'Shape',
Integer(Bevel1.Shape));
____Ini.WriteInteger(Sect, 'Width',
Bevel1.Width);
__end;
end;
Routine GetUniqueFileNameInDir
Declaration: function
GetUniqueFileNameInDir(const Path, FileNameMask: string): string;
The GetUniqueFileNameInDir creates a unique (for specified directory) name for a file. The filename is the concatenation of specified path and strings formed from a specified FileNameMask The FileNameMask parameter MUST contain "%d".
GetUniqueFileNameInDir
example:
FileName := GetUniqueFileNameInDir('C:\TEMP',
'file%d.tmp');
Routine InstantiateForm
Declaration: function
InstantiateForm(FormClass: TFormClass; var Reference): TForm;
When the Reference parameter is nil then InstantiateForm creates a new form of the type specified by the FormClass parameter and assigns it to the variable given by the Reference parameter. The owner of the new form is the Application object. Return value is final value of Reference parameter. When the initial Reference value is not nil then InstantiateForm don't create new form and simply return Reference as function return value.
InstantiateForm example:
with InstantiateForm(TMyForm,
MyForm) do
__ShowModal;
Routine ReadFormPlacement
Declaration:
procedure ReadFormPlacement(Form: TForm; IniFile: TIniFile; const
Section: string; LoadState, LoadPosition: Boolean);
ReadFormPlacement retrieves state (normal, minimize, maximize) and placement (size and position) of Delphi form Form from an INI file specified by IniFile parameter.
To store form's placement to an INI file use WriteFormPlacement or SaveFormPlacement procedures.
ReadFormPlacement example:
ReadFormPlacement(MyMDIChildForm, IniFile,
MyMDIChildForm.ClassName, True, False);
Routine ReadFormPlacementReg
Declaration:
procedure ReadFormPlacementReg(Form: TForm; IniFile: TRegIniFile;
const Section: string; LoadState, LoadPosition: Boolean);
ReadFormPlacementReg retrieves state (normal, minimize, maximize) and placement (size and position) of Delphi form Form from the Windows 95/NT system registry.
To store form's placement to the system registry use WriteFormPlacementReg procedure.
ReadFormPlacementReg
example:
ReadFormPlacementReg(MyMDIChildForm, RegIniFile,
MyMDIChildForm.ClassName, True, False);
Routine RestoreFormPlacement
Declaration:
procedure
RestoreFormPlacement(Form: TForm; const IniFileName: string);
NOTE! In 32-bit Delphi versions
this procedure has next syntax:
procedure
RestoreFormPlacement(Form: TForm; const IniFileName: string;
UseRegistry: Boolean);
RestoreFormPlacement retrieves state (normal, minimize, maximize) and placement (size and position) of Delphi form Form from an INI file specified by IniFileName parameter (or from the Windows95/NT system registry in 32-bit Delphi versions).
To store form's placement to an INI file or system registry use SaveFormPlacement procedure.
RestoreFormPlacement
example:
RestoreFormPlacement(MyForm, GetDefaultIniName);
Routine RestoreGridLayout
Declaration:
procedure RestoreGridLayout(Grid: TCustomGrid; IniFile:
TIniFile);
Retrieves grid's columns widths and positions (indexes) from an INI file. Can be used for any TCustomGrid descendants such as TStringGrid, TDrawGrid, TRxDrawGrid or other. To save grid's layout to an INI file use SaveGridLayout procedure. You can call this procedure in the OnRestorePlacement event handler of the
TFormPlacement, TFormStorage components.
RestoreGridLayout example:
RestoreGridLayout(DrawGrid1, Placement.IniFile);
Routine RestoreGridLayoutReg
Declaration:
procedure RestoreGridLayoutReg(Grid: TCustomGrid; IniFile:
TRegIniFile);
Retrieves grid's columns widths and positions (indexes) from the Windows95/NT system registry. Can be used for any TCustomGrid descendants such as TStringGrid, TDrawGrid, TRxDrawGrid or other. To save grid's layout to the system registry use SaveGridLayoutReg procedure. You can call this procedure in the OnRestorePlacement event handler of the TFormPlacement, TFormStorage components when its UseRegistry property is True.
RestoreGridLayoutReg example:
RestoreGridLayoutReg(DrawGrid1, Placement.RegIniFile);
Routine RestoreMDIChildren
Declaration:
procedure RestoreMDIChildren(MainForm: TForm; IniFile: TIniFile);
This procedure restores from an INI-file set and placements of MDI-child forms in MDI application. Use RestoreMDIChildren with SaveMDIChildren to store all child forms in INI-file. You must register all MDI-child form classes by RegisterClass or RegisterClasses procedure to use these classes in SaveMDIChildren and RestoreMDIChildren procedures.
RestoreMDIChildren
example:
RestoreMDIChildren(MainForm, IniFile);
...
initialization
__RegisterClasses([TChildForm1,
TChildForm2]);
end.
Routine RestoreMDIChildrenReg
Declaration:
procedure RestoreMDIChildrenReg(MainForm: TForm; IniFile:
TRegIniFile);
This procedure restores from Windows System Registry set and placements of MDI-child forms in MDI application.
Use RestoreMDIChildrenReg with SaveMDIChildrenReg to store all child forms in Registry.
You must register all MDI-child form classes by RegisterClass or RegisterClasses procedure to use these classes in SaveMDIChildrenReg and RestoreMDIChildrenReg procedures.
RestoreMDIChildrenReg
example:
RestoreMDIChildrenReg(MainForm, RegIniFile);
...
initialization
__RegisterClasses([TChildForm1,
TChildForm2]);
end.
Routine SaveFormPlacement
Declaration:
procedure
SaveFormPlacement(Form: TForm; const IniFileName: string);
NOTE! In 32-bit Delphi versions this procedure has next syntax:
procedure SaveFormPlacement(Form: TForm; const IniFileName: string; UseRegistry: Boolean);
SaveFormPlacement writes state (normal, minimize, maximize) and placement (size and position) of Delphi form Form to an INI file specified by IniFileName parameter (or to the Windows95/NT system registry in 32-bit Delphi versions).
To retrieve form's placement from an INI file or system registry use RestoreFormPlacement procedure.
SaveFormPlacement example:
SaveFormPlacement(MyForm, GetDefaultIniName);
Routine SaveGridLayout
Declaration:
procedure SaveGridLayout(Grid: TCustomGrid; IniFile: TIniFile);
Write grid's columns widths and positions (indexes) to an INI file. Can be used for any TCustomGrid descendants such as TStringGrid, TDrawGrid, TRxDrawGrid or other. To retrieve grid's layout from an INI file use RestoreGridLayout procedure. You can call this procedure in the OnSavePlacement event handler of the TFormPlacement, TFormStorage components.
SaveGridLayout example:
SaveGridLayout(DrawGrid1, Placement.IniFile);
Routine SaveGridLayoutReg
Declaration:
procedure SaveGridLayoutReg(Grid: TCustomGrid; IniFile:
TRegIniFile);
Writes grid's columns widths and positions (indexes) to the Windows95/NT system registry. Can be used for any TCustomGrid descendants such as TStringGrid, TDrawGrid, TRxDrawGrid or other. To retrieve grid's layout from the system registry use RestoreGridLayoutReg procedure. You can call this procedure in the OnSavePlacement event handler of the TFormPlacement, TFormStorage components when its UseRegistry property is True.
SaveGridLayoutReg example:
SaveGridLayoutReg(DrawGrid1, Placement.RegIniFile);
Routine SaveMDIChildren
Declaration:
procedure SaveMDIChildren(MainForm: TForm; IniFile: TIniFile);
This procedure stores in INI-file set and placements of opened MDI-child forms in MDI application. Use SaveMDIChildren with RestoreMDIChildren to open all child forms stored by SaveMDIChildren. You must register all MDI-child form classes by RegisterClass or RegisterClasses procedure to use these classes in SaveMDIChildren and RestoreMDIChildren procedures.
SaveMDIChildren example:
SaveMDIChildren(MainForm, IniFile);
Routine SaveMDIChildrenReg
Declaration:
procedure SaveMDIChildrenReg(MainForm: TForm; IniFile:
TRegIniFile);
This procedure stores in Windows System Registry set and placements of opened MDI-child forms in MDI application.
Use SaveMDIChildrenReg with RestoreMDIChildrenReg to open all child forms stored by SaveMDIChildrenReg.
You must register all MDI-child form classes by RegisterClass or RegisterClasses procedure to use these classes in SaveMDIChildrenReg and RestoreMDIChildrenReg procedures.
SaveMDIChildrenReg example:
SaveMDIChildrenReg(MainForm, RegIniFile);
Routine ShowDialog
Declaration: function
ShowDialog(FormClass: TFormClass): Boolean;
ShowDialog creates Delphi form of the type specified by the FormClass parameter and shows new form as a modal form by using ShowModal method. When the modal form is closed, ShowDialog destroys the form by using Free method.
ShowDialog returns True if the ModalResult property of the form is mrOk or mrYes, another ShowDialog returns False.
ShowDialog example:
var
__Ok: Boolean;
begin
__Ok := ShowDialog(TAboutDlg);
end;
Routine WriteFormPlacement
Declaration:
procedure WriteFormPlacement(Form: TForm; IniFile: TIniFile;
const Section: string);
WriteFormPlacement writes state (normal, minimize, maximize) and placement (size and position) of Delphi form Form to an INI file specified by IniFileName parameter. To retrieve form's placement from an INI file use ReadFormPlacement procedure.
WriteFormPlacement
example:
WriteFormPlacement(MyForm, IniFile, MyForm.ClassName);
Routine WriteFormPlacementReg
Declaration:
procedure WriteFormPlacementReg(Form: TForm; IniFile:
TRegIniFile; const Section: string);
WriteFormPlacementReg writes state (normal, minimize, maximize) and placement (size and position) of Delphi form Form to the Windows95/NT system registry key specified by IniFile parameter. To retrieve form's placement from the system registry use ReadFormPlacementReg procedure.
WriteFormPlacementReg
example:
WriteFormPlacementReg(MyForm, RegIniFile,
MyForm.ClassName);
Index Page | About | Download
Creation Date: 4 Feb 1998 | Last Update: 16 Mar 2000