Autor Beitrag
elduchte
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: So 18.06.06 13:55 
Hallo,

heute ist der Tag der Exceptions..... nur warum, das verstehe ich nicht...

Ich habe 2 Formulare: Form1 und Form2
auf Form1 sind 3 Checkboxen platziert.

Nun klicke ich auf einen Button:

ausblenden Delphi-Quelltext
1:
Form2.ShowModal;					


Im FormCreate-Ereignis der Form2:

ausblenden Delphi-Quelltext
1:
2:
3:
  If Frm1.Checkbox1.Checked = True then ...
  If Frm1_Checkbox2.Checked = True then ...
  If Frm1_Checkbox3.Checked = True then ...


Die Unit zur Form1 steht unter Uses in der Form2.

Ich versteh die Welt nicht mehr, warum bekomme ich eine Exception der Klasse EAccessViolation?

Vielleicht hat ja jemand einen Tipp für mich ....Vielen Dank dafür....
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 18.06.06 14:03 
Wo bekommst du die Exception?

Gruß alias5000

PS.: ich verweise auf meine Signatur

_________________
Programmers never die, they just GOSUB without RETURN
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 14:09 
Hast du die Form instantiiert? Nur Einbinden der Unit reicht nicht.
BTW.
ausblenden Delphi-Quelltext
1:
If Frm1.Checkbox1.Checked  then ...					

reicht.

@alias5000: Gruß über den Neckar

_________________
Markus Kinzler.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 18.06.06 14:18 
@Markus: Gruß zurück :wink:
Jetzt weiß ich auch endlich etwas g'scheits was ich bei "Wohnort" eintragen kann :D

_________________
Programmers never die, they just GOSUB without RETURN
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 14:21 
Soll ich dann bei mir "Diese Seite ..." schreiben? :D

_________________
Markus Kinzler.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 18.06.06 14:22 
why not? :mrgreen:



<<break>>

Back2Topic

_________________
Programmers never die, they just GOSUB without RETURN
elduchte Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: So 18.06.06 14:30 
Hallo,

@Alias5000:
die Exception bekomme ich direkt bei der IF-Anweisung....

@mkinzler: auch wenn ich

ausblenden Delphi-Quelltext
1:
If Frm1.Checkbox1.Checked  then ...					


schreibe, bekomme ich die Exception .... und by the way Instantiiert? Was verstehst du darunter?

Nur warum ?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 14:39 
Poste mal den Code, es sieht so aus, ob Frm1 nil ist, das keine Instanz der Klasse referenziert.

_________________
Markus Kinzler.
elduchte Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: So 18.06.06 14:44 
Hi,

super, vielen dank für deine Hilfe, doch welchen Code meintest du? Den gesamten Code der Form1 und den gesamten Code der Form2 ?? Wird wohl ein bißchen viel werden....
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: So 18.06.06 14:47 
wo rufst du Form2.ShowModal auf? Nicht bei Form1 oder?

_________________
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.
elduchte Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: So 18.06.06 14:52 
Hallo,

doch, beim OnClick-Ereignis (der Button ist auf Frm1) wird Frm2 aufgerufen.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 18.06.06 14:54 
Kannst Du den genauen Source dieses Events mal posten?

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 14:57 
Kreuzreferenzen sollte man vermeiden. Spendiere der Form2 einen weiteren Konstruktor, dem du die den Zustand der 3 Checkboxen übergibst.

_________________
Markus Kinzler.
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: So 18.06.06 15:02 
Hallo
Ich würde die If Abfragen ins OnShow von Form2 packen.
Gruß

_________________
[b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]
elduchte Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: So 18.06.06 15:04 
Klar, mache ich, bin ja dankbar für jede Hilfe.

Also hier der Code des Formulars Eingabe (auf dem sich der Button befindet):
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:
unit Unit_Eingabe;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Buttons, ComCtrls;
....
var
  Frm_Eingabe: TFrm_Eingabe;
  
implementation

uses Unit_Ergebnis,
     Unit_KW,
     Unit_Definitionen,
     Unit_Algorithmen,
     Unit_AusgabeKW,
     Unit_Fortschritt;
...
procedure TFrm_Eingabe.BTN_BerechnenClick(Sender: TObject);
begin
  If CB_Start.Text = '' then
     MessageDlg('Bitte Startknoten eingeben !', mtError, [mbOK], 0)
     else
  If CB_Ziel.Text = '' then
     MessageDlg('Bitte Zielknoten eingeben !', mtError, [mbOK], 0)
     else
  If (CheckB_Dijkstra.Checked = False) and
     (CheckB_Bellmann.Checked = False) and
     (CheckB_Ford.Checked = False) then
        MessageDlg('Bitte einen Algorithmus auswählen !', mtError, [mbOK], 0)
     else
  If ED_Durchlauf.Text = '0' then
     MessageDlg('Anzahl der Durchläufe darf nicht 0 sein !', mtError, [mbOK], 0)
     else
      begin
      Frm_Fortschritt.ShowModal; 
      Frm_Ergebnis := TFrm_Ergebnis.Create(Self);
      Frm_Haupt.Hauptmenue.Items[2].Items[0].Checked := False;
      Frm_Haupt.Hauptmenue.Items[2].Items[1].Enabled := True;
      Frm_Haupt.Hauptmenue.Items[2].Items[1].Checked := True;
      end;
end;


und hier der Code des Formulars Fortschritt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TFrm_Fortschritt.FormCreate(Sender: TObject);

begin
  If Frm_Eingabe.CheckB_Dijkstra.Checked then
  begin
   StartZeitMessen();
   Dijkstra();
   StoppZeitMessen();
   Zeit_Dijkstra := verbrauchteZeit();
  end;
  ....
  If Frm_Eingabe.CheckB_Bellmann.Checked then .....
end;


So, ich hoffe, das hilft Euch und mir weiter...
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: So 18.06.06 15:04 
user profile iconmkinzler hat folgendes geschrieben:
Kreuzreferenzen sollte man vermeiden. Spendiere der Form2 einen weiteren Konstruktor, dem du die den Zustand der 3 Checkboxen übergibst.

Warum?

_________________
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.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 18.06.06 15:10 
In Zeile 38 scheint es mir, als ob FormFortschritt nicht initialisiert ist ...

1. Wird sie über die Projekt-Datei mit Application.CreateForm initialisiert?
2. Was sagt Delphi als Wert der Variablen an dieser Stelle (vor dem Aufruf an?

Voraussichtliche Lösung:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
With TFormFortschritt.Create(Self) do
Begin
    try
        //Status der Checkboxes setzen)
        If showmodal THen
            //Bearbeitung der Eingaben
    finally
        Free;
    end;
end;


Naja, oder sie einfach korrekt initialisieren, bevor man sie verwendet ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 15:11 
Zitat:
mkinzler hat folgendes geschrieben:
Kreuzreferenzen sollte man vermeiden. Spendiere der Form2 einen weiteren Konstruktor, dem du die den Zustand der 3 Checkboxen übergibst.

Warum?

Er ruft die 2.Form aus der 1. auf (Uses Unit2 in Unit1) und versucht im Konstruktor dieser auf Form1 zuzugreifen ( Uses Unit1 in Unit2). Soetwas sollte man vermeiden.


Außerdem kommt es darauf an, wann das 2. Formular erzeugt wird.

@elduchte: Das was dein Konstruktor macht, hat nichts mit einem Konstruktor zu tun. Ich würde diesen Code in eigene Methoden auslagern.

Zudem wird innerhalb des Codes keine Instanz erzeugt.

_________________
Markus Kinzler.
elduchte Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: So 18.06.06 15:20 
Hallo Leute,

vielen Dank für die zahlreichen Antworten, ich sehe, ich muss noch viel lernen, aber das macht ja nix...

@BenBE:

Zitat:

In Zeile 38 scheint es mir, als ob FormFortschritt nicht initialisiert ist ...

1. Wird sie über die Projekt-Datei mit Application.CreateForm initialisiert?
2. Was sagt Delphi als Wert der Variablen an dieser Stelle (vor dem Aufruf an?


Zu 1. Wie mache ich das, bzw wo?
Zu 2. Die Checkboxen sind alle TRUE beim Starten des Programms

Zitat:
Naja, oder sie einfach korrekt initialisieren, bevor man sie verwendet


Wie mache ich das? Die sind doch schon TRUE ....

@mkinzler:
ich wollte eigentlich vermeiden, noch mehr Variablen ins Spiel zu bringen, aber wenn alles nichts hilft, muss es wohl sein. Aber vielleicht klappt ja auch der Tipp von BenBe.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 18.06.06 15:26 
Zitat:
Zu 1. Wie mache ich das, bzw wo?
Projekt->Quelltext anzeigen.
Zitat:
Aber vielleicht klappt ja auch der Tipp von BenBe.

der geht eigentlich in die selbe Richtung. Da dein Formular entweder nicht oder automatsich erzeugt wurde, bekommst du im Konstruktor nie die richtigen Werte des anderen Formulars bzw. der Konstruktor wird nie aufgerufen. Du mußt also die automatische Erzeugung des Formulars deaktivieren und die manuell kurz vor der Benutzung erzeugen.

_________________
Markus Kinzler.