Autor Beitrag
chickenfigt1989
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 444
Erhaltene Danke: 2



BeitragVerfasst: Sa 13.08.11 10:17 
Hallo
Hab folgenden Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm2.AccountSystemClient1LoggedIn(
  AUserLevel: TAccountSystemUserLevel; AExpired: Boolean);
begin
Form1.Caption := 'Farm-House Manager Herzlich Willkommen ' + Form2.AccountSystemClient1.UserName;
if AExpired then
  begin
    ShowMessage('Dein Benutzerkonto ist abgelaufen!');
    Application.Terminate;
  end
  else if AUserLevel = aulDisabled then
  begin
    ShowMessage('Dein Benutzerkonto wurde deaktiviert!');
    Application.Terminate;
  end;
  SaveLoginData;

  Form1.Button1.Enabled:=(AUserLevel = aulEnabled) or (AUserLevel = aulAdmin);

end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
program Project1;

uses
  Forms, Controls,
  Unit2 in 'Unit2.pas' {Form2},
  Unit1 in 'Unit1.pas' {Form1};


{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm2, Form2);
IF Form2.ShowModal=mrOK Then Begin
Form2.Free;
Application.CreateForm(TForm1, Form1);
  Application.Run;



wirft mir immer einen fehler aus

Wahrscheinlich weil Form 1 noch gar nicht zu diesen zeitpunkt existiert.
Wie kann ich das beheben?
lg
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 12:58 
Pack den Status z.B. in eine Property, die du dann im Projektquelltext abfragen und nach dem Erzeugen an das zweite Formular weitergeben kannst.
chickenfigt1989 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 444
Erhaltene Danke: 2



BeitragVerfasst: Sa 13.08.11 13:44 
Und wie mach ich das?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 13:58 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
type
  TSecondForm = class...
  private
    FUserLevel: TUserLevel;
  public
    property UserLevel: TAccountSystemUserLevel read FUserLevel;
  end;

procedure TSecondForm.AccountSystemClient1LoggedIn(
  AUserLevel: TAccountSystemUserLevel; AExpired: Boolean);
begin
  ...
  FUserLevel := AUserLevel;
end;
Jetzt kannst du von außen auf die Property UserLevel zugreifen.
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Sa 13.08.11 17:59 
Irre ich mich oder ist Application.Terminate; nicht eig. sehr böse?

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 18:01 
Nein, es beendet die Anwendung, das ist schon richtig. (Denkst du vielleicht gerade an Halt? ;-))

Allerdings ist es an der Stelle natürlich absolut unnötig, weil schlicht der weitere Start unterbunden werden muss.
chickenfigt1989 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 444
Erhaltene Danke: 2



BeitragVerfasst: Sa 13.08.11 20:39 
Hallo,

Wieso sagt er mir immer
ausblenden Delphi-Quelltext
1:
[Error] Unit2.pas(28): Undeclared identifier: 'UserLevel'					

lg
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 20:41 
Da nur du deinen Quelltext siehst, kannst das im Moment nur du herausfinden... :roll:
Dude566
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1592
Erhaltene Danke: 79

W8, W7 (Chrome, FF, IE)
Delphi XE2 Pro, Eclipse Juno, VS2012
BeitragVerfasst: Sa 13.08.11 20:41 
Weißt du denn, was dir die Fehlermeldung sagt? ;)

_________________
Es gibt 10 Gruppen von Menschen: diejenigen, die das Binärsystem verstehen, und die anderen.
chickenfigt1989 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 444
Erhaltene Danke: 2



BeitragVerfasst: Sa 13.08.11 20:56 
Das UserLevel' nicht deklariert ist.

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:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
unit Unit2;

interface

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

type

  TForm2 = class(TForm)
    Label1: TLabel;
    edtUsername: TEdit;
    Label2: TLabel;
    edtPassword: TEdit;
    Button1: TButton;
    Button2: TButton;
    AccountSystemClient1: TAccountSystemClient;
    chkAutoLogin: TCheckBox;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure SaveLoginData;
    procedure LoadLoginData;
    procedure AccountSystemClient1LoggedIn(
      AUserLevel: TAccountSystemUserLevel; AExpired: Boolean);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
       FUserLevel: TUserLevel;
  public
    { Public declarations }
     property UserLevel: TAccountSystemUserLevel read FUserLevel;
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
begin
LoadLoginData;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
if AccountSystemClient1.Login(edtUsername.Text, edtPassword.Text) then
  begin
    ModalResult := mrOK;
    
      end
  else
    ShowMessage('Falsche Benutzerdaten!');
end;

procedure TForm2.AccountSystemClient1LoggedIn(
  AUserLevel: TAccountSystemUserLevel; AExpired: Boolean);
begin
Form1.Caption := 'Farm-House Manager Herzlich Willkommen ' + Form2.AccountSystemClient1.UserName;
if AExpired then
  begin
    ShowMessage('Dein Benutzerkonto ist abgelaufen!');
    Application.Terminate;
  end
  else if AUserLevel = aulDisabled then
  begin
    ShowMessage('Dein Benutzerkonto wurde deaktiviert!');
    Application.Terminate;
  end;
  SaveLoginData;

  Form1.Button1.Enabled:=(AUserLevel = aulEnabled) or (AUserLevel = aulAdmin);
  FUserLevel := AUserLevel;

end;

