Autor Beitrag
Andi1982
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 497

WinXP HE
D6 Enterprise
BeitragVerfasst: So 07.09.03 20:13 
Hallo,
ich habe eine Form2 die ich so aufrufe:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button2Click(Sender: TObject);
var Options: TForm;
begin
  Options := TForm2.Create(Self);
  TRY
  IF (Options.ShowModal = mrOK) THEN
       // Hier Optionen Speichern
  FINALLY
    Options.Free;
  END// TRY Finally
end;


Dies habe ich hier im Forum gefunden und kopiert. In dieser Form2 habe ich eine Variable (RenDatname) so deklariert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
type
  TForm2 = class(TForm)
    Label1: TLabel;
      .
      .
      .
    procedure Button5Click(Sender: TObject);
  private
    { Private-Deklarationen }
      MPEGaudio: TMPEGaudio;
      procedure Mp3Laenge(Datname: String);
  public
    { Public-Deklarationen }
    RenDatname: String;       
  end;


Diese Variable will ich in Form3 mitbenutzen. Diese form rufe ich ebenfalls wieder mit ShowModal auf:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
// Formular erzeugen und aufrufen
   Options := TForm3.Create(Self);
   TRY
   IF (Options.ShowModal = mrOK) THEN
        // Hier Optionen Speichern
   FINALLY
     Options.Free;
   END// TRY Finally


Meine Form3 sieht so aus:
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:
45:
46:
47:
unit Unit3;

interface

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

type
  TForm3 = class(TForm)
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    GroupBox2: TGroupBox;
    Button1: TButton;
    Edit2: TEdit;
    Edit3: TEdit;
    Button2: TButton;
    Button3: TButton;
    Edit4: TEdit;
    Button4: TButton;
    Button5: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form3: TForm3;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm3.FormCreate(Sender: TObject);
var
   pos1bind, pos2bind, pos3bind: Integer;
begin
   pos1bind := pos('-', Form2.RenDatname);
end;

end.


Jetzt mein Problem, wenn ich das Programm ausführe kommt bei dieser anweisung pos1bind := pos('-', Form2.RenDatname); eine zugriffsverletzung. Aber warum??? Kann mir jemand helfen?? habe delphi 6.

Hoffe es kann mir jemand helfen!!!!

Gruss andi

_________________
Solange die Bombe tickt ist alles in Ordnung, erst wenn sie damit aufhört wird es problematisch...
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Di 09.09.03 19:26 
Weil Form2 noch nicht existiert?
grez
msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
Andi1982 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 497

WinXP HE
D6 Enterprise
BeitragVerfasst: Mi 10.09.03 07:01 
Form2 existiert da schon lange. Die hat doch die Form3 aufgerufen!

_________________
Solange die Bombe tickt ist alles in Ordnung, erst wenn sie damit aufhört wird es problematisch...
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mi 10.09.03 08:14 
Du greifst aber auf die Variable Form2 zu, und nicht auf die Varible Options die du instanziert hast... enthält Form2 eine gültige Objektreferenz?

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Andi1982 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 497

WinXP HE
D6 Enterprise
BeitragVerfasst: Mi 10.09.03 08:19 
In der Form2 ist doch die Variable Form2 vom Type TForm2 deklariert. Naja, egal. hab das jetzt anders gemacht.

Meine Variable Remdatname habe ich in der Form2 unter den "var"s deklariert und kann sie in Form3 jetzt mit Unit2.Remdatname ansprechen. Weiß zwar nicht warum das funktioniert, aber es funktioniert 8)

_________________
Solange die Bombe tickt ist alles in Ordnung, erst wenn sie damit aufhört wird es problematisch...
barfuesser
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 324



BeitragVerfasst: Mi 10.09.03 11:15 
Pack die Variable wieder in den Public-Bereich und greif dann im Form3 über TForm2(Owner).<Variable> auf Deine Variable zu.

barfuesser
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Mi 10.09.03 12:41 
Es reicht nicht, nur ne Objektvariable zu deklarieren, sie muss auch mit Create() erzeugt werden! Vielleicht liegts daran
grez
msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?