Solved

Writing to the Registery

Posted on 2004-09-23
7
237 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:computerprogramer
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
Comment Utility
0
 
LVL 12

Expert Comment

by:Ivanov_G
Comment Utility
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
Comment Utility
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 ;-)
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:computerprogramer
Comment Utility
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?
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 50 total points
Comment Utility
mmm...

What about this?

Function CheckRandomWord(RandomWord: STring;Restore: Boolean; var Buffer: String): Integer; //0 = Found, 1 = STored, 2 = Not Found;
var
reg: TRegistry;
begin
   Result := 2;
   Buffer := Format('Word %s was not found',[RandomWord]);
   Reg := TRegistry.Create;
   try
      with Reg do
         begin
            RootKEy := HKEY_LOCAL_MACHINE;
            If restore then DeleteKey('\Software\MyApplication\RandomWord');
            If KeyExists('\Software\MyApplication\RandomWord') then
            begin
               OpenKey('\Software\MyApplication\RandomWord',False);
               If ReadString('Value') = RandomWord then
                  begin
                     Result := 0;
                     Buffer := Format('Word %s was found',[RandomWord]);
                  end;
               CLoseKEy;
            end else begin
               Result := 1;
               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
   If CheckRandomWord(Edit1.Text,False,Msg) = 2 then
      If Messagedlg(Msg+'. Do you want to replace it?',mtConfirmation,[mbYes,mbNo],0) = idYes then
         CheckRandomWord(Edit1.text,True,Msg);
   ShowMessage(Msg);
end;
0
 

Author Comment

by:computerprogramer
Comment Utility
Thanks Mate!
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
Comment Utility
Glad to have helped you :)

F68 ;-)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 163
code issue 8 84
Printing problem 2 72
HTML text in the body of an email (delphi code) 12 71
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now