Solved

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

Posted on 1998-10-30
7
158 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 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