Autor Beitrag
ChaseX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Do 30.11.06 14:21 
Also mein Problem:
Ich habe ein Programm, dass beim Start überprüfen soll, ob ein bestimmter Key mit bestimmten Wert existiert.
Dieser Key sollte in CURRENT_USER liegen. wenn er nicht existiert, soll er ein anderes Form öffnen(kein problem) und wenn doch, dann überprüfen ob noch ein weiterer Key existiert.
Das Problem ist, dass ich das mit dem auslesen und schreiben nicht vernünftig hinbekomme..
Ich müsste ja in CURRENT_USER/Software einen Ordner und einen Eintrag mit bestimmten Wert erstellen(das passiert im 2ten Form), also irgendwas mit write.. und dann da halt auch noch auslesen, was dann ja wahrscheinlich kein problem mehr ist..
Vielen Dank im Vorraus


Moderiert von user profile iconGausi: Topic aus Sonstiges (Delphi) verschoben am Do 30.11.2006 um 14:23
Moderiert von user profile iconChristian S.: Topic aus Windows API verschoben am Do 30.11.2006 um 16:53
Danny W.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Do 30.11.06 14:34 
ja, schön.

Und wo liegt das Problem? Kannst du uns evtl. deinen Quelltext zeigen, von dem was du bis jetzt hast?

mfG,
Danny

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"
ChaseX Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Do 30.11.06 15:10 
Text wäre der hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
With TRegistry.Create do
  begin
    RootKey:=hkey_current_user;
    OpenKey('Software\X\', false);
    if not ValueExists('Go') then
      begin
      Application.terminate;
      end;
  end;

und
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
begin
reg.Rootkey := HKEY_CURRENT_USER;
reg.OpenKey('SOFTWARE\X', true);
reg.WriteBool('A',True);
reg.CloseKey;
reg.Free;
end;
DaKirsche
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

Win XP Pro, SuSe Linux 7.3 - 10.2, Win 2k3 Server, Win 2000, Win NT 4.0
Delphi 2006 Pro, Java, HTML, SQL, PHP, CSS
BeitragVerfasst: Do 30.11.06 15:10 
suche doch mal nach "Arbeiten in der Registry" oder so....

da findest du sowas, wie

writekey und so...

_________________
Die simpelsten Fehler sind meist die Schwersten...
Danny W.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Do 30.11.06 15:17 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
With TRegistry.Create do
  begin
    RootKey:=hkey_current_user;
    OpenKey('Software\X\', false);
    if not ValueExists('Go') then
      begin
      Application.terminate;
      end;
  end;


das sieht mir nicht ganz richtig aus ^^..folglich wären die anderen elemente ja

TRegistry.Create.RootKey und TRegistry.Create.OpenKey

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Do 30.11.06 15:19 
user profile iconMantis1987 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
With TRegistry.Create do
  begin
    RootKey:=hkey_current_user;
    OpenKey('Software\X\', false);
    if not ValueExists('Go') then
      begin
      Application.terminate;
      end;
  end;


das sieht mir nicht ganz richtig aus ^^..folglich wären die anderen elemente ja

TRegistry.Create.RootKey und TRegistry.Create.OpenKey


Nein, Registry.Create erzeugt ein temporäres Objekt, das dann an dieser Stelle steht. ;)

MfG
freak

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Do 30.11.06 15:23 
Grüß dich Chase ;)

Versuch es doch einfach mal mit eine '\' vor dem 'Software' in OpenKey...

momentan versuchst du nämlich den Key HKEY_CURRENT_USERSoftware zu öffnen und den gibt es eben nicht ;)
Danny W.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Do 30.11.06 15:27 
user profile iconfreak4fun hat folgendes geschrieben:
user profile iconMantis1987 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
With TRegistry.Create do
  begin
    RootKey:=hkey_current_user;
    OpenKey('Software\X\', false);
    if not ValueExists('Go') then
      begin
      Application.terminate;
      end;
  end;


das sieht mir nicht ganz richtig aus ^^..folglich wären die anderen elemente ja

TRegistry.Create.RootKey und TRegistry.Create.OpenKey


Nein, Registry.Create erzeugt ein temporäres Objekt, das dann an dieser Stelle steht. ;)

MfG
freak


Das versteh ich grade nicht.

müsste es nicht Tregistry.create; heißen?
dann kommen doch sachen wie
Tregistry.writekey('bla');

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Do 30.11.06 15:51 
@user profile iconMantis1987 simple Sache... mit

ausblenden Delphi-Quelltext
1:
2:
3:
  with TRegistry.Create do begin

  end;


hast du ein temporäres objekt erschaffen. dass quasi nur in dem bereich zwischen begin und end existiert (Wichtig ist aber, dass du es noch vor dem end freigibst. du hast quasi ein unbenanntes objekt, auf dessen eigenschaften du direkt zugreifen kannst. gerade bei stringlisten ist sowas immer wieder recht praktisch ;)

und nochmal @user profile iconChaseX