procedure TForm2.SaveLoginData;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('Software\' + Application.Title + ' ' + ExtractFileName(Application.ExeName), True) then
    begin
      Reg.WriteString('UserName', edtUsername.Text);
      Reg.WriteString('Password', edtPassword.Text);
      Reg.WriteBool('AutoLogin', chkAutoLogin.Checked);
      Reg.CloseKey;
    end;
  finally
    Reg.Free;
  end;
end;

procedure TForm2.LoadLoginData;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('Software\' + Application.Title + ' ' + ExtractFileName(Application.ExeName), False) then
    begin
      edtUsername.Text := Reg.ReadString('UserName');
      edtPassword.Text := Reg.ReadString('Password');
      chkAutoLogin.Checked := Reg.ReadBool('AutoLogin');
      Reg.CloseKey;
    end;
  finally
    Reg.Free;
  end;
end;

end.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 20:59 
Ja, da habe ich mich verschrieben. Aber das hättest du bei dem Fehler doch wohl sehen können, dass dein Typ anders heißt...
user profile iconchickenfigt1989 hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
  private
    { Private declarations }
       FUserLevel: TUserLevel;
  public
    { Public declarations }
     property UserLevel: TAccountSystemUserLevel read FUserLevel;
  end;
chickenfigt1989 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 444
Erhaltene Danke: 2



BeitragVerfasst: Sa 13.08.11 21:00 
Oh da hab ich selber nich drauf geschaut hab üebrsehn das meine Komponente anders heißt
chickenfigt1989 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 444
Erhaltene Danke: 2



BeitragVerfasst: Sa 13.08.11 21:06 
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:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
unit Unit2;

interface

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

type

  TForm2 = class(TForm)
    Label1: TLabel;
    edtUsername: TEdit;
    Label2: TLabel;
    edtPassword: TEdit;
    Button1: TButton;
    Button2: TButton;
    AccountSystemClient1: TAccountSystemClient;
    chkAutoLogin: TCheckBox;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure SaveLoginData;
    procedure LoadLoginData;
    procedure AccountSystemClient1LoggedIn(
      AUserLevel: TAccountSystemUserLevel; AExpired: Boolean);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
       FUserLevel: TAccountSystemUserLevel;
  public
    { Public declarations }
     property UserLevel: TAccountSystemUserLevel read FUserLevel;
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
begin
LoadLoginData;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
if AccountSystemClient1.Login(edtUsername.Text, edtPassword.Text) then
  begin
    ModalResult := mrOK;
    
      end
  else
    ShowMessage('Falsche Benutzerdaten!');
end;

procedure TForm2.AccountSystemClient1LoggedIn(
  AUserLevel: TAccountSystemUserLevel; AExpired: Boolean);
begin
Form1.Caption := 'Farm-House Manager Herzlich Willkommen ' + Form2.AccountSystemClient1.UserName;
if AExpired then
  begin
    ShowMessage('Dein Benutzerkonto ist abgelaufen!');
    Application.Terminate;
  end
  else if AUserLevel = aulDisabled then
  begin
    ShowMessage('Dein Benutzerkonto wurde deaktiviert!');
    Application.Terminate;
  end;
  SaveLoginData;

  Form1.Button1.Enabled:=(FUserLevel = aulAdmin) or (FUserLevel = aulAdmin);


end;

procedure TForm2.SaveLoginData;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('Software\' + Application.Title + ' ' + ExtractFileName(Application.ExeName), True) then
    begin
      Reg.WriteString('UserName', edtUsername.Text);
      Reg.WriteString('Password', edtPassword.Text);
      Reg.WriteBool('AutoLogin', chkAutoLogin.Checked);
      Reg.CloseKey;
    end;
  finally
    Reg.Free;
  end;
end;

procedure TForm2.LoadLoginData;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('Software\' + Application.Title + ' ' + ExtractFileName(Application.ExeName), False) then
    begin
      edtUsername.Text := Reg.ReadString('UserName');
      edtPassword.Text := Reg.ReadString('Password');
      chkAutoLogin.Checked := Reg.ReadBool('AutoLogin');
      Reg.CloseKey;
    end;
  finally
    Reg.Free;
  end;
end;

end.


Was ist hier den noch Falsch?

Er wirft mir immer noch eine Fehlermeldung aus.

lg
glotzer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 393
Erhaltene Danke: 49

Win 7
Lazarus
BeitragVerfasst: Sa 13.08.11 21:07 
wie war das mit copy& paste?...

ach und:

Zitat:
Er wirft mir immer noch eine Fehlermeldung aus.

muss ja sehr toll sein, vieleicht solltest du ja schreiben WELCHE es ist?

_________________
ja, ich schreibe grundsätzlich alles klein und meine rechtschreibfehler sind absicht
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 21:12 
Auf den ersten Blick sehe ich ohne die Fehlermeldung zu kennen erst einmal nur, dass du FUserLevel benutzt, aber nie zuweist.
chickenfigt1989 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 444
Erhaltene Danke: 2



BeitragVerfasst: Sa 13.08.11 21:27 
Das hier kommt:
Einloggen, um Attachments anzusehen!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 21:29 
Weil du immer noch auf Form1 zugreifst statt nur den Status in FUserLevel zu packen und dann aus dem Projektquelltext heraus abzurufen...
chickenfigt1989 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 444
Erhaltene Danke: 2



BeitragVerfasst: Sa 13.08.11 21:38 
Ja aber wie mach ich das ich des ?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 21:44 
:roll:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
program Project1;

[...]

  Form2.UserLevel
chickenfigt1989 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 444
Erhaltene Danke: 2



BeitragVerfasst: Sa 13.08.11 21:48 
Und wo muss ich das hinmachen?