Link to home
Start Free TrialLog in
Avatar of computerprogramer
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
Avatar of Ivanov_G
Ivanov_G
Flag of Bulgaria image

Avatar of Ferruccio Accalai
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\MyApplication\RandomWord') then
            begin
               OpenKey('\Software\MyApplication\RandomWord',False);
               result := ReadString('Value') = RandomWord;
               If Result then
                  Buffer := Format('Word %s was found',[RandomWord]);

               CLoseKEy;
            end else begin
               OpenKey('\Software\MyApplication\RandomWord',True);
               WriteString('Value',RandomWord);
               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 ;-)
Avatar of computerprogramer
computerprogramer

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?
ASKER CERTIFIED SOLUTION
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

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
Thanks Mate!
Glad to have helped you :)

F68 ;-)