Autor Beitrag
Tom.Schröder
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Mo 06.08.07 09:08 
Erhalte beim Erzeugen eines Objektes eine EAccessViolation bei folgender Klasse:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
type
  TFrage = class(TObject)
  private
   FBewertungsText: array[0..9of String;
    function Get(Index: Integer): string;
    procedure setString(Index: Integer; const S: string);
  public
   property Bewertungstext[Index: Integer]: string read Get write setString;
   constructor Create(bewText: array of String);
  end;


In Form1 hab ich einfach 10 Editfelder, klicke ich auf den Button passiert folgendes:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Button1Click(Sender: TObject);
var
 frage : TFrage;
 stringArray: array of string;
begin
  SetLength(stringArray, 10);
    stringArray[0]:= Edit1.Text;
    ... // Der Kürze halber 1 bis 8 weggelassen
    stringArray[9]:= Edit10.Text;
    frage.Create(StrToFloat(eGewichtung.Text), stringArray);
  end;
end;


Der Konstruktor von TFrage sieht so aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
constructor TFrage.Create(bewText: array of String);
var i:Integer;
begin
  for i  := 0 to 9 do
  begin
   Bewertungstext[i]:=bewText[i];
  end;
end;


Warum erhalte ich eine EAccessviolation?

MfG Tom Schröder
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 06.08.07 09:18 
Pack mal ein inherited an den Anfang des Constructors mit bei. Und:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Button1Click(Sender: TObject); 
var 
 frage : TFrage; 
 stringArray: array of string
begin 
  SetLength(stringArray, 10); 
    stringArray[0]:= Edit1.Text; 
    ... // Der Kürze halber 1 bis 8 weggelassen 
    stringArray[9]:= Edit10.Text; 
    frage := Tfrage.Create(StrToFloat(eGewichtung.Text), stringArray); 
  end
end;

_________________
We are, we were and will not be.
Tom.Schröder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Mo 13.08.07 14:42 
Auch wenn es schon einige Tage her ist,
Danke für das Beantworten und Helfen!
Inzwischen habe ich mich weiter in Delphi eingearbeitet und verstehe sogar warum mein Ansatz nicht funktionierte :-)

MfG
Tom Schröder