Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1998-10-30
7
Medium Priority
?
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 5

Accepted Solution

by:
inter earned 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

730 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