Autor Beitrag
rubooo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

WIN XP
Delphi 2005 Prof
BeitragVerfasst: Mi 21.06.06 12:47 
warum komm denn hier eine Zugriffsverletzung. ist es anderst möglich die Form zu verstecken?

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:
unit telnet;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, IdBaseComponent, IdComponent, IdTCPServer, IdTelnetServer,
  IdAntiFreezeBase, IdAntiFreeze, idContext;

type
  TForm1 = class(TForm)
    IdTelnetServer: TIdTelnetServer;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure IdTelnetServerExecute(AContext: TIdContext);
    procedure IdTelnetServerAuthentication(AContext: TIdContext;
      const AUsername, APassword: stringvar AAuthenticated: Boolean);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;


implementation

{$R *.dfm}

procedure TForm1.IdTelnetServerAuthentication(AContext: TIdContext;
  const AUsername, APassword: stringvar AAuthenticated: Boolean);

label richtig,falsch;
begin

AAuthenticated:=false;
if AUsername='test' then
  begin
    goto richtig;
  end
  else
    acontext.Connection.IOHandler.WriteLn('Anmeldung nicht erfolgreich.');
    acontext.Connection.Disconnect;
    richtig:
  if APassword='123' then
    begin
      acontext.Connection.IOHandler.WriteLn('Anmeldung erfolgreich.');
      acontext.Connection.IOHandler.WriteLn('');
      AAuthenticated:=True;
    end;

end;

procedure TForm1.IdTelnetServerExecute(AContext: TIdContext);
var befehl: String;
begin
with acontext.Connection.IOHandler do
  begin
    befehl:=ReadLn;


  end;

end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  idTelnetServer.Active := False;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowWindow(Application.MainForm.Handle, SW_HIDE);
end;

end.



user defined image


Moderiert von user profile iconraziel: Topic aus Internet / Netzwerk verschoben am Mi 21.06.2006 um 15:36
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Mi 21.06.06 13:35 
Sofern MainForm noch nicht erstellt wurde kannst du in Form1 darauf nicht zugreifen.

Application.MainForm.Handle <- crashed

Erstell Mainform halt vor Form1. dann sollte es gehen (steht in der Project.dpr)


Zum Codestil: Bitte vermeide die Benutzung von Labels (richtig/falsch) :)

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
rubooo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

WIN XP
Delphi 2005 Prof
BeitragVerfasst: Mi 21.06.06 14:32 
sorry aber wie muss ich das machen erstellen?!!? keine ahnung wie du das meinst. kannst du mir evtl. ein codebsp. geben?

und warum keine labels benutzen. was an stelle von diesen sollte man besser benutzen ?
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 21.06.06 15:05 
Du versuchst auf die Mainform zuzugreifen, bevor sie überhaupt erstellt (created) wurde. Da diese beim Zugriff also nicht vorhanden ist, gibts eine Zugriffsverletzung. Schreib einfach die Zeile aus OnCreate in OnShow.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
rubooo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

WIN XP
Delphi 2005 Prof
BeitragVerfasst: Mi 21.06.06 15:44 
wenn ichs in onShow einsetz verschwindet Sie aber garnicht....
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 21.06.06 15:46 
setz es einfach bei OnActivate ein :P
fidionael
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 232

Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
BeitragVerfasst: Mi 21.06.06 16:29 
user profile iconrubooo hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
if AUsername='test' then
  begin
    goto richtig;
  end
  else
    acontext.Connection.IOHandler.WriteLn('Anmeldung nicht erfolgreich.');
    acontext.Connection.Disconnect;
    richtig:
  if APassword='123' then
    begin
      acontext.Connection.IOHandler.WriteLn('Anmeldung erfolgreich.');
      acontext.Connection.IOHandler.WriteLn('');
      AAuthenticated:=True;
    end;


Wo ist denn das Problem mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if (AUsername='test'and (APassword='123'then
  {Anmeldung erfolgreich}
else
  {Anmeldung fehlgeschlagen}

Goto sollte man in Hochsprachen eigentlich nicht mehr benutzen - ist ein schlechter Programmierstil.
rubooo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

WIN XP
Delphi 2005 Prof
BeitragVerfasst: Mi 21.06.06 16:51 
mit OnActivate klappts auch nicht ! krieg ich auch ne fehlermeldung!


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

uses
  Forms,
  telnet in 'telnet.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.MainForm.Hide;
  Application.Run;
end.


und so passiert garnichts....

wo ist mein fehler?
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Mi 21.06.06 17:02 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
program telnet1;

uses
  Forms,
  telnet in 'telnet.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.ShowMainForm := False;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.


Versuchs damit ;)

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
rubooo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

WIN XP
Delphi 2005 Prof
BeitragVerfasst: Mi 21.06.06 17:20 
JAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa :D :D :D :D :D :D :D

na endlich funzt des mal ^^ bin bald wahnsinnig geworden ! danke auch an alle anderen für Tipps :)