Autor Beitrag
THF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Fr 04.03.05 08:15 
Hallo,


wenn ich meinem Projekt ein weiteres Formular
hinzufüge und in ein RichEdit1 auf dem neuen Formular
vom Hauptformular etwas eintragen möchte ,erhalte ich
immer eine Zugriffsverletzung , obwohl ich unter USES
die neue Unit eingebunden habe .
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
implementation

uses NeueUnit;


procedure THauptprogramm.FormShow(Sender: TObject);
begin
NeuesFormular.RichEdit1.Lines.Add(((intToStr(XXX))+'-'+(intToStr(YYY))+'-'+(intToStr(ZZZ))));
end;

Gruß

THF


Moderiert von user profile iconGausi: Topic aus VCL (Visual Component Library) verschoben am Fr 04.03.2005 um 08:58
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Fr 04.03.05 08:19 
Vielleicht ist das "Neue Formular" noch nicht erstellt.

_________________
Ciao, Sprint.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 04.03.05 08:20 
Ist "NeuesFormular" denn schon erzeugt?
Dein FormShow wird, falls es die Hauptform ist, schon ziemlich "früh" beim Programmstart aufgerufen. Da kann es passieren, dass die andere Form noch gar nicht existiert.

EDIT:
Sprint macht seinem Namen wieder alle Ehre.
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Fr 04.03.05 08:27 
Hallo,
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
implementation  

 
uses NeueUnit;  

procedure THauptprogramm.FormShow(Sender: TObject);
var NeuesFormular :TNeuesFormular 
begin  
NeuesFormular := TNeuesFormular.Create(Application);

end; 
procedure THauptProgramm.Formactivate(Sender: TObject);
begin
NeuesFormular.RichEdit1.Lines.Add(((intToStr(XXX))+'-'+(intToStr(YYY))+'-'+(intToStr(ZZZ))));  
end;

Glaubt Ihr so ist es richtig ?

Gruß

THF
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 04.03.05 08:52 
Richtiger Ansatz.

Also ich mache das immer folgendermaßen:
Nur eine Form (Hauptform) wird automatisch erzeugt. Das muss natürlich in den Projekt-Optionen eingestellt werden.
Alle anderen Formen werden zur Laufzeit generiert, wenn diese benötigt werden.
Dabei gibt es auch bei mir durchaus mal Ausnahmen, sind aber selten.

Zu deinem Source:
Ich gehe mal davon aus, dass die Variable "NeuesFormular" in NeueUnit schon deklariert ist.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
implementation  

 
uses NeueUnit;  

procedure THauptprogramm.FormShow(Sender: TObject); // brauchst du nicht.
var NeuesFormular :TNeuesFormular 
begin  
NeuesFormular := TNeuesFormular.Create(Application);

end; 
procedure THauptProgramm.Formactivate(Sender: TObject);
begin
if not Assigend(NeuesFormular) then // dafür diese 2 Zeilen
  NeuesFormular := TNeuesFormular.Create(Application);
NeuesFormular.RichEdit1.Lines.Add(((intToStr(XXX))+'-'+(intToStr(YYY))+'-'+(intToStr(ZZZ))));  
end;

Du musst allerdings beachten, dass du "NeuesFormular" auf Nil setzt, wenn die NeuesFormular zerstört (z.B. bei Free oder Destroy) wird. Sonst funktioniert Assigned nicht.
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Sa 05.03.05 07:13 
hallo,

trotzdem steht jetzt Zugriffsverletzung,in der Zeile mit dem "RichEdit1"
weiß jemand was da falsch ist ?
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:
procedure THauptformular.FormActivate(Sender: TObject);
var Zuggenerator:TZuggenerator; 
begin
if not Assigned(Nebenformular) then
 Nebenformular := TNebenformular.Create(Application);

