TPJWdwState & TPJRegWdwState 5.4.1

By Peter Johnson

Freeware 10 Jan 2013

In category

Components > Forms > State savers


The window state components can save and restore a window's size, position and state (minimized, maximized or normal) between program executions. Three components are provided that use different means of storing the information. They are:
  • TPJWdwState: This component records window information in an ini file. The user has control over the ini file name (via the IniFileName property) and the name of the section of the file where window information is recorded (using the Section property). Alternatively the ini and section names can be configured by handling the OnGetIniData event that is triggered immediately before the ini file is read or written.
  • TPJRegWdwState: This component uses the registry to record window information. The registry root key and sub key where the information is stored are controlled by the RootKey and SubKey properties, or by handling the OnGetRegData event. This event is triggered just before the registry is accessed.
  • TPJUserWdwState: This component relies on the user to handle saving and reading the window state data to or from persistent storage. The component gives the most flexibility of all the components at the expense of placing the storage burden on the user. The component triggers OnReadData and OnSaveData events when it is ready to read or save data.
All components implement the same functionality, controlled by some common properties and events, as follows::
  • The components can automatically restore and save windows when the program starts up and closes down (using the AutoSaveRestore property). If AutoSaveRestore is set to False then the Restore and Save methods must be called from the host application.
  • The Options property can be used to customise the way the window is restored. State, and position can be ignored, which is useful for dialog boxes that should retain the same size and not be minimizied. The window can also be kept within the desktop's work area.
  • When the form is to be restored in a minimized state it briefly appears on screen in the normal state before being minimized. The MinimizeDelay property controls the delay between the window appearing and being minimized.
TPJWdwState and TPJRegWdwState also support the OnReadWdwState event. Handling this event enables the stored window's state, size and position values to be changed before the window is restored. This event is called after reading the data and before sizing the window. TPJUserWdwState does not expose this event because the user is in charge of reading the data and can modify it in the OnReadData event.

An abstract base class for both components – TPJCustomWdwState – is also provided. This class provides the core window handling and sizing functionality. It provides abstract methods for accessing the required storage medium. Therefore it is quite straightforward to create further components that use alternative storage systems. All that needs to be provided are methods to read/write the window information along with any additional properties that are required to configure the storage medium.

Compatible with 32bit and 64bit targets with Delphi XE2 or later.

A help file is included that integrates into the Delphi 3 to 7 OpenHelp system. The help does not integrate with Delphi 2005 and later, but can be used independently of the IDE, with some loss of functionality.

The components are also documented in a wiki.

A property editor is provided for editing HKEY values (such as the registry root key property of TPJRegWdwState). This editor is also available separately.


  • Status: Fully functional
  • Source: FW
  • Size: 71 876kB


  • Delphi 2005 (VCL)
  • Delphi 2006 (Win32)
  • Delphi 2007 (VCL)
  • Delphi 2009
  • Delphi 2010
  • Delphi 3
  • Delphi 4
  • Delphi 5
  • Delphi 6
  • Delphi 7
  • Delphi XE
  • Delphi XE 2
  • Delphi XE3
  • Delphi XE2 64-bit