?
Solved

How can I save an array of strings into registry?

Posted on 2003-03-31
9
Medium Priority
?
271 Views
Last Modified: 2010-04-04
Hi there,

I'm trying to write an  array of strings into the registry, and thought that would be easy...But I'm not making it happen!

Does anyone have an easy solution to this problem?~


{Following code is already in use for saving data to registry : }
procedure TFormMain.SaveSetting;
var
  Myreg : TRegistry;
  index : integer;
begin
  Myreg := TRegistry.Create;
  try
    with MyReg do
    begin
      Rootkey := HKEY_CURRENT_USER;//HKEY_LOCAL_MACHINE;
      if OpenKey('Key' + ProgramFileName, True) then
      begin
        WriteBinaryData('ScanSunmaster', Registry_ScanSunmaster,
            Sizeof(Registry_ScanSunmaster));
        // I'm trying something like the two lines above, but now with an array of strings
        // The registry_scansunmaster is an array of booleans, which can be written to using binary data

           for index := 0 to 31 do
              WriteString('SerialCheckArray', Registry_SerialCheckArray[index]);

        // this was what I've tried, amongst other things...It just copies the value of
        // the arrayposition, and therefore keeps overwriting the line over and over...
        // the Registry_serialcheckarray is declared as array of strings, which I want copied to
        // registry (it needs to be saved for future use anyway...

I need this for a serial number detection procedure in my program, so all I actually want is to store an array of strings...I was trying to avoid writing to file, as I've already got a registry entry.

Could someone help me please?

Thanks in advance,

Robin Oudhuis

0
Comment
Question by:Binsky
[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
9 Comments
 
LVL 7

Accepted Solution

by:
billious earned 150 total points
ID: 8238219
try

            WriteString('SerialCheckArray'+inttostr(index), Registry_SerialCheckArray[index]);

...Bill
0
 
LVL 4

Expert Comment

by:Greg Rowland
ID: 8238338
You could truncate the array into a string like
 ‘415838344A48464E423639334E42444D4E’

When reading parse each par of chars as hex values results in this array
 ‘A,X,8,4,J,H,F,N,B,6,9,3,N,B,D,M,N’

or visa-versa..

0
 
LVL 1

Author Comment

by:Binsky
ID: 8238411
Thanks for a (very) quick reply!

I'm affraid I was looking for a slightly more "solid" solution... I mean, if it's possible to save a (sort of) array of binaries, why not an array of strings?

If no new/better answer's forthcoming, I'll give both your solutions a go...But your answer, Billious is probably easiest to use for me...(even though it does create a bit too many registry entries for me. (Eventually I will need to be able to store up to 255 "8-byte serial numbers converted to strings") I'll probably end up storing the bytes, and using a sort of separator in between serials.

I think both solutions have their ups and downs...

Binsky

(Has anyone got other solutions as well?)
0
Independent Software Vendors: 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!

 
LVL 9

Expert Comment

by:tkalchev
ID: 8238739
Why not to try to port your array of strings to TStringList type. Then use TStringList1.Text for reading and writing.
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8241144
hello Binsky, I don't quit get why you use Binary for strings? but there is a property in TString (and TStringList) called TStrings.CommaText which you might be able to use to read text in and out of the resgistry and get it into a StringList. OR you can use your own Array of strings to create a comma delimted string and put that into the registry. . .

for index := 0 to 31 do
             WriteString('SerialCheckArray', Registry_SerialCheckArray[index]);

does not work because it Overwrites the string each time

for index := 0 to 31 do
 Str1 := Str1+','+ Registry_SerialCheckArray[index]);

WriteString('SerialCheckArray', Str1);

or if all of your strings are 8 bytes (char) then you can leave out the commas
0
 
LVL 1

Author Comment

by:Binsky
ID: 8260451
Thanks for all the repsonses,

The only problem is, they were all good! But to make it easier on myself, I've stuck with Billious's easy solution. I now have many many registry entries containing the serial numbers...

Can anyone tell me if it's a problem (or just bad practise) to fill up the registry with a lot of values? I'd say it's no problem, as they're not loaded when windows starts up, and the data itself does not take too much space (a maximimum of 255 registry entries containing an 8-byte string, and the same again for backing up old values)

I'll close this question tomorrow, but would like an answer to the last question...

Thanks again,

Binsky
0
 
LVL 1

Author Comment

by:Binsky
ID: 8260483
A short message to Slick812 :

I didn't (and still don't) try to use a binary for storing strings, I added that part of the code because it looked like the thing to use for saving arrays of strings to the registry. I thought it would be possible to use the "same" commands to get the array saved. (using ReadString/WriteString instead of Readbinary/writebinary)

Now I know better...

It still is a shame it's not possible...

Binsky

(And I chose not to create one long string containing all data because it handles easier for me if I can read/write serial numbers to specific places (i.e. a different number for every key, that corresponds with the index of the array of strings I used in the first place)
0
 
LVL 7

Expert Comment

by:billious
ID: 8260724
If you need to save the data in the registry, what does it really matter? A minor adjustment may be a single, easy-to-locate change rather than read-everything, write-everything that you'd have to do if all of the data was in a single entry.

If you look at say Microsoft's entries, I'd suggest 'tis but a drop in the ocean!

...Bill


0
 
LVL 1

Author Comment

by:Binsky
ID: 8267168
You are quite right, Bill...

I just asked the registry question because some things are said to be "not done" (except if there is no other way) I just wanted to make sure...

Thanks for the help, all of you, the points go to Bill(ious)!

Robin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

765 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