Autor Beitrag
Force
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: Fr 10.03.06 23:14 
Hi!

Ich will ein kleines Programm schreiben, dass prüfen soll, on der Wert "Ieuse" in einem Schlüsseö existiert und wenn ja dann Form3 sichtbar macht - wisst ihr wo der Fehler liegt? Bei mir öffnet sich nämlich nie Form3...


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:
25:
26:
27:
28:
29:
30:
procedure TForm2.FormCreate(Sender: TObject);
var
  Reg: TRegistry;
  DataType: Cardinal;
  DataSize: Cardinal;
  Res: Integer;
  Str: String;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKeyReadOnly('\Software\Microsoft\Windows\CurrentVersion\Policies') then
    begin
    DataSize := 0;
    Res := RegQueryValueEx(
      Reg.CurrentKey,
      'Ieuse',
      nil,
      @DataType,
      nil,
      @DataSize);
    if DataType <> REG_SZ then begin
    SetLength(Str, DataSize - 1);
    if DataSize > 1 then form3.Visible:=true;
    end;
    end;
  finally
    Reg.Free;
  end;
  end;
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 11.03.06 05:18 
Welchen Wert hat denn DataSize und was gibt RegQueryValueEx zurück und was sagt GetLastError dazu?
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: Sa 11.03.06 10:32 
oha, der zeigt mit getlasterror an, dass Angeblich nicht genug Speicher zur Verfügung stehe?!?
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 11.03.06 18:00 
Bei DataSize = 0 auch kein wunder oder?

Zitat:

lpcbData
[in, out] Pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes. When the function returns, this variable contains the size of the data copied to lpData.


Zitat:

If the buffer specified by lpData parameter is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to by lpcbData. In this case, the contents of the lpData buffer are undefined.


Ich würde die Funktion zwei mal aufrufen. Beim ersten mal ermittelst du wie groß der Buffer sein muss und beim zweiten mal nimmst du dann die zurückgegebene Buffer Größe.

Und ich würde nicht VCL mit WinAPI mischen.
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: Sa 11.03.06 22:42 
Ich hab das jetzt so gemacht:

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:
procedure TForm2.FormCreate(Sender: TObject);
var
  Reg: TRegistry;
  DataType: Cardinal;
  DataSize: Cardinal;
  Res: Integer;
  Str: String;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKeyReadOnly('\Software\Microsoft\Windows\CurrentVersion\Policies') then begin
    DataSize := 0;
    Res := RegQueryValueEx(
      Reg.CurrentKey,
      'Ieuse',
      nil,
      @DataType,
      nil,
      @DataSize);
    if DataType <> REG_SZ then else
    begin
      SetLength(Str, DataSize - 1);
    if DataSize > 1 then begin
      Res := RegQueryValueEx(
        Reg.CurrentKey,
        'Ieuse',
        nil,
        @DataType,
        PByte(Str),
        @DataSize);
    end;
    if Str='no' then form3.Visible:=true
    end;
    end;
  finally
    Reg.Free;
  end;
  end;


Allerdings kommt, wenn der Wert wirklich 'no' ist, eine Fehlermeldung (acess Violation). Wisst ihr woran das liegt?
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 13.03.06 19:25 
IMHO existiert Form3 noch gar nicht, da erst Form1, dann Form2 und schließlich Form3 erstellt wird. Vertausche mal in der Projekt-Datei Form2 und Form3 und versuche es noch einmal.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: Mo 13.03.06 19:30 
Form1 gibt es in meinen Projekten nicht - der fängt immer mit Form2 an.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 14.03.06 17:02 
Das ändert nix an meiner Anweisung, Form2 und Form3 zu vertauschen.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: Di 14.03.06 17:59 
Ah, danke!!! Es funktioniert!!