Tuesday, July 18, 2006

Delphi Tips: How To Save The Position & Size Of A Form Based On A User's Preference

I sometimes get asked the question: How do you save the position and size of a given window based on a user's preference, and then use the saved settings next time you open the window?

The solution to this problem is quite simple. First, you must decide how to save the settings. The three most common ways are:

  1. Use an INI File - Typically one user per computer
  2. Use the Windows Registry - Can be for a single user, or for multiple users with different accounts sharing the same computer
  3. Use a database table - Client/Server environmnet where one user can use any networked computer

I will only cover the first method - the use of an INI file to save the settings. The concept is the same for all three:

When the window is opened, check to see if you should load any saved settings and if they had been saved. If so, use the settings to display the window. Otherwise, load the default window settings (design settings). Before closing the window, check to see if you should save any settings. If so, save the settings and exit.

To see the full explanation and code, click on:

How To Save A Window's Size & Position In Delphi

For more information about Online Delphi Training:

Krikor Mnatzaganian
Managing Director Of Training
Website: www.OnlineDelphiTraining.com
Phone: +1 (678) 921-0644
Email: info@onlinedelphitraining.com

No comments: