[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

error msg when reading data from registry

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

873 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