Autor Beitrag
Hansi@OMG
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 304

Vista
Delphi 2006 Prof., Lazarus
BeitragVerfasst: Di 28.12.04 17:47 
Hallo, ich benutze folgenden Code:
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:
procedure checkmessages(empf:PCHAR);
var
 Form1:TForm1;
 myforms: array of TForm1;
 i:integer;
 user:tstringlist;
begin
//user wird von mir vorher gesetzt, dass ist aber hier uninteressant

setlength(myforms,user.count-1);

  for i:=0 to length(myforms) do begin
     Myforms[i]:=Tform1.create(application);
     myforms[i].Caption:='Session - '+user.Strings[i];
     myforms[i].empfaenger.Caption:=user.strings[i];
     myforms[i].absender.Caption:=empf;
     myforms[i].Timer1.Enabled:=true;

        myforms[i].Show;
  end;//Ende for forms

user.free;
end;


Ich rufe diesen Code aus einer DLL auf und habe ein Problem, ich weis nicht, wo ich schreiben soll, dass die erzeugten Formulare wieder freigegeben werden sollen, da diese nach Ende der Procedure noch da sein sollen. Momentan lass ich das einfach weg und es funktioniert auch so weit, bloß beim beenden des Programms kommen dann ein paar Fehler. Ein Beispiel: "Der Vorgang "read" konnte nicht auf dem Speicher durchgeführt werden."
Zur Info: In form1 befindet sich ein Timer, der regelmäßig einen httprequest über indy abschickt.

_________________
Who doesn't know the Micrsoft developer "Mahatma Fatal Error"?
sourcehunter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 482

Win XP | Suse 10.1
Delphi 2005 Pers.
BeitragVerfasst: Di 28.12.04 18:21 
Also ich denke, dass du eine Prozedur prauchst, in der du alle Forms freigibst. Diese rufst du dann einfach auf, wenn du die Forms nicht mehr brauchst, z.B. im OnDestroy von deinem Mainform.

_________________
Linux und OpenSource rulez!
Hansi@OMG Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 304

Vista
Delphi 2006 Prof., Lazarus
BeitragVerfasst: Di 28.12.04 18:30 
Das geht aber nicht, weil myforms kein globales array ist und ich weis nicht, wie ich sonst die forms ansprechen soll.

_________________
Who doesn't know the Micrsoft developer "Mahatma Fatal Error"?
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 28.12.04 18:32 
dan machs doch global !

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Hansi@OMG Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 304

Vista
Delphi 2006 Prof., Lazarus
BeitragVerfasst: Di 28.12.04 18:43 
Das hat das Problem leider auch nicht gelöst. Die Fehler sind zwar weniger geworden, es kommen aber immer noch 1 oder 2.

_________________
Who doesn't know the Micrsoft developer "Mahatma Fatal Error"?
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 28.12.04 19:04 
ja welche fehler kommen denn ?

_________________
In the beginning was the word.
And the word was content-type: text/plain.
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Di 28.12.04 19:19 
Hallo,

setz doch einfach das Ereignis OnClose und gib dort das Formular mit dem Parameter caFree frei!

Gruß Hape!

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
Hansi@OMG Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 304

Vista
Delphi 2006 Prof., Lazarus
BeitragVerfasst: Di 28.12.04 20:31 
Jetzt bekomme ich nur noch den Fehler:
"Die Ausnahme "Unbekannter Softwarefehler" (0x0eedfade) ist in der Anwendung an der Stelle 0x77e4d756 aufgetreten" und dann noch ein Runtimeerror.

_________________
Who doesn't know the Micrsoft developer "Mahatma Fatal Error"?
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Di 28.12.04 20:36 
vielleicht liegts ja auch an deinem user.free
Hansi@OMG Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 304

Vista
Delphi 2006 Prof., Lazarus
BeitragVerfasst: Di 28.12.04 20:39 
Wie das denn?

_________________
Who doesn't know the Micrsoft developer "Mahatma Fatal Error"?
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Di 28.12.04 20:41 
du gibst den user nicht in der selben prozedur frei als in der wo du ihn erstellst
das kann immer zu problemen führen

am besten testet du vor jedem create oder free ob das object NIL ist
Hansi@OMG Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 304

Vista
Delphi 2006 Prof., Lazarus
BeitragVerfasst: Di 28.12.04 20:43 
Ich erstell user schon in dieser Procedure, lies dir mal den Komment oben im Source durch. Dieses erstellen ist hier nicht relevant.

_________________
Who doesn't know the Micrsoft developer "Mahatma Fatal Error"?
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Di 28.12.04 20:44 
möglicherweise ist dein compiler da aber andrer meinung :evil:
Hansi@OMG Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 304

Vista
Delphi 2006 Prof., Lazarus
BeitragVerfasst: Di 28.12.04 20:47 
Nein, daran liegt es nicht, ich hab das auch schon mal durch einen integerwert ersetzt. Das hängt damit wirklich nicht zusammen und das war übrigens weder böse noch arogant gemeint. :wink:

_________________
Who doesn't know the Micrsoft developer "Mahatma Fatal Error"?
Grendel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 443

Gentoo Linux, MacOS X, Win 2000
D5 Ent, D7 Ent, Lazarus, Anjuta, MonoDevelop
BeitragVerfasst: Di 28.12.04 20:49 
retnyg hat folgendes geschrieben:
du gibst den user nicht in der selben prozedur frei als in der wo du ihn erstellst
das kann immer zu problemen führen

Stimmt nicht.
Es ist überhaupt kein Problem ein Objekt in einer anderen Prozedur frizugeben als der Erzeugenden.
Es kommt doch soundsooft vor, daß man ein Objekt im Constructor erzeugt und im Destructor wieder freigibt. Und auch sonst ist es aabsolut normal.

Bis neulich ...
Hansi@OMG Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 304

Vista
Delphi 2006 Prof., Lazarus
BeitragVerfasst: Di 28.12.04 20:53 
Ich hab das Problem leider immer noch nicht gelöst und jetzt ist auch noch ein EInvalidPointer dazugekommen, der auftritt, nachdem die Forms erstellt wurden. Wo kommt denn der schon wieder her ? :cry:

_________________
Who doesn't know the Micrsoft developer "Mahatma Fatal Error"?
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Di 28.12.04 20:55 
ok, aber die Anwendungsfehler kommen entweder durch nichtexistente objekte, die dein Programm ansprechen will oder durch bereits erstellte objekte, die dein Programm benutztz.
Also prüfst du am einfachsten immer bei einer derartigen Aktion ob das Objekt nil ist.

@grendel: bei oncreate und ondestroy is das kein problem, werden ja beide nur einmal aufgerufen. Üblicherweise werden Prozeduren und Funktionen aber öfter als einmal und von verschiedenen Stellen aus aufgerufen. sonst würde man den ganzen code in die onshow oder oncreate prozedur der form reinpacken...
Hansi@OMG Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 304

Vista
Delphi 2006 Prof., Lazarus
BeitragVerfasst: Di 28.12.04 20:58 
Und wann soll ich das prüfen? Der erste Fehler kommt nach dem Ende der for-Schleife, an der keine Anweisung ein Objekt anspricht. Und der zweite kommt beim beenden, in dem wieder nicht angesprochen wird.

_________________
Who doesn't know the Micrsoft developer "Mahatma Fatal Error"?
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Di 28.12.04 21:02 
jedesmal wenn du objekte erzeugst, freigibst oder ihnen werte zuweist.
Grendel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 443

Gentoo Linux, MacOS X, Win 2000
D5 Ent, D7 Ent, Lazarus, Anjuta, MonoDevelop
BeitragVerfasst: Di 28.12.04 21:04 
retnyg hat folgendes geschrieben:
@grendel: bei oncreate und ondestroy is das kein problem, werden ja beide nur einmal aufgerufen. Üblicherweise werden Prozeduren und Funktionen aber öfter als einmal und von verschiedenen Stellen aus aufgerufen. sonst würde man den ganzen code in die onshow oder oncreate prozedur der form reinpacken...

Ahh jetzt verstehe ich was Du meinst.
Wie oft eine Prozedur aufgerufen wird spielt keine Rolle. Das "Problem" ist, daß man ein Objekt nicht mehrfach freigeben kann/darf/muss.

Wenn ich innerhalb einer Prozedur zweimal "Objekt.Free();" aufrufe bekomme ich auch eine Zugriffsverletzung.
Der eine Lösungweg ist FreeAndNil() der andere saubere Programmierung.

Bis neulich ...