Autor Beitrag
bruce185
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Fr 21.10.05 01:09 
hi, also ich habe ein problem, und zwar möchte ich Prüfen ob ein Registry Eintrag besteht, aber es zeigt mir an das der eintrag nicht besteht, obwohl der eintrag vorhanden ist, hier mal mein code:


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
procedure TForm3.FormCreate(Sender: TObject);
  var reg: TRegistry;
    text, Texte: string;
begin
  reg := TRegistry.Create;
  reg.RootKey := HKEY_CURRENT_USER;
  reg.OpenKey('Software\BBHB\Softs', true);


  if not Reg.KeyExists('Software\BBHB\Softs') then
  begin
    Application.MessageBox('Key existiert nicht!', 'Meldung!', MB_OK);
    regist.WriteString('Minuten', '50');
  end
  else
  begin
    Application.MessageBox('Key existiert!', 'Meldung!', MB_OK);
  end;

  text := Reg.ReadString(Texte);
  Label1.Caption := 'schön dich zu sehen, ' + text;

  reg.Free;
end;


wisst ihr vieleicht was ich da falsch gemacht habe, für die hilfe bin ich euch sehr dankbar :(

Andreas


Moderiert von user profile iconChristian S.: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Sa 22.10.2005 um 12:52
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Fr 21.10.05 11:02 
Hallo,

mit der Anweisung reg.OpenKey('Software\BBHB\Softs', true); wird der Reg-Schlüssel erzeugt (siehe u.a. Delphi-Hilfe).

Um festzustellen, ob der RegKey existiert musst Du folgendermassen vorgehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
  reg:=TRegistry.Create;  
  with reg do
  try
    RootKey:=HKEY_CURRENT_USER;  
    if not KeyExists('Software\BBHB\Softs') then  
    begin  
      Application.MessageBox('Key existiert nicht!', 'Meldung!', MB_OK);  
      OpenKey('Software\BBHB\Softs', true);  
      WriteString('Minuten', '50');  
    end  
    else  
    begin  
      Application.MessageBox('Key existiert!', 'Meldung!', MB_OK);  
    end;  
    ...
    ...
  finally
    Free;  
  end; // try, with

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
flieger-michl
Hält's aus hier
Beiträge: 14

W2K, Linux
D5, FPC
BeitragVerfasst: Fr 21.10.05 12:24 
Hallo,

das Problem ist, daß Du hier relative Pfade verwendest.

Der Befehl

ausblenden Delphi-Quelltext
1:
if OpenKey('Software\BBHB\Softs', True);					


öffnet den angegebenen Schlüssel und legt ihn notfalls an, falls er nicht existiert.

Du befindest Dich dann bereits in diesem Schlüssel und die Abfrage

if KeyExists('Software\BBHB\Softs') liefert false. Wohingegen
if KeyExists('\Software\BBHB\Softs') True liefert!

Gruß
Michl
bruce185 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Fr 21.10.05 20:46 
vielen dank für die hilfe, genau das hat mir gefehlt, "OpenKey", vielen dank :D

Andreas