Solved

error msg when reading data from registry

Posted on 2004-09-10
5
242 Views
Last Modified: 2010-04-05
when i reading the data from the registry i got the following error: "EConvertError".

this code writes the data to registry:
procedure TForm1.FormDestroy(Sender: TObject);
var clbx: integer;
    buf: string;
begin
 with TRegistry.Create do begin
  RootKey := HKEY_CURRENT_USER;
  try
  if OpenKey('\Software\Test\', True) then begin
   for clbx := 0 to CheckListBox1.Items.Count - 1 do begin
    if CheckListBox1.Checked[clbx] = True then buf := buf + IntToStr(clbx) + ' ';
   end;
   WriteString('items', buf);
  end;
  finally
  CloseKey;
  Free;
  end;
 end;
end;

this code reads the data:
procedure TForm1.FormCreate(Sender: TObject);
var buf: string;
    intbuf: integer;
begin
 with TRegistry.Create do begin
  RootKey := HKEY_CURRENT_USER;
  try
  if OpenKey('\Software\Test\', false) then begin
    buf := ReadString('items');
    for intbuf := 0 to Length(buf) - 1 do begin
     if buf[intbuf] <> ' ' then CheckListBox1.Checked[StrToInt(buf[intbuf])] := True;
    end;
  end;
  finally
  CloseKey;
  Free;
  end;
 end;
end;

something is wrong with this code: "if buf[intbuf] <> ' ' then CheckListBox1.Checked[StrToInt(buf[intbuf])] := True;" ?
i use delphi 4.
0
Comment
Question by:din345
5 Comments
 
LVL 4

Accepted Solution

by:
LMuadDIb earned 30 total points
ID: 12029982
I usually use "0" or "1" to designate checked or not in checklists.
Here is the code.....

uses
   StrUtils;


procedure TForm1.FormDestroy(Sender: TObject);
var clbx: integer;
    buf: string;
begin
 with TRegistry.Create do begin
  RootKey := HKEY_CURRENT_USER;
  try
  if OpenKey('\Software\Test\', True) then begin
   for clbx := 0 to CheckListBox1.Items.Count - 1 do begin
    if CheckListBox1.Checked[clbx] = True then
      buf := buf + '1'
    else
      buf := buf + '0';
   end;
   WriteString('items', buf);
  end;
  finally
  CloseKey;
  Free;
  end;
 end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var buf: string;
    intbuf: integer;
begin
 with TRegistry.Create do begin
  RootKey := HKEY_CURRENT_USER;
  try
  if OpenKey('\Software\Test\', false) then begin
    buf := ReadString('items');
    for intbuf := 0 to Length(buf) - 1 do begin
     if midstr(buf,intbuf+1,1) <> '1' then
      CheckListBox1.Checked[intbuf] := False
     else
      CheckListBox1.Checked[intbuf] := True;
    end;
  end;
  finally
  CloseKey;
  Free;
  end;
 end;
end;


hope this helps
Frank
0
 

Assisted Solution

by:meadorj
meadorj earned 20 total points
ID: 12030133
You can use the strtointdef function and set the default number to -1.  That should solve the convert error.  What string value does the registry return when you try to read it?
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 12031308
try:

if buf[intbuf] <> ' ' then CheckListBox1.Checked[StrToIntDef(buf[intbuf], 0)] := True;
0
 
LVL 6

Assisted Solution

by:vadim_ti
vadim_ti earned 30 total points
ID: 12033312
buf is string, in your loop you need to use
    for intbuf := 1 to Length(buf)  do begin


    buf := ReadString('items');
    for intbuf := 0 to Length(buf) - 1 do begin
     if buf[intbuf] <> ' ' then CheckListBox1.Checked[StrToInt(buf[intbuf])] := True;
    end;


0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 12035264
vadim is right.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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