Board index » delphi » Registry question

Registry question

Every time i make to GetKeyNames(strings: TStrings) my program crashes.
Here's a piece of code that does'nt work, could someone tell me what I'm
doing wrong... Any help would be really appreciated!

function DSRegServeurSynove.listeInstances():TStringList;
var
   chaines : TStrings;
   liste: TStringList;
   registre : TRegistry;
   i: integer;
begin
     registre := TRegistry.Create;
     registre.RootKey := HKEY_LOCAL_MACHINE;
     registre.OpenKey('SOFTWARE',false);
     registre.GetKeyNames(chaines);      // crashes here, why ???

     for i:=0 to chaines.count do
     begin
          liste.add(chaines[i]);
     end;
     registre.Free;
     result := liste;
end;

 

Re:Registry question


Try:

chaines:=tstrings.create;

in your form.create method and make chaines a global variable.

Eric...

Quote
Martin Anctil wrote in message <6cmvqe$r9...@news.quebectel.com>...
>Every time i make to GetKeyNames(strings: TStrings) my program crashes.
>Here's a piece of code that does'nt work, could someone tell me what I'm
>doing wrong... Any help would be really appreciated!

>function DSRegServeurSynove.listeInstances():TStringList;
>var
>   chaines : TStrings;
>   liste: TStringList;
>   registre : TRegistry;
>   i: integer;
>begin
>     registre := TRegistry.Create;
>     registre.RootKey := HKEY_LOCAL_MACHINE;
>     registre.OpenKey('SOFTWARE',false);
>     registre.GetKeyNames(chaines);      // crashes here, why ???

>     for i:=0 to chaines.count do
>     begin
>          liste.add(chaines[i]);
>     end;
>     registre.Free;
>     result := liste;
>end;

Re:Registry question


On Sat, 21 Feb 1998 11:34:00 -0500, "Martin Anctil"

Quote
<ancti...@globetrotter.qc.ca> wrote:
>Every time i make to GetKeyNames(strings: TStrings) my program crashes.
>Here's a piece of code that does'nt work, could someone tell me what I'm
>doing wrong... Any help would be really appreciated!

GetKeyNames expects you to have created the object to store the data
into

i.e.

var
lStrings : tStringList;
begin

lStrings := tStringList.Create;
fReg.GetKeynames( lStrings );
.
.
.

lStrings.Free;

Re:Registry question


On Sat, 21 Feb 1998 11:34:00 -0500, "Martin Anctil"

Quote
<ancti...@globetrotter.qc.ca> wrote:

Corretc your for loop with

     for i:=0 to chaines.count-1 do

and try.

Quote
>Every time i make to GetKeyNames(strings: TStrings) my program crashes.
>Here's a piece of code that does'nt work, could someone tell me what I'm
>doing wrong... Any help would be really appreciated!

>function DSRegServeurSynove.listeInstances():TStringList;

----------------------------------------------
 Andrea Pizzeghella
 Home Page : http://webcom.global-inf.com/kiuan
 email : mo...@tin.it
         ki...@relay.global-inf.com
 ----------------------------------------------

Other Threads