Autor Beitrag
Vaio
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

Win XP Home
D7 Prof
BeitragVerfasst: Sa 18.02.06 17:02 
Für mein Informatikunterricht programmiere ich das Programm "Notizzettel". Ich habe im ersten Fenster eine Listbox und drei Buttons: Neuer Notizzettel, Zettel löschen und Programmende.
Wenn ich auf Notizzettel klicke öffnet sich eine Aboutbox, dort kann ich den Namen für den neuen Notizzettel in ein Editfeld eingeben. Wenn ich dann auf OK klicke öffnet sich ein Form3-Fenster und der Edit.Text wird an die Caption übergeben.
In dem neuen Form3 Fenster gibt es ein Memofeld wo man die Notiz hinterlassen kannst. Wenn man jetzt auf OK in Form3 klickt, sollte die Caption in die Listbox übergeben und das Fenster sich schließen. Und wenn man jetzt in der Listbox, den Notizzettel auswählt sollte sich dieser wieder öffnen.
Wenn ich jedoch auf OK drücke kommt ein Fehler:
Im Project Project1.exe ist eine Exception der Klasse EAccessViolation aufgetreten. Meldung: 'Zugriffsverletzung bei Adresse 00454720 in Modul Project1.exe. Lesen von Adresse 00000000'.

Form1:

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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    btnn: TButton;
    btzl: TButton;
    btp: TButton;
    Listbox: TListBox;
    procedure btnnClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.btnnClick(Sender: TObject);
begin
 AboutBox.show;
end;

end.


Unit2:

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 Unit2;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
  Buttons, ExtCtrls;

type
  TAboutBox = class(TForm)
    edn: TEdit;
    Label1: TLabel;
    btok: TButton;
    btab: TButton;
    procedure btabClick(Sender: TObject);
    procedure btokClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  AboutBox: TAboutBox;
  Listbox: TListbox;

implementation

uses Unit3;

{$R *.dfm}

procedure TAboutBox.btabClick(Sender: TObject);
begin
 AboutBox.Close;
end;

procedure TAboutBox.btokClick(Sender: TObject);
begin
 Form3.show;
 Form3.caption:=edn.text;
 Aboutbox.Close;
end;

end.


Unit3:

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:
unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Unit1, Unit2;

type
  TForm3 = class(TForm)
    MemZettel: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
 ListBox.Items[ListBox.ItemIndex]:=Form3.caption;
end;

end.
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Sa 18.02.06 18:17 
Setze doch mal einen Breakpoint(links neben die Codezeile im Editor klicken), wenn das bei dir richtig bezeichnet ist dann in btokClick. Dann startest du das Programm und führst das aus was du machen willst. Dann hält der Debugger am Breakpoint und du kannst dich mit F8 an die Stelle herantasten bis es knackt.

Instinktiv würde ich aufgrund der
Zitat:
Adresse 00000000
sagen das du vergessen hast was zu initialisieren. In Unit3 wird z.B. einem Item ein Text zugewiesen aber in deinen ganzen Quellcode wird nirgendwo Listbox.items.add() aufgerufen.
Vaio Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

Win XP Home
D7 Prof
BeitragVerfasst: Sa 18.02.06 18:27 
An btokclick liegt das nicht, der ganze Fehler taucht bei der Unit3 auf bei Button1click.
Ich weiß jetzt nicht wo ich jetzt dieses Listbox.items.add() initialisieren könnte.
Wenn ich:

Listbox.items.add(Form3.caption)

eingebe, kommt der selbe Fehler.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 18.02.06 18:40 
mh.. schreib mal form1.listbox1. denn er weiß ja nicht, dass du die listbox aus unit1 meinst ;)
dann muss natürlich noch uses unit1 in unit 3 rein
Vaio Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

Win XP Home
D7 Prof
BeitragVerfasst: Sa 18.02.06 18:54 
Jetzt taucht der Fehler nicht mehr auf, aber es wird nichts in die Listbox eingetragen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
  Form3: TForm3;
  edn: TEdit;

implementation

uses Unit1, Unit2;

{$R *.dfm}


procedure TForm3.Button1Click(Sender: TObject);
begin
  Form1.ListBox.Items[Form1.ListBox.ItemIndex]:=Form3.caption;
end;

end.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 18.02.06 19:00 
komisch, bei mir klappts :roll:
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: So 19.02.06 10:54 
Aber das Item existiert doch noch garnicht, oder?
ausblenden Delphi-Quelltext
1:
Form1.ListBox.Items.Add(Form3.caption);					
Vaio Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

Win XP Home
D7 Prof
BeitragVerfasst: So 19.02.06 15:18 
Muss es denn existieren? Dann muss man es vorher deklarieren, oder was?

EDIT: Das Problem hat sich behoben!
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: So 19.02.06 21:48 
Und wie?