Autor Beitrag
Christian V.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Mo 21.02.05 16:01 
Hallo, gleich am Start meines Programms greife ich auf die Registry zu, dann kommt die Fehlermeldung: "Zugriffsverletzung bei der Adresse 00426BBA". Im weiteren Verlauf des Programms ,öchte ich einen String in die Registry schreiben, dann kommt diese Fehlermeldung:"Zugriffsverletzung bei der Adresse 00426D55".
Weiss jemand den fehler?
Hier mein Code:
ausblenden volle Höhe 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:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
unit pswd;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,Registry;

type
  TForm1 = class(TForm)
    OK: TButton;
    pswd1: TLabeledEdit;
    pswd2: TLabeledEdit;
    procedure OKClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  reg:TRegistry;
  zwischen,fertig:int64;
  anfang,versch:string;
implementation

uses main;

{$R *.dfm}

procedure TForm1.OKClick(Sender: TObject);
begin
if pswd2.Visible=true then begin
   if pswd1.Text=pswd2.Text then begin
      reg.OpenKey('\SOFTWARE\TopSecur',false);
      reg.WriteString('pwd',pswd1.Text);
      Form2.show;
      Form1.Visible:=false;
   end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
reg.RootKey:=HKEY_LOCAL_MACHINE;
if reg.KeyExists('\SOFTWARE\TopSecur') then begin
   pswd2.Visible:=false;
end
else
reg.CreateKey('\SOFTWARE\TopSecur');

end;


end.

Ich freue mich auf Antworten
Invulnerabilis
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Mo 21.02.05 16:05 
Du musst reg erst erzeugen:
ausblenden Delphi-Quelltext
1:
reg := TREgistry.Create;					

und natürlich nach Gebrauch wieder freigeben:
ausblenden Delphi-Quelltext
1:
reg.Free;					


Gruß,
raziel

_________________
JSXGraph
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 21.02.05 16:05 
Ja, ich weiß deinen fehler.
Du hast zwar reg definiert, aber noch nicht erzeugt.
ausblenden Delphi-Quelltext
1:
reg := TRegistry.Create;					

Muss noch irgendwo stehen.
Und dann auch noch:
ausblenden Delphi-Quelltext
1:
reg.Free;					


//Edit:
Mist. Raziel war schneller.
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Mo 21.02.05 16:07 
Danke, aber wo genau muss das stehen?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 21.02.05 16:08 
Das create, bevor du reg benutzt und das free, wenn du mit deinen Aktionen fertig bist.
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Mo 21.02.05 16:10 
Das Erzeugen muss vor dem Zugriff auf die Registry über reg stehen (also am besten in deinem Code am Anfang von FormCreate
Das Freigeben der Instanz würde ich im OnClose-Ereignis aufrufen, da es scheinbar im Verlauf des Programms immer wieder gebraucht werden kann.

//Edit: Diesmal war ich zu langsam :D

_________________
JSXGraph


Zuletzt bearbeitet von raziel am Mo 21.02.05 16:10, insgesamt 1-mal bearbeitet
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Mo 21.02.05 16:10 
ich hab reg:=TRegistry.create jezt bei OnCreate sthen und reg.free bei onClose ist das richtig so?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 21.02.05 16:11 
jep.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 21.02.05 16:12 
Und warum ist das ganze global?
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Mo 21.02.05 16:16 
Danke, habe nun keine Fehlermeldungen mehr.