Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How can I save an array of strings into registry?

Posted on 2003-03-31
Medium Priority
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;
  Myreg : TRegistry;
  index : integer;
  Myreg := TRegistry.Create;
    with MyReg do
      if OpenKey('Key' + ProgramFileName, True) then
        WriteBinaryData('ScanSunmaster', 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

Question by:Binsky

Accepted Solution

billious earned 150 total points
ID: 8238219

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


Expert Comment

by:Greg Rowland
ID: 8238338
You could truncate the array into a string like

When reading parse each par of chars as hex values results in this array

or visa-versa..


Author Comment

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...


(Has anyone got other solutions as well?)
Industry Leaders: 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!


Expert Comment

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

Expert Comment

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

Author Comment

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,


Author Comment

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...


(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)

Expert Comment

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!



Author Comment

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)!


Featured Post

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.

Question has a verified solution.

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

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…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

571 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