?
Solved

error msg when reading data from registry

Posted on 2004-09-10
5
Medium Priority
?
248 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 90 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 60 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 90 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

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

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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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…
Suggested Courses
Course of the Month10 days, 9 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