WICHTIG: DENKE AN DAS FREIGEBEN VON DEINEM OBJEKT

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
with TRegistry.Create do begin  
  try
    RootKey := HKEY_Current_User;  
    OpenKey('\Software\X\', False);  
    if not ValueExists('Go') then begin  
      Application.terminate;  
    end;  
  finally
    Free;
  end; 
end;
ChaseX Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Do 30.11.06 16:46 
hmh okay ich probier es mal aus;)
Danke schonmal, hab nur momentan n bisschen Probleme mit dem compilieren. Der meint da wär ein Zugriffsfehler.
Mal gucken:)
Edit:
Es kommt eine Fehlermeldung: 'Im Projekt Project1.exe ist eine Exception der Klasse EAccessViolation aufgetreten.[..]'
Das kann aber doch nicht daran liegen dass ich nicht als Admin angemeldet bin oder?Weil auf Current_user kann doch eigentlich jeder User zugreifen?!Oder geht das mit eingeschränkten Rechten doch nicht?
Wennich das Programm mit F7 oder F8 ausführen will zeigt er mir komischerweise nur die folgenden Stellen an:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
begin
  Application.Initialize;
  Application.Title := 'ProgName';
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Fr 01.12.06 14:04 
nein, es kann(sollte) nicht daran liegen, dass du kein admin bist...

vielleicht solltest du etwas mehr code posten? an welcher stelle kommt denn der fehler bei dir? evt. im FormCreate?

C.
ChaseX Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Fr 01.12.06 15:42 
Ja wie gesagt, es kommt die Fehlermeldung und dann zeigt er mir Application.CreateForm(TForm2, Form2)
markiert an..
ChaseX Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Sa 02.12.06 18:15 
hmmm schön dass das grade jetzt verschoben wurde...:/
ChaseX Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Mo 04.12.06 14:00 
Warum konnten mir im anderen Unterforum mehr dabei helfen??danke fürs verschieben..-.-
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Mo 04.12.06 14:07 
sers,

also, wenn er dir auf das CreateForm springt, solltest du dir noch einmal das FormCreate anschauen. Am besten schaust du mal in beide Formulare rein.

Wie es scheint, hast du genau da den Fehler. Greifst du vielleicht in Form1.FormCreate schon auf Werte von Form2 zu?

Gruss,
C.
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Mo 04.12.06 14:29 
Ich arbeite lieber mit TRegIniFile statt mit TRegistry. ;)

MfG
freak

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
Popov
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1655
Erhaltene Danke: 13

WinXP Prof.
Bei Kleinigkeiten D3Pro, bei größeren Sachen D6Pro oder D7
BeitragVerfasst: Mo 04.12.06 14:36 
Eine wichtige Frage! Wieso bestehst du unbedingt auf TRegistry?

Bei TRegIniFile sieht das so aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
uses
  Registry;

function ReadIniString(RegFile, Section, Ident, Default: String): String;
begin
  with TRegIniFile.Create(RegFile) do 
  try
    Result := ReadString(Section, Ident, Default)
  finally Free end;
end;

procedure TForm1.Button1Click(Sender: TObject);
const
  ERROR = '#ERROR#';
var
  FileName: String;
begin
  FileName := ExtractFileName(ParamStr(0));
  if ReadIniString(FileName, 'Section', 'Ident', ERROR) = ERROR then ... ;
end;


Hier prüfst du es zwar indirekt, aber mit viel weniger Arbeit;

Oder willst du es nicht indirekt?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure ReadIniSection(RegFile, Section: String; Strings: TStrings);
begin
  with TRegIniFile.Create(RegFile) do 
  try
    ReadSection(Section, Strings);
  finally Free end;
end;

function KeyTest(RegFile, Section, Key: String): Boolean;
var
  sl: TStringList;
begin
  sl := TStringList.Create;
  try
    ReadIniSection(RegFile, Section, sl);
    Result := sl.IndexOf(Key) > -1;
  finally
    sl.Free
  end;
end;


Ist zwar etwas mehr Code, aber weniger fehleranfällig.

//EDIT:

PS: Alles ungeprüft aus dem Kopf direkt in FireFox getippt. Es könnten Fehler vorkommen.

_________________
Popov
ChaseX Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Mo 04.12.06 16:05 
Weil ich mich mit TRegIniFile überhaupt net auskenne(selbst bei TRegistry ists sehr wenig).
Könntest du vielleicht mal mit '\\' oder sonstwie dazu schreiben, was die einzelnen Befehle bewirken?
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Mo 04.12.06 16:28 
noch einmal hallo ChaseX

Ehrlich: Technisch gesehen macht es kaum einen Unterschied, ob du auf TRegIniFile oder auf TRegistry zurückgreifen willst. Die von Popov verwendeten Befehle kannst du doch auch in der Delphi Hilfe nachlesen. Das sind absolute Basisc's.

Ich denke auch, dass der Wechsel von TRegistry nach TRegIniFile nichts mit deinem Fehler zu tun haben wird.

Poste doch mal bitte deine "FormCreate"s und was sonst damit noch zu tun haben könnte.

C.
NTM
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 120

Win XP
2005 Prof
BeitragVerfasst: Mo 04.12.06 16:35 
schau doch mal hier www.dsdt.info/tutorials/ado/