Autor Beitrag
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mo 05.08.02 15:54 
Hallo !!!
ICh wollte mir ein kleines Proggi schreiben, dass für mich im Hintergrund immer Mails abfragt, und dann eine Meldung uasgibt, falls ich ein paar neue bekommen habe !!!

Aber das Programm bricht immer mit nem Ausnahmefehler ab !!! Warum ?? Ich benutze dazu die Indy 9 Kompos

Hier mal der Code:
ausblenden 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:
procedure TForm1.Timer1Timer(Sender: TObject);
var
  Ini: TIniFile;
begin
 try
    Ini:=TIniFile.Create('.\config.ini');
      finally
    Ini.Free;
  end;

      try
 if  IdPOP31.Connected  then idPOP31.Disconnect
  else
    begin

          Memo1.Lines.Add (Ini.ReadString('1','server','')+': Verbinde...');
          Application.ProcessMessages ;
          IdPop31.Host  := Ini.ReadString('1','server','');
          IdPop31.Username  := Ini.ReadString('1','name','');
          IdPOP31.Password := Ini.ReadString('1','pass','');
          IdPOP31.Connect ;
          Memo1.Lines.Add ('Sie haben '+IntToStr(IDPOP31.CheckMessages )+' neue Mails !');
          end;
  except
     Memo1.Lines.Add ('Verbindung fehlgeschlagen !!');
     end;
     end;




Danke schonaml im Vorraus !

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Mo 05.08.02 16:33 
matze hat folgendes geschrieben:
ausblenden Quelltext
1:
Ini:=TIniFile.Create('.\config.ini');					

Das geht so nicht. Das müsste so gehen:
ausblenden Quelltext
1:
Ini:=TIniFile.Create(ExtracFilePath(paramstr(0)) + 'config.ini');					


matze hat folgendes geschrieben:
ausblenden Quelltext
1:
2:
  finally
    Ini.Free;


Hier gibst du das INI-Object ja schon wieder Frei. Wie willst du dann später noch darauf zugreifen können?

Gruß
Klabautermann
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 06.08.02 11:07 
Oh da mit dem Ini.free ..... Hm tja muss ich mla testen !!! Aber das mit dem .\config.ini hat bisher in allen meinen proggis bestens geklappt !!!! (das hab ich nämlich auf dem alten delphiforum und wenn ich mich nicht täusche sogar von dir !!! )

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Di 06.08.02 13:17 
matze hat folgendes geschrieben:
Aber das mit dem .\config.ini hat bisher in allen meinen proggis bestens geklappt !!!! (das hab ich nämlich auf dem alten delphiforum und wenn ich mich nicht täusche sogar von dir !!! )


Ich glaube nicht, das du es von mir hast. Da viele Delphi Komandos nicht mit den Verzeichnissen . und .. umgehen können verwende ich diese nicht. Das tIniFile es kann überrascht micht.

Gruß
Klabautermann
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 06.08.02 13:52 
also nochmal danke für deine Hilfe !!! ich habe das proggi jetzt fertig (naja fast :lol: ) und es lag an dem ini.free; !!!! das mit .\config.ini funzt einwandfrei !!!!

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Di 06.08.02 13:59 
Bitte, bitte.

Diesesmal habe ich ja auch wieder was dazugelernt.

Ich hoffe du hast das ini.free nicht ersatzlos gestrichen. Du musst zu einem Spätern Zeitpunk schon noch aufrufen. Aber das nur zur sicherheit ;).

Gruß
Klabautermann
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 06.08.02 14:01 
nein nein !!! ich habe das ini.free; nur ganz unten an den code angehängt !!!

Wobei ich aber leider nicht genau weiss, was das ini.free eigendlich soll !!!

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Renegade
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 358

Win XP Pro, Win 7 Beta
BDS 2006
BeitragVerfasst: Di 06.08.02 15:35 
matze hat folgendes geschrieben:
Wobei ich aber leider nicht genau weiss, was das ini.free eigendlich soll !!!


Damit gibst du den speicher auf eine saubere Art und Weise wieder frei.

_________________
Sokrates (468 v.Chr. - 399 v.Chr.)
"Es ist keine Schande, nichts zu wissen, wohl aber, nichts lernen zu wollen."
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Di 06.08.02 15:36 
Hi,

generell musst du jedes Objekt (z.B. eines der Klasse tIniFile) erzeugen.
Dies machst du mit dem aufruf von Create. Beim erzeugen wird Speicher für das Objekt reserviert. Dieser Speicher muss auch wieder Freigegeben werden. Das machst du über den Free Befehl. Tust du es nicht erhälst du Speicherlecks. Es sind also Speicherbereiche belegt, auf die du nicht mehr sinvoll zugreifen kannst.
In einem solchen Fall kannst du noch drauf Hoffen das die Windows Speicherverwaltung hinter deinem Programm aufräumt und den "müll" den du hinterlassen hast wieder freigibt. Die Betonung liegt hierbei aber auf hoffen.
Nach dem aufruf vonn Free ist dein Objekt weg, du kannst also nicht mehr darauf zugreifen. Was passiert wenn du es trozdem versuchst hast du ja gemerkt ;).

Gruß
Klabautermann

PS: Für genauere Informationen solltest du dich mit dem Thema Objektorientierte Programmierung beschäftigen.
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 06.08.02 15:56 
aha !!! :idea:

danke !! 8)

_________________
In the beginning was the word.
And the word was content-type: text/plain.