computerprogramer
asked on
Writing to the Registery
Hey,
Is there a way so when I enter some random word into a form and then click on a button it will store it in the registrey and then say the next day i enter the same word into another form and click ok it will find the word in the registery and then say found and if it didnt it would say not found.
Is there a way?
Cheers,
Computer Programer
Is there a way so when I enter some random word into a form and then click on a button it will store it in the registrey and then say the next day i enter the same word into another form and click ok it will find the word in the registery and then say found and if it didnt it would say not found.
Is there a way?
Cheers,
Computer Programer
Well, my example:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,registry, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function CheckRandomWord(RandomWord : STring; var Buffer: String): Boolean;
var
reg: TRegistry;
begin
Result := False;
Buffer := Format('Word %s was not found',[RandomWord]);
Reg := TRegistry.Create;
try
with Reg do
begin
RootKEy := HKEY_LOCAL_MACHINE;
If KeyExists('\Software\MyApp lication\R andomWord' ) then
begin
OpenKey('\Software\MyAppli cation\Ran domWord',F alse);
result := ReadString('Value') = RandomWord;
If Result then
Buffer := Format('Word %s was found',[RandomWord]);
CLoseKEy;
end else begin
OpenKey('\Software\MyAppli cation\Ran domWord',T rue);
WriteString('Value',Random Word);
Buffer := Format('Word %s was stored',[RandomWord]);
CLoseKEy;
end;
end;
finally
reg.Free;
end;
end;
procedure TForm1.Button1Click(Sender : TObject);
var
Msg: STring;
begin
CheckRandomWord(Edit1.Text ,Msg);
ShowMessage(Msg);
end;
end.
F68 ;-)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,registry, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function CheckRandomWord(RandomWord
var
reg: TRegistry;
begin
Result := False;
Buffer := Format('Word %s was not found',[RandomWord]);
Reg := TRegistry.Create;
try
with Reg do
begin
RootKEy := HKEY_LOCAL_MACHINE;
If KeyExists('\Software\MyApp
begin
OpenKey('\Software\MyAppli
result := ReadString('Value') = RandomWord;
If Result then
Buffer := Format('Word %s was found',[RandomWord]);
CLoseKEy;
end else begin
OpenKey('\Software\MyAppli
WriteString('Value',Random
Buffer := Format('Word %s was stored',[RandomWord]);
CLoseKEy;
end;
end;
finally
reg.Free;
end;
end;
procedure TForm1.Button1Click(Sender
var
Msg: STring;
begin
CheckRandomWord(Edit1.Text
ShowMessage(Msg);
end;
end.
F68 ;-)
ASKER
Hi,
Thanks for the replys. F68 is there a way that you could put something in the code so if a different word was entred and there already is a word stored there is would delete the older word and enter the newer word?
Thanks for the replys. F68 is there a way that you could put something in the code so if a different word was entred and there already is a word stored there is would delete the older word and enter the newer word?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Mate!
Glad to have helped you :)
F68 ;-)
F68 ;-)
https://www.experts-exchange.com/questions/10834801/read-and-write-the-registry.html