Autor Beitrag
Florian.K
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win Xp Prof. & SP 2
Delphi 10 Lite
BeitragVerfasst: So 19.03.06 14:59 
Hi, benutze diesen Code um mein Programm zu schützen, bei der Eingabe test : Meldung falsches Passwort. Wie gelange ich in mein Form :/ ?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.FormCreate(Sender: TObject);
begin
  if InputBox('Passwort','Bitte das Passwort eingeben','') <> 'test' then
  begin
    Showmessage('Falsches Passwort!');
    Application.Terminate;
  end;
  Application.Initialize;
  Application.CreateForm(TForm3, Form3);
  Application.Run;
end;
end.


Das wärs auch heut an Threads gewesen ;)

Moderiert von user profile iconChristian S.: Beiträge zusammengefasst
Florian.K Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win Xp Prof. & SP 2
Delphi 10 Lite
BeitragVerfasst: So 19.03.06 18:54 
Wie keiner weiß die Antwort was ich tun muss damit mein Form sich öffnet :/.
Sprich: Passworteingabe z.b 123 und die Form erscheint


edit: habs schon : D


Zuletzt bearbeitet von Florian.K am So 19.03.06 19:01, insgesamt 1-mal bearbeitet
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: So 19.03.06 18:58 
sei nicht so ungeduldig.

hier die Antwort:
ausblenden Delphi-Quelltext
1:
2:
3:
  Application.Initialize;  
  Application.CreateForm(TForm3, Form3);  
  Application.Run;


kannst du nicht in einer Form aufrufen die in deiner Anwendung steckt.

gehe wie folgt vor:
lösch das.

statt Terminate (das ist die harte Methode) schreibe z.b.

ausblenden Delphi-Quelltext
1:
PostMessage(Self.Handle,wm_Close,0,0);					


grez
msch

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: So 19.03.06 19:00 
machs so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.FormActivate(Sender: TObject);
begin
  if InputBox('Passwort','Bitte das Passwort eingeben','') <> 'test' then
  begin
    Showmessage('Falsches Passwort!');
    form1.Close;
  end;
end;


verschiebs in die formaktivate ;)
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: So 19.03.06 19:02 
Form3.Show; wär ne Möglichkeit
//Edit: huch.. irgendwie quatsch, was ich da geschrieben hab :roll:


Zuletzt bearbeitet von Danniolo am So 19.03.06 19:03, insgesamt 1-mal bearbeitet
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: So 19.03.06 19:02 
damit jedes mal, wenn die FOrm aktiviert wird, ein Passwort abgefragt wird.
:-?

msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: So 19.03.06 19:06 
hier die "clevere" Lösung:

Du schickst eine Nachricht an dein eigenes Programm, welches dann die Passwortabfrage
durchführt. Hat den Vorteil, es funktioniert immer unabhängig aus welchem Kontext.

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:
const
  wm_Password = wm_user  +1; // eigene Nachricht

type TMyForm = Class(TForm)
   // hier das übliche geraffe
   public
      procedure WMPassword(var Msg:TMessage);Message wm_Password; // Nachrichtenhandler
   ...
end;

procedure TMyForm.OnCreate;
begin
 ...
  PostMessage(Self.Handle,wm_Password,0,0); // Nachricht ans eigene Fenster
 ...
end;

procedure TMyForm.WMPassword;
begin
  if ImputBox(...) // rest spar ich mir 
  then // Fehler
    PostMessage(Self.Handle,wm_Close,0,0);
  else
    // weiter in Program
end;

grez
msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
MrSaint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1033
Erhaltene Danke: 1

WinXP Pro SP2
Delphi 6 Prof.
BeitragVerfasst: So 19.03.06 19:14 
Wenn man das PostMessage(Self.Handle,wm_Password,0,0); // Nachricht ans eigene Fenster aber wieder im OnCreate macht, kommt die Abfrage jedes mal, wenn ich das Forumlar erzeuge (kann ja durchaus öfters vorkommen!). Keine Ahnung, ob man das PostMessage vor das Application.Run in der dpr machen kann und ob das dann funktioniert (also machen kann man es schon, nur ob das funktioniert?) Ich würde es wahrscheinlich so machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1); 
  if InputBox('Passwort','Bitte das Passwort eingeben','') <> 'test' then
    MessageDlg('Falsches Passwort!', mtWarning, [mbOK], 0)
  else
    Application.Run;
end.



MrSaint

_________________
"people knew how to write small, efficient programs [...], a skill that has subsequently been lost"
Andrew S. Tanenbaum - Modern Operating Systems
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Di 21.03.06 15:59 
Zitat:
Wenn man das PostMessage(Self.Handle,wm_Password,0,0); // Nachricht ans eigene Fenster aber wieder im OnCreate macht, kommt die Abfrage jedes mal, wenn ich das Forumlar erzeuge (kann ja durchaus öfters vorkommen!).


wohl kaum, wenn das Fenster=MainForm der Applikation ist.

grez
msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?