end;
Procedure THauptformular.Notiere(var von,nach,index :Integer );
begin
inc(Index);
Stapel[Ti,Index].von :=von;
Stapel[Ti,Index].nach :=nach;
Stapel[Ti,Index].Figur :=F_index ;
Nebenformular.RichEdit1.Lines.Add(Umrechnung((Stapel[Ti,Index].von),(Stapel[Ti,Index].nach),(Stapel[Ti,Index].Figur));
end;
function THauptformular.Umrechnung(var von,nach,F_index: Integer):String;
 var v1,n1,F1 : string ;
begin

v1:= Felder[von];
n1:= Felder[nach];

case F_Index of
2,8: F1:='A';
3,9: F1:='B';
4,10: F1:='C';
5,11: F1:='D';
6,12: F1:='E';
 end;
 result:= (F1+''+v1+'-'+n1);
end;

Gruß

THF
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 05.03.05 09:22 
Setz dort mal einen Haltepunkt und gehe mit F7 in die Unter-Routinen (z.B. Umrechnung). Vielleicht ist das Problem gar nicht das Fenster.
Wo rufst du übrigens die Prozedur Notiere auf? Falls du das vor dem FormActivate machst, gibt es natürlich auch ein Zugriffsverletzung, weil die NebenForm dann noch nicht existiert.
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Sa 05.03.05 12:23 
Hallo,
procedure "Notiere"rufe ich auch wieder über eine andere
"Procedure THauptformular.Berechne" auf ,
ob das Nebenformular da schon besteht weiß ich nicht.
Kann man das irgendwie absichern ?

Gruß
THF
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 05.03.05 12:53 
Prüfe wie im FormActivate mit Assigned, ob NebenForm schon erzeugt ist.
Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
if not Assigned(NebenForm) then
begin
  ShowMessage('NebenForm noch nicht erzeugt! Prozedur wird mit Exit abgeprochen!');
  Exit;
end;
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Sa 05.03.05 18:45 
Hallo jasocul,

jetzt habe ich es so gemacht wie Du geschrieben hast.
Jetzt erscheint dieselbe Fehlermeldung genau an derselben Stelle:

Zugriffsverletzung

Der Fehler muß also woanders liegen .
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Procedure THauptformular.Notiere(var von,nach,index :Integer );  
begin  
inc(Index);  
Stapel[Ti,Index].von :=von;  
Stapel[Ti,Index].nach :=nach;  
Stapel[Ti,Index].Figur :=F_index ;  
if not Assigned(Nebenformular) then
Nebenformular := TNebenformular.Create(Application);
Nebenformular.RichEdit1.Lines.Add(Umrechnung((Stapel[Ti,Index].von),(Stapel[Ti,Index].nach),(Stapel[Ti,Index].Figur));  
end;

Gruß

THF
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 05.03.05 20:08 
Darum habe ich ja geschrieben:
Zitat:
Setz dort mal einen Haltepunkt und gehe mit F7 in die Unter-Routinen (z.B. Umrechnung). Vielleicht ist das Problem gar nicht das Fenster.
Popov
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1655
Erhaltene Danke: 13

WinXP Prof.
Bei Kleinigkeiten D3Pro, bei größeren Sachen D6Pro oder D7
BeitragVerfasst: Sa 05.03.05 20:30 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
program Project1;

uses
  Forms,
  Unit1 in '\Unit1.pas' {Form1},
  Unit2 in '\Unit2.pas' {Form2},
  Unit3 in '\Unit3.pas' {Form3};

{$R *.RES}

begin
  BetaTest;
  
  Application.Initialize;
  Application.Title := 'Project1';
  Application.CreateForm(TForm1, Form1); // <<< Formular mit RichEdit an erste stelle setzten
  Application.CreateForm(TForm2, Form2);
  Application.CreateForm(TForm3, Form3);
  Application.Run;
end.


Geh in deine Projektdatei und setzte das Formular mit der RichEdit Komponente an erste Stelle.

Moderiert von user profile iconAXMD: Code- durch Delphi-Tags ersetzt.

_________________
Popov
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Sa 05.03.05 21:19 
Hallo,

hab schon alles probiert , hilft alles nichts .
Steht immer : Zugriffsverletzung

Könnt Ihr mir sagen was da falsch ist ?

Gruß

THF
Popov
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1655
Erhaltene Danke: 13

WinXP Prof.
Bei Kleinigkeiten D3Pro, bei größeren Sachen D6Pro oder D7
BeitragVerfasst: Sa 05.03.05 21:36 
THF hat folgendes geschrieben:
hab schon alles probiert , hilft alles nichts .


Bist du sicher?

Zitat:
Steht immer : Zugriffsverletzung


Zugriffsverletzung gibt es immer dann, wenn auf ein Objekt, das noch nicht initialisiert wurde, zugriffen wird.

So richtig glaube ich dir nicht, daß du alles ausprobiert hast. Entweder befolgst du nicht die Reihenfolge oder du gibst nicht alle Infos preis. Bevor du auf eine Komponente zugreifen kannst, muß sie erst da sein.

_________________
Popov
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: So 06.03.05 07:14 
Hallo,

ich habe das Formular mit dem RichEdit1 an die erste Stelle gesetzt.
Zusätzlich habe ich noch geschrieben

if not Assigned(Nebenformular) then
Nebenformular := TNebenformular.Create(Application);

und trotzdem steht immer dort: Zugriffsverletzung .

Ich glaube der Fehler liegt bei dem Array.
Dort stoppt es nämlich wenn ich mit F7 reingehe.
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:
24:
25:
26:
27:
28:
const Felder :Array [1..64] of String =
 ('a1','b1','c1','d1','e1','f1','g1','h1',
 'a2','b2','c2','d2','e2','f2','g2','h2',
 'a3','b3','c3','d3','e3','f3','g3','h3',
 'a4','b4','c4','d4','e4','f4','g4','h4',
 'a5','b5','c5','d5','e5','f5','g5','h5',
 'a6','b6','c6','d6','e6','f6','g6','h6',
 'a7','b7','c7','d7','e7','f7','g7','h7',
 'a8','b8','c8','d8','e8','f8','g8','h8') ;
.............
function THauptformular.Umrechnung_Notation( von,nach,F_index: Integer):String;
 var v1,n1,F1 : string ;
begin
v1:= Felder[von];  <------ hier stoppt es !!!
n1:= Felder[nach];


case F_Index of
2,8: F1:='S';
3,9: F1:='L';
4,10: F1:='T';
5,11: F1:='D';
6,12: F1:='K';
 end;
 result:= (F1+''+ v1+'-'+n1);


 end;

Gruß

THF
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: So 06.03.05 09:24 
Dann wird vermutlich "von" einen Wert haben, der außerhalb des Arrays liegt.