Solved

Writing to the Registery

Posted on 2004-09-23
7
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 12140662
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:computerprogramer
ID: 12141162
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 23

Accepted Solution

by:
Ferruccio Accalai earned 50 total points
ID: 12141260
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
ID: 12141317
Thanks Mate!
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 12141321
Glad to have helped you :)

F68 ;-)
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month6 days, 10 hours left to enroll

634 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