Solved

error msg when reading data from registry

Posted on 2004-09-10
5
246 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
[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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

718 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