Solved

How do i save statusbar settings to the registry etc...

Posted on 1998-10-30
7
157 Views
Last Modified: 2010-04-06
How do i save statusbar settings to the registry, I want to have a View| Status Bar, and have it display and hide the status bar, but also save the settings to the registry at the same time. So when i load my program the statusbar will be displayed or not displayed. also have the statusbar menu item check when the statusbar is displayed and not checked when it is hidden on startup. Code Examples Please Thank's Hyper66.
0
Comment
Question by:hyper66
  • 5
  • 2
7 Comments
 
LVL 5

Accepted Solution

by:
inter earned 100 total points
ID: 1345024
The easiest way is to use TRegIniFile. Add the following part to your forms implementation part and do the following:

1 - Declare the following in your forms public part
procedure WriteRegistry;
procedure ReadRegistry;
2 - on your menu click paste the code I supplied
3 - Test the result

The following creates a key under HKEY_CURENT_USER\Software\hyperProgs\hyper66.
You can add as many properties as you want with this method


const
  SECTION = 'hyper66';
var
  FIniFile : TRegIniFile;

procedure tform1.FormCreate(Sender: TObject);
begin
  FIniFile := TRegIniFile.Create('Software\hyperProgs');
  ReadRegistry;
end;

procedure tform1.WriteRegistry;
begin
  FIniFile.WriteBool(SECTION, 'BooleanTest', MyMenu1.Checked);
end;

procedure tform1.ReadRegistry;
begin
  MyMenu1.Checked := FIniFile.ReadBool(SECTION, 'BooleanTest', False);
end;

procedure TForm1.MyMenu1Click(Sender: TObject);
begin
  MyMenu1.Checked := not MyMenu1.Checked;
  WriteRegistry;
  //hide or show you status bar here
end;

regards, igor
0
 

Author Comment

by:hyper66
ID: 1345025
I followed the example above but all the code does is just add a Zero to registry, How can i get it to display or hide the statubar by reading from the reg, I can't get that part to work.
This is what i have.

Unit Unit1;

Interface

Uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Registry, Menus, ComCtrls;

Type
  TForm1 = Class(TForm)
    MainMenu1   : TMainMenu;
    View1       : TMenuItem;
    Statusbar1  : TMenuItem;
    Statusbar   : TStatusBar;
    Procedure FormCreate(Sender : TObject);
    Procedure Statusbar1Click(Sender : TObject);
    Procedure WriteRegistry;
    Procedure ReadRegistry;
  Private
    { Private-Deklarationen }
    RegIni : TRegIniFile;
  Public
    { Public-Deklarationen }
  End;

var
  Form1: TForm1;

Implementation

{$R *.DFM}

Const
 Section = 'Hyper66';

Procedure TForm1.FormCreate(Sender: TObject);
Begin
 RegIni := TRegIniFile.Create('Software\HyperProgs');
 ReadRegistry;
End;

Procedure TForm1.WriteRegistry;
Begin
 RegIni.WriteBool(Section,'BooleanTest',StatusBar1.Checked);
End;

Procedure TForm1.ReadRegistry;
Begin
 StatusBar1.Checked := RegIni.ReadBool(Section,'BooleanTest',False);
End;

procedure TForm1.Statusbar1Click(Sender: TObject);
Begin
 StatusBar.Visible := Not StatusBar.Visible;
 WriteRegistry;
  If StatusBar.Visible Then
   StatusBar.Visible := True
   Else
  StatusBar.Visible := False;
 StatusBar1.Checked := StatusBar.Visible;
End;

Initialization

End.


What am i doing wrong??
0
 
LVL 5

Expert Comment

by:inter
ID: 1345026
move
StatusBar1.Checked := StatusBar.Visible;
just before
WriteRegistry
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 5

Expert Comment

by:inter
ID: 1345027
move
StatusBar1.Checked := StatusBar.Visible;
just before
WriteRegistry
0
 
LVL 5

Expert Comment

by:inter
ID: 1345028
My friend,
the good programing practice tells us to syncronize the actions of linked controls. What I mean is to think carefully about WHO causes WHAT before coding. In our example

StatusBar1 menu CAUSES StatusBar to be visible or not
So, the our original even for synchronization should be CHANGE of StatusBar1.Checked. We'better do the following:(the other parts are unchanged)

Procedure TForm1.WriteRegistry;
Begin
  RegIni.WriteBool(Section,'BooleanTest',StatusBar1.Checked);
End;

Procedure TForm1.ReadRegistry;
Begin
 StatusBar1.Checked := RegIni.ReadBool(Section,'BooleanTest',False);
 StatusBar.Visible := StatusBar1.Checked;
End;

procedure TForm1.Statusbar1Click(Sender: TObject);
Begin
 StatusBar1.Checked := not StatusBar1.Checked;
 StatusBar.Visible := StatusBar1.Checked;  
 WriteRegistry;
End;
0
 

Author Comment

by:hyper66
ID: 1345029
Excellent. Thank's inter.
0
 
LVL 5

Expert Comment

by:inter
ID: 1345030
you are welcome, happy it works, regards, inter
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question