Name
HInstance Variable
Syntax
unit SysInit; var HInstance: LongWord;
Description
The HInstance variable stores the instance handle
for the module (application, library, or package) that contains the
HInstance reference.
Tips and Tricks
The most common use for a module’s instance handler is to load resources from the module. A unit can use
HInstanceto load resources that are linked with that unit (using the$Rcompiler directive). To load resources that are linked with a different unit (which might reside in a different package), see theFindHInstancefunction.To load resources that must be localized (e.g., forms, strings), see
FindResourceHInstance.The instance handle of the main application is stored in
MainInstance.Earlier versions of Delphi stored the main instance handle in
HInstance, requiring a call toFindHInstanceto learn a module’s instance handle. The current release stores the module’s instance handle inHInstance.
Example
// Use the Image Editor to create a .RES file that
// contains the company logo as the resource named LOGO.
// The GetLogo procedure sets its Bitmap argument
// to the company logo bitmap.
{$R 'Logo.res'}
procedure GetLogo(Bitmap: TBitmap);
begin
Bitmap.LoadFromResourceName(HInstance, 'LOGO');
end;See Also
| FindClassHInstance Function, FindHInstance Function, MainInstance Variable |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access