Autor Beitrag
marvin190
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 55

Win XP, SuSe Linux 10.1
Delphi 3/5/2005 Personal; C++ Builder 6
BeitragVerfasst: Fr 08.12.06 20:54 
Hallo zusammen!

Folgendes Problem:
Wenn ich ein (Neben-)Formular mit dem Programm starte, funktioniert das, was im FormCreate steht: u.A. das hier

ausblenden Delphi-Quelltext
1:
Button1.Enabled := False;					


einwandfrei, wenn ich das Formular nun per TForm.Create(Owner) öffne, kommt eine Fehlermeldung (EAccessViolation).

Woran scheitert es?

Danke schonmal für eure Hilfe!

_________________
Mfg Marvin
Carpe Diem! - Genieße den Tag! - [gr. Horaz]
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 08.12.06 21:04 
Daran, dass beim FormCreate der Button noch nicht erstellt ist. Benutze daher OnShow oder OnActivate.


EDIT: Nach nochmaligem Durchlesen, bin ich nicht mehr so ganz sicher. Du erstellst ein Form zur Laufzeit? Wo hast du dann OnFormCreate zugewiesen und wo wird der Button erstellt?

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
marvin190 Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 55

Win XP, SuSe Linux 10.1
Delphi 3/5/2005 Personal; C++ Builder 6
BeitragVerfasst: Fr 08.12.06 21:11 
Das bringt leider auch nichts :-(

Der selbe Fehler kommt, egal ob das in OnCreate, OnShow oder unter OnActivate steht.

Aber ich konnte das Problem genauer einkreisen:
Wenn ich eine direkte Anweisung habe also z.B. "Label1.Caption := '';" funktioniert das, verweise ich allerdings auf eine andere Unit, wo z.B. sowas ausgeführt werden soll:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
[...]
with Form do
begin
  Edit1.Enabled := false;
[...]
end;


Dann tritt der Fehler auf, weil Form nil ist.

_________________
Mfg Marvin
Carpe Diem! - Genieße den Tag! - [gr. Horaz]
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Sa 09.12.06 09:15 
In welchem Kontext wird denn der Aufruf gemacht? Wird Form irgendwie als als Parameter übergeben? Wenn nicht kann es daran liegen das Form in der zweiten Unit nicht das Form der 1. Unit ist und noch nicht initialisiert wurde mit Form:=TForm.Create.
Ich nehme den weiten Fall an, da Du schreibst weil Form nil ist.
marvin190 Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 55

Win XP, SuSe Linux 10.1
Delphi 3/5/2005 Personal; C++ Builder 6
BeitragVerfasst: Sa 09.12.06 15:38 
Also der Kontext:

In ein der OnClick Methode eines TMainmenu steht diese Anweisung:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure THaupt.Datei_NeutralClick(Sender: TObject);
begin
  TNeutral.Create(HAUPT);
end;


Neutral ist das Formular, das aufgerufen werden soll und Haupt ist das, von dem aus es auferufen wird.

Ich vermute auch, dass es noch nicht initialisiert ist, aber wie kann ich das verhindern?

_________________
Mfg Marvin
Carpe Diem! - Genieße den Tag! - [gr. Horaz]
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 09.12.06 15:41 
Es fehlt die Instanzvariable##
ausblenden Delphi-Quelltext
1:
  Neutral := TNeutral.Create(self);					

_________________
Markus Kinzler.
marvin190 Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 55

Win XP, SuSe Linux 10.1
Delphi 3/5/2005 Personal; C++ Builder 6
BeitragVerfasst: Sa 09.12.06 15:47 
Funktioniert leider auch nicht :-(

Auch bei dieser Methode kommt der EAccesViolation Fehler...

_________________
Mfg Marvin
Carpe Diem! - Genieße den Tag! - [gr. Horaz]
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 09.12.06 16:03 
Zeig mal ein wenig mehr Code

_________________
Markus Kinzler.
marvin190 Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 55

Win XP, SuSe Linux 10.1
Delphi 3/5/2005 Personal; C++ Builder 6
BeitragVerfasst: Sa 09.12.06 16:12 
Alles kein Problem ;-)

Also das OnClick in dem Menü

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure THaupt.Datei_NeutralClick(Sender: TObject);
begin
  TNeutral.Create(self);
end;


Dann der FormCreate von Neutral

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TNeutral.FormCreate(Sender: TObject);
begin
  FehlerLabel.Caption := '';
  Zeichne.Enable(false);
end;


Das interessante dabei: Das FehlerLabel.Caption := ''; funktioniert!

Nun das was unter Zeichne.Enable passiert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TZeichnen.Enable(Direction: Boolean);
begin
  with Neutral do
  begin
    EDecAnzAtomMitOH.Enabled := direction;
    EDecAnzOH.Enabled := direction;
    [und noch mehr davon]
  end;
end;


Dort tritt in der 1. Zeile der Fehler auf, wenn ich nun im Debugger nachsehe, welche Eigenschaften Neutral hat, steht da "nil", von daher ist es ja logisch, dass da ein Fehler kommt, aber was ich nicht verstehe ist, warum dann bei dem obigen FehlerLabel.Caption := ''; nicht gemeldet wird.

Die Unit (uNeutral) ist ganz normal vereinbart:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
implementation

uses
  uNeutral;


Wenn noch irgendein Code für die Fehlerfindung hilfreich ist, sagt bescheid!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 09.12.06 16:29 
Die Erzeugung ist immer noch falsch! Du erzeugst eien Istanz, auf welche man dann nicht mehr zugreifen kann.

_________________
Markus Kinzler.
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Sa 09.12.06 16:31 
Probier es mal so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TNeutral.FormCreate(Sender: TObject);
begin
  FehlerLabel.Caption := '';
  Zeichne.Enable(false,self);//Self ist das Form
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TZeichnen.Enable(Direction: Boolean;aform:TNeutral);
begin
  with aform do
  begin
    EDecAnzAtomMitOH.Enabled := direction;
    EDecAnzOH.Enabled := direction;
    [und noch mehr davon]
  end;
end;


oder Du vereinbarst ist TZeichen ein Parant vom Typ TNeutral und übergibst Dein Form als Parent nach TZeichen
In Tzeichen muss "Neutral" nicht das selbe "Neutral" wie Thaupt sein.

Frage: Wird in TZeichen.Enable nur Werte gesetzt die auch schon beim Aufruf von TNeutral.OnCreate bekannt sind? Wenn ja definiere doch in Tneutral eine Methode welche die Werte setzt. Dann hast Du nicht das Problem mit der Referenz.
marvin190 Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 55

Win XP, SuSe Linux 10.1
Delphi 3/5/2005 Personal; C++ Builder 6
BeitragVerfasst: Sa 09.12.06 16:42 
Wenn ich die aForm und self hinzufüge gehts!

Danke für eure Antworten!

EDIT:

Aber ein anderes Problem taucht auf:
Was ím FormCreate steht funktioniert, aber wenn ich nun auf irgendeine der Komponenten auf dem Formular zugreife, kommt wieder der EAccessViolationError...

EDIT2:

Weil Neutral bei dem Zugriff (der nicht mehr im FormCreate steht) immernoch nil ist.

_________________
Mfg Marvin
Carpe Diem! - Genieße den Tag! - [gr. Horaz]
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Sa 09.12.06 19:27 
Jetzt mal mehrere Fragen:
1) Wo wird Neutral definiert? Also ist Neutral global oder lokal?
2) Wo wird Neutral intialiesiert?
3) Wo steht etwas in der Richtung Neutral.Free;
4) sind diese Komponenten extra Klassen?
5) werden allen Klassen die Neutral verwenden auch wirklich eine Referenz auf Neutral übergeben?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 09.12.06 19:28 

_________________
Markus Kinzler.