Solved

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

Posted on 1998-10-30
7
155 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi with SQL Natvie Client 15 87
Delphi: how to send PJL commands to printer 3 90
add combobox item based on numbers 9 125
error 1.1 400 Bad request idhttp delphi 18 55
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

22 Experts available now in Live!

Get 1:1 Help Now