Solved

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

Posted on 1998-10-30
7
154 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now