Who Do I Save CheckMark Settings Of A Popup Menu To The Registry?

Who Do I Save CheckMark Settings Of A Popup Menu To The Registry?

 I would like to save the settings of my popup menu, but I cannot get anything to work without errors and crashes. I have "Pictures and Text" as one heading. When I click on "Pictures and Text" on my popup menu I want it to save the settings to the registey, so that when I load my program that Popup Menu Item is always checked. When I choose another Heading "Text Only" on my popup menu I want it to save that setting to the registry and Uncheck "Pictures and Text". When that setting is saved and I load my program I want "Text Only" to be checked. How can I do this.  

Thank's Hyperion66.
hyperion66Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheNeilCommented:
You're probably trying to save actual booleans. An alternative would be to save either integers or strings and decode them yourself.

i.e.

In your OnClick method for your menu items call a further routine that encapsulates the following

IF PicturesAndText1.Checked
THEN
  {Output '1' to the registry entry}
ELSE
  {Output '0' to the registry entry}

IF Text1.Checked
THEN
  {Output '1' to the registry entry}
ELSE
  {Output '0' to the registry entry}

Then when you do the read back from the registry (when you launch your application) just do the following(ish) in your form's OnCreate method:

PicturesAndText1.Checked := {Read entry} = 1;
Text1.Checked := {Read entry} = 1;

It might not be the best solution in the world but it should work

The Neil
0
JaymolCommented:
Sorry to do this Neil, but I'd recommend using an INI file to do what you suggested.  That way, it'll work on all platforms.  (Might not be able to write to registry if it's a low-level user using NT)

Eh?

John.
0
TheNeilCommented:
Jaymol,

No problem with that at all. I only kept with the Registry approach as Hyperion66 specifically mentioned it. Personally I'd always go for the INI file approach myself and this is the approach I use with them when dealing with booleans

The Neil
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

JaymolCommented:
DOH!!!!  Even though the question specifically asked for registry help!!!

Have a look at this....

function ReadRegString(rHKey: HKey; rKey, rName: String): String;
var
  WinReg : TRegistry;
begin
  WinReg:=TRegistry.Create;
  WinReg.RootKey:=rHKey;
  WinReg.OpenKey(rKey, False);
  Result:=WinReg.ReadString(rName);
  WinReg.Free;
end;

procedure WriteRegString(rHKey: HKey; rKey, rName, rValue: String);
var
  WinReg : TRegistry;
begin
  WinReg:=TRegistry.Create;
  WinReg.RootKey:=rHKey;
  WinReg.OpenKey(rKey, False);
  WinReg.WriteString(rName, rValue);
  WinReg.Free;
end;

Those 2 bits of code make it a tad easier to read/write the reg entries.

John.
0
JaymolCommented:
Sorry.....I posted that last bit of stuff after you posted the last bit you did, but only saw it after the bit I did was posted now!  (D'you get me?)

John.
0
TheNeilCommented:
John

Err, are you on drugs? Can I have some?

The Neil
0
JaymolCommented:
Neil,

Ha, I wish!

John.
0
TheNeilCommented:
John

About which bit? The bit about you being on drugs or the bit about me having some?

The Neil
0
JaymolCommented:
He's not gonna take this as an answer is he?  He's just used us for our knowledge - I feel violated! :(

John.
0
TheNeilCommented:
John

Would you in all honestly give good points for a load of questions about suspected drug usage/availability? (Naturally you'd head for the 'Crack Head' section for such things)

The Neil
0
hyperion66Author Commented:
Hi TheNeil,

 Could you please so me an example or demo explaining how to accomplish this task. I have tried but I cannot get it to work.

 Thank's Hyperion66
0
TheNeilCommented:
Hyperion66,

No problem. If you don't mind though, I'll use INI files rather than the registry (if you want a registry version then just say).

You'll need to add INIFiles to your USES clause.

PROCEDURE TForm1.SaveSettings;
VAR
  iniINI_Data : TINIFile;
BEGIN
  iniINI_Data := TINIFile.Create('MyINIFile.INI');

  IF MenuCommand1.Checked
  THEN
    iniINI_Data.WriteInteger('Menu Settings', 'Option1', 1)
  ELSE
    iniINI_Data.WriteInteger('Menu Settings', 'Option1', 0);

  IF MenuCommand2.Checked
  THEN
    iniINI_Data.WriteInteger('Menu Settings', 'Option2', 1)
  ELSE
    iniINI_Data.WriteInteger('Menu Settings', 'Option2', 0);

  iniINI_Data.Free;
END;

PROCEDURE TForm1.ReadSettings;
VAR
  iniINI_Data : TINIFile;
BEGIN
  iniINI_Data := TINIFile.Create('MyINIFile.INI');

  MenuCommand1.Checked := (iniINI_Data.ReadInteger('Menu Settings', 'Option1', 0) = 1);

  MenuCommand2.Checked := (iniINI_Data.ReadInteger('Menu Settings', 'Option2', 0) = 1);

  iniINI_Data.Free;
END;

What these two routines do is save and load the checked settings for the two menu commands (MenuCommand1 and MenuCommand2). What you need to do is use the ReadSettings routine when you create your form and the SaveSettings routine when you destroy it (or for extra safety, whenever you change the menu states).

Need anymore then just ask

The Neil

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hyperion66Author Commented:
Thank's TheNeil.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.