Autor Beitrag
JustusJonas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Mo 01.09.03 09:32 
Hallo Leute,

wenn jemand mein Programm beenden möchte, wird eine zweite Form geöffnet. Dort muss der Benutzer ein Passwort eingeben. Mit der richtigen Eingabe werden beide Forms geschlossen. Bei falscher Eingabe soll die Form2 wieder geschlossen werden, aber die 1. Form soll wieder aktiv werden.
Leider funktioniert das nicht!

Wenn ich Form2.Close mache, dann schließen beide Formulare, obwohl eigentlich Form1 mein Hauptformular ist.
Bei Form2.Hide und Form1.Focus oder so funktioniert gar nicht! :(

Hat jemand eine Idee?

Greetz
rochus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416

Win XP Prof, Fedora Core 4, SuSE 7.0
D7 Ent, D2005 Pers
BeitragVerfasst: Mo 01.09.03 09:36 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.FormClose(Sender: TObject;
  var Action: TCloseAction);
var
  test : string;
begin
  InputQuery('Passwort','Passwort:',test);
  if test <> '12345' then
    Action := caNone;
end;


EDIT: Natürlich sollte das Passwort so niemals in einem Programm stehen!
Chilloutfuchs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Win XP Pro
Delphi 7
BeitragVerfasst: Mo 01.09.03 10:33 
@rochus: Das wäre zwar eine Möglichkeit, er wollte es aber glaube ich so:

Code Für Form1:


ausblenden volle Höhe 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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);  // Close-Button
begin
  Form2.Show;
  Form1.Hide;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Form2.Edit1.Text <> 'pass' then Action := caNone;
  Form2.Show;
  Form1.Hide;
end;

end.



Code für Form2:

ausblenden volle Höhe 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:
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  IF Edit1.Text = 'pass' THEN
  BEGIN
    Form1.Close;
    Form2.Close;
  END
  ELSE
  BEGIN
    Form1.Show;
    Form2.Close;
  END;
end;
end.

_________________
Leben und leben lassen....
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Mo 01.09.03 11:14 
Danke erst Mal für eure Antworten!

Leider habe ich wenn ich euren Code benutze das Problem, dass ich die Form2 nicht Modal anzeigen lassen kann. Das wäre jedoch aber nötig. Denn wenn ich es nur modal anzeigen lasse, kann man ja trotzdem außerhalb des Programms hantieren. Genau das wollte ich ja verhindern!

Greetz
Chilloutfuchs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Win XP Pro
Delphi 7
BeitragVerfasst: Mo 01.09.03 11:22 
Sehe ich das richtig?

Du willst verhindern das der user dein program ohne passwort beendet, und du willst nicht das der user irgendwas anderes machen kann, als in deine program zu klicken? Er soll nicht z.b. den Taskmanager öffnen dürfen?

_________________
Leben und leben lassen....
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Mo 01.09.03 11:29 
Ok....fangen wir von ganz von vorne an! (hätte ich von Anfang an machen sollen).

Wir haben an unserer Zentrale ein Info-Terminal stehen, auf dem die wartenden Kunden ein wenig auf unserer eigenen Homepage surfen können. Leider wird dies aber viel zu oft benutzt um eMails bei GMX abzurufen (als Beispiel jetzt) oder Pornoseiten zu besuchen. Mein Programm beinhaltet einen TWebBrowser. Mit diesem Browser soll man nur auf unserer eigenen Seite surfen können.
Ich bin schon so weit, dass ein "ALT" + "F4" abgefangen wird. Genau in diesem Moment soll dann die Passwortabfrage erfolgen.

STRG, ALT + ENTF ist ok...ich denke es ist OK, wenn diese Tastenkombi noch erlaubt ist. Schließlich ist ja Windows extra so programmiert worden! ;)

Es geht also rein darum, dass der User beim Beenden des Progamms (außer durch den TaskManager) in eine zweite form kommt, in der er in ein Edit-Feld das Passwort eingeben muss. Ist dieses Passwort nicht korreckt, kommt er zurück in die Form1 und kann weitersurfen. Ist das Passwort richtig wird beides geschlossen.

Mit Form1.Show und Form2.Hide ist die Form2 dann zwar wirklich weg, aber ich kann in meinem WebBrowser in Form1 keine Links mehr anklicken!

Greetz
Chilloutfuchs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Win XP Pro
Delphi 7
BeitragVerfasst: Mo 01.09.03 12:00 
Also ich weiss nicht was du falsch machst! Ich habe in meinem Test Program jetzt auch noch in Form1 einen browser eingebaut, und ich kann Links klicken, wenn ich wieder zurück ins Form1 komme. Der Browser hat sich sogar gemerkt, auf welcher Seite ich war!

Hier, lade dir doch mal mein Projekt runter:

test:temp@chilloutfu...ftp.org/passwort.rar

_________________
Leben und leben lassen....
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Mo 01.09.03 12:26 
Ja....funktioniert bei mir ja auch.

Das Problem ist nur, dass ich die Form2 gerne Modal anzeigen würde. Wenn ich das aber mache, dann funktioniert es nicht mehr!
Ich möchte ja verhindern, dass jemand - der das Kennwort nicht hat - aus dem Programm rauskommt. Wenn das Form2 ganz normal geöffnet wird, dann kann man ja trotzdem alle möglichen Dinge auf dem Desktop machen und anklicken usw.!

Greetz
Chilloutfuchs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Win XP Pro
Delphi 7
BeitragVerfasst: Mo 01.09.03 12:30 
...und wie wäre es wenn du form2.formstyle := fsStayonTop machst, und form1 nicht schließt?

_________________
Leben und leben lassen....
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Mo 01.09.03 13:19 
Diese Eigenschaft "FormStyle" kannte ich ja noch gar nicht!

Damit habe ich's jetzt hingekriegt....vielen Dank!

Greetz
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 01.09.03 14:15 
Hallo!

Auch wenn das Problem schon gelöst ist, möchte ich doch noch eine Möglichkeit zeigen, wie es mit ShowModal geht. In Form1 steht folgender Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  form2.showmodal;
  CanClose := form2.modalresult > 0;
end;

Und die Passwortabfrage sieht dann so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm2.Button1Click(Sender: TObject);
begin
  self.Close;
end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if edit1.text = 'mein_passwort' then
  modalresult := 1 else modalresult := -1;
end;

Auf Form2 befindet sich nur ein Editfeld fürs Passwort und ein Button mit dem der Nutzer die Passworteingabe bestätigt.

MfG
Peter

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".