function CreateKey(const Key: String): Boolean; procedure TForm1.Button1Click(Sender: TObject); var Reg: TRegIniFile; begin if Length(NameofKey.Text) or Length(ValueforKey.Text) <=0 then Showmessage('Either the key name or value is missing.') else begin Reg:=TRegIniFile.Create('MyApp'); try Reg.RootKey:=HKey_Local_Machine; // Section to look for within the registry if not Reg.OpenKey(NameofKey.Text,False) then if MessageDlg('The specified key does not exist, create it?' ,Mtinformation,[mbYes,mbNo],0)=mryes then begin Reg.CreateKey(NameofKey.Text); if not Reg.OpenKey(NameofKey.Text,False) then ShowMessage('Error in Opening Created Key') else Reg.WriteString('Main Section','Value1',ValueForKey.Text); end else Reg.WriteString('Main Section','Value1',ValueForKey.Text); finally Reg.Free; end; end; end;
procedure TForm1.Button1Click(Sender: TObject);
var
Reg: TRegIniFile;
begin
if Length(NameofKey.Text) or Length(ValueforKey.Text) <=0 then
Showmessage('Either the key name or value is missing.')
else begin
Reg:=TRegIniFile.Create('MyApp');
try
Reg.RootKey:=HKey_Local_Machine; // Section to look for within the registry
if not Reg.OpenKey(NameofKey.Text,False) then
if MessageDlg('The specified key does not exist, create it?' ,Mtinformation,[mbYes,mbNo],0)=mryes then
begin
Reg.CreateKey(NameofKey.Text);
if not Reg.OpenKey(NameofKey.Text,False) then
ShowMessage('Error in Opening Created Key')
else
Reg.WriteString('Main Section','Value1',ValueForKey.Text);
end
else
Reg.WriteString('Main Section','Value1',ValueForKey.Text);
finally Reg.Free;
end;
end;
end;