Autor Beitrag
einfach112
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

xp
del7
BeitragVerfasst: Di 14.09.04 20:22 
Hallo !
Also ich möchte gerne checken ob eine Internetverbindung besteht !
Das möchte ich aber auf eine ganz bestimmte art und weise machen !
und zwar sage ich meinem programm es soll eine meiner internetseiten aufrufen und schauen was auf der seite steht !
dies mache ich in einem intervall von 6 sekunden per timer !
das Problem ist das leider wenn keine verbindung besteht das programm einfach beendet wird !
doch meines wissens nach unterdrücke ich doch den fehler und starte einfach den timer wieder neu oder ?!
hier mal der quelltext !
Weis einer von euch wo hier ein fehler sein soll !?
Würde mich wie immer über gute antworten und Ideen freuen
thx cu
einfach112

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

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    IdHTTP1: TIdHTTP;
    Timer1: TTimer;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
timer1.Enabled :=true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
sTemp: string;
begin
Timer1.Enabled := False;
 try
sTemp:= IdHTTP1.Get('http://www.hallo-aachen.de/counter/actionv2.htm');
except
    on E: Exception do
    Timer1.Enabled := True;
    end;
if sTemp ='1' then label1.Visible :=true else application.Terminate;

 end;


end.

_________________
sorry bin noob !
FAlter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 192

Win XP Home
Turbo Delphi 2006 (Win32), C# (VS 2008 Prof.), Java (Eclipse), PHP
BeitragVerfasst: Di 14.09.04 20:35 
Mit application.Terminate Beendest du das Programm!!!

Das würde schon eher funktionieren (ungetestet):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Timer1Timer(Sender: TObject);  
var
  HasConnection: Boolean;
begin  
 try  
   HasConnection := idHTTP.Get('http://www.google.de/') <> '';  
  except  
    HasConnection := false;
  end;
  if HasConnection then
    label1.Show
  else
    Label1.Hide;
end;


Aber ich denke, es wäre besser, WIN.Funktionen zu nutzen oder einfach einen Suche in: Delphi-Forum, Delphi-Library PING zu senden.
einfach112 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

xp
del7
BeitragVerfasst: Di 14.09.04 20:41 
Titel: naja....
das terminate greift ja nur für den fall das dort nicht 1 kommt sondern irgendwas anderes z.B. 2 oder auch die 3 oder halt sonst was ! aber deine Idee werde ich auch direkt mal antesten thx !

_________________
sorry bin noob !
einfach112 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

xp
del7
BeitragVerfasst: Di 14.09.04 20:43 
Titel: wobei....
wobei mir dann gerade auffält das es mir leider nix bringt da ich nämlich nicht nur wissen muss ob ne verbindung zum netz besteht sondern was halt auch dort auf der seite ist ! also ich muss schon wissen ob 1 dort steht oder auch 2 damit ich später meinem programm somit auch sagen kann was es zu tun hat ?!

_________________
sorry bin noob !
einfach112 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

xp
del7
BeitragVerfasst: Di 14.09.04 20:55 
Titel: bei deiner version...
also deine version will auch net so ganz weil er dann sagt :
try
HasConnection := idHTTP.Get('http://www.google.de/') <> '';
=
[Fehler] Unit1.pas(41): Inkompatible Typen: 'Boolean' und 'String'

_________________
sorry bin noob !
Benutzername
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 210

Win XP Pro
Delphi 7 PE, D2005 Prof. SSL
BeitragVerfasst: Mi 15.09.04 11:01 
Dann probiers doch mal mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
If IdHTTP.Get('http://www.google.de/') <> '' then
 HasConnection:=true
else
 HasConnection:=false;
einfach112 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

xp
del7
BeitragVerfasst: Mi 15.09.04 11:57 
Titel: mmmhhh.....
naja danke für den tipp ! habe es dann mal so versucht :



aber leider meckert der dann dass .Get ein undifinierter bezeichner währe !?

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

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    IdHTTP1: TIdHTTP;
    Timer1: TTimer;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
timer1.Enabled :=true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
HasConnection: Boolean;
begin
Timer1.Enabled := False;
If IdHTTP.Get('http://www.google.de/') <> '' then
 HasConnection:=true
else
 HasConnection:=false;
 if hasConnection = true then label1.caption :='steht'
 else label1.Caption:= 'steht net';

end;
end.

_________________
sorry bin noob !
mirage228
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 338

Win 7 Prof.
Delphi 2005 Prof., Delphi 2010 Prof.
BeitragVerfasst: Mi 15.09.04 15:31 
Hi,

in deinem Quelltext steht idHTTP, die Komponente auf deiner Form heisst aber idHTTP1 - daran liegts ;)

mfG
mirage228

_________________
May the source be with you, stranger.
einfach112 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

xp
del7
BeitragVerfasst: Mi 15.09.04 16:00 
Titel: stimmt ! aber...
mmhh war ja klar so ein sau dummer fehler ! LOL !
aber leider bringt mich hier bisher keine sache wirklich weiter !
denn es besteht immer noch der fehler das wenn keine verbindung besteht bricht das programm ab ! es erscheint also kein verbindung steht nicht !
mmmhhh es muss doch irgendwie möglich sein das wenn der keine verbindung bekommt bzw. die aktion also nicht ausführen kann das der dann nicht einfach abbricht oder ?!
Suche also immer noch nach weiteren Ideen ! thx cu
einfach112

_________________
sorry bin noob !
einfach112 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

xp
del7
BeitragVerfasst: Mi 15.09.04 16:11 
Titel: ...
also fehlermeldung lautet immer was von :
exception der klasse EIdSocketError
daher gehe ich einfach doch davon aus der halt panick macht weil er die seite net auf bekommt !
kann man vieleicht irgendwo die fehlermeldungen unterdrücken oder so !?

_________________
sorry bin noob !
zed
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mi 15.09.04 16:13 
Versuch doch als erstes zu prüfen ob überhaupt eine Internet verbindung besteht und wenn ja dann führ dann dein Programm aus.

Ich hab hier mal was gefunden vieleicht hilft es ja weiter.
www.swissdelphicente.../showcode.php?id=342

With best regards
zed
einfach112 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

xp
del7
BeitragVerfasst: Mi 15.09.04 16:26 
Titel: .... mmhh
ne also hilft mir nicht wirklich weiter ! ich weis mittlerweile das es irgendwo estwas geben muss womit man sowas unterbinden kann ! also irgendwo ne einstellung das der dann nicht abbricht nur finde ich leider nicht wo ! ?
sonst noch einer ne idee ?!

_________________
sorry bin noob !
kachel81
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63



BeitragVerfasst: Mo 27.09.04 17:26 
Du machst doch nach dem try .. except Block

ausblenden Quelltext
1:
2:
3:
4:
if sTemp ='1' then 
  label1.Visible :=true 
else 
  application.Terminate;


Also wenn Deine Get-Abfrage schief läuft, weil keine Internet-Verbindung hergestellt werden konnte, dann schließt Du einfach. Das steht zumindest in dem Code.
Denn immer wenn nicht "1" zurückkommt...