Solved

Writing to the Registery

Posted on 2004-09-23
7
243 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 12

Expert Comment

by:Ivanov_G
ID: 12140646
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12140649
0
 
LVL 22

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 22

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 22

Expert Comment

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

F68 ;-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 227
Adoquery sql  left join does not work 25 121
Dynamically Created Query 3 81
SQL Server Express automatically execute SQL or SP 8 69
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

752 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