Link to home
Start Free TrialLog in
Avatar of hyperion66
hyperion66

asked on

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.
Avatar of TheNeil
TheNeil

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
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.
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
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.
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.
John

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

The Neil
Neil,

Ha, I wish!

John.
John

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

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

John.
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
Avatar of hyperion66

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of TheNeil
TheNeil

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank's TheNeil.