Einzelnen Beitrag anzeigen

JulianBayer

Registriert seit: 2. Jan 2016
2 Beiträge
 
#1

Kompilierfehler bei während er Laufzeit erstellten Objekten

  Alt 2. Jan 2016, 12:48
Delphi-Version: 7
Liebe Delphi Gemeinde!,
ich bringe mir gerade selbst im Rahmen meiner Diplomarbeit das Programmieren für die Programmierung eines Titroprozessors bei, jedoch bin ich nun auf einen für mich unerklärlichen Fehler gestoßen ... ich hoffe einer von euch kann mir helfen:

Bei meinem Programm erstelle ich ComboBoxen und Edits, welche während der Laufzeit durch die Änderung eines SpinEdits aufgerufen werden.

Das eigenartige ist, dass ich wenn ich das Programm normal mit F9 ausführe nur ein Fehler auftritt wenn ich eine ComboBox auf die Items 3,4 od. 5 stelle was dazu führt, dass ein weiteres Edit created wird.
Wenn ich nun das SpinEdit increase oder decrease, dann folgt die Fehlermeldung: "Zugriffsverletzung in der Adresse 00000000".

Wenn ich aber die Routine einzeln durchlaufen lasse (F8) und ich dann zu dem Form komme wo diese Objekte erstellt werden läuft der Compiler alle Zeilen wie erwartet und ohne Fehlermeldung durch, auch die die den Items der Dropbox Namen zuweisen, doch dann sind die Dropboxen "Leer" und man kann nichts auswählen.

Die Edits weisen nie Fehler auf ^^

Ich hoffe ihr könnt mit meiner Beschreibung etwas anfangen!

Hier noch Quelltext von dem besprochenen Form:

Varriablendekl.:
Delphi-Quellcode:
var
  Form7: TForm7;
  GlobaleZahl: Word;
  AnalytEdit : Array of TEdit;
  MassloesungsEdit : Array of TEdit;
  MrzMassloesungsEdit : Array of TEdit;
  TitrationsartComboBox : Array of TComboBox;
  BestimmungsartComboBox : Array of TComboBox;
  {ÜbergangsArray für Form5}
  UeAr : Array of TAnaly;
  BestZ : Array of Word;
implementation
Prozedur zum erstellen (und davor löschen):
Delphi-Quellcode:
 SetLength(AnalytEdit, i+1);
 SetLength(MassloesungsEdit, i+1);
 SetLength(TitrationsartComboBox, i+1);
 SetLength(BestimmungsartComboBox, i+1);
 for x := 0 to i do
  begin
   AnalytEdit[x].Free;
   MassloesungsEdit[x].Free;
   TitrationsartComboBox[x].Free;
   BestimmungsartComboBox[x].Free;
  end;


 SetLength(MassloesungsEdit, i);
 SetLength(TitrationsartComboBox, i);
 SetLength(BestimmungsartComboBox, i);
 SetLength(AnalytEdit, i);
 for x := 0 to i-1 do
  begin
   BestimmungsartComboBox[x] := TComboBox.Create(Form7);
   BestimmungsartComboBox[x].Parent := Form7;
   BestimmungsartComboBox[x].Top := Grundy + x*42;
   BestimmungsartComboBox[x].Left := Grundx;
   BestimmungsartComboBox[x].Height := 24;
   BestimmungsartComboBox[x].Width := 145;
   BestimmungsartComboBox[x].Clear;
   BestimmungsartComboBox[x].Items.Append('Einzelbestimmung');
    if SpinEdit2.Value > 1 then
     begin
      BestimmungsartComboBox[x].Items.Append('Summenbestimmung');
     end;
   BestimmungsartComboBox[x].ItemIndex := 0;
   BestimmungsartComboBox[x].OnChange := BestimmungsartChange;

   TitrationsartComboBox[x] := TComboBox.Create(Form7);
   TitrationsartComboBox[x].Parent := Form7;
   TitrationsartComboBox[x].Top := Grundy + x*42;
   TitrationsartComboBox[x].Left := Grundx + 160;
   TitrationsartComboBox[x].Height := 24;
   TitrationsartComboBox[x].Width := 145;
   TitrationsartComboBox[x].Clear;
   TitrationsartComboBox[x].Items.Append('Titerstellung');
   TitrationsartComboBox[x].Items.Append('Direkte Titration');
   TitrationsartComboBox[x].Items.Append('Inverse Titration');
   TitrationsartComboBox[x].Items.Append('Indirekte Titration'); //
   TitrationsartComboBox[x].Items.Append('Rücktitration'); //
   TitrationsartComboBox[x].Items.Append('Substitutionstitration'); //
   TitrationsartComboBox[x].ItemIndex := 0;
   TitrationsartComboBox[x].OnChange := TitrationsartChange;

   MassloesungsEdit[x] := TEdit.Create(Form7);
   MassloesungsEdit[x].Parent := Form7;
   MassloesungsEdit[x].Top := Grundy + x*42;
   MassloesungsEdit[x].Left := Grundx + 320;
   MassloesungsEdit[x].Height := 24;
   MassloesungsEdit[x].Width := 121;
   MassloesungsEdit[x].Text := 'Maßlösung ' + IntToStr(x+1);

   AnalytEdit[x] := TEdit.Create(Form7);
   AnalytEdit[x].Parent := Form7;
   AnalytEdit[x].Top := 256 + x*42;
   AnalytEdit[x].Left := 24;
   AnalytEdit[x].Height := 24;
   AnalytEdit[x].Width := 121;
   AnalytEdit[x].Text := 'Analyt ' + IntToStr(x+1);
  end;
Erstellen der weiteren Edits wenn Item 3,4,5 ausgewählt:
Delphi-Quellcode:
procedure TForm7.TitrationsartChange(Sender: TObject); //Titrationsart
 var i,SD,index : Word;
 begin
  for i := 0 to SpinEdit1.Value -1 do
   begin
    if Sender = TitrationsartComboBox[i] then
     begin
      index := i; //index = die Reihe von 0 bis 9
     end;
   end;
  SD := (Sender as TComboBox).ItemIndex;
  if SD > 2 then
   begin
    MrzMassloesungsEdit[index].Free;
    MrzMassloesungsEdit[index]:= TEdit.Create(Form7);
    MrzMassloesungsEdit[index].Parent := Form7;
    MrzMassloesungsEdit[index].Left := 644;
    MrzMassloesungsEdit[index].Width := 162;
    MrzMassloesungsEdit[index].Top := 256 + 42*index;
    MrzMassloesungsEdit[index].Text := 'Rücktitrationssubstanz ' + IntToStr(1+index);
   end else
   begin
    MrzMassloesungsEdit[index].Free;
   end;
 end;

Wieder Löschen:

Delphi-Quellcode:
procedure TForm7.SpinEdit1Change(Sender: TObject); //Analysen
 var i: Word;
 begin
  ShowEdits(SpinEdit1.Value,168, 256);
  SetLength(MrzMassloesungsEdit,SpinEdit1.Value);
   for i := 0 to SpinEdit1.Value-1 do
    begin
     if MrzMassloesungsEdit[i].Text = 'then
      begin
      end
      else
       MrzMassloesungsEdit[i].Free;
      end;
    end;
Beste Grüße,
und danke im voraus
Julian Bayer
  Mit Zitat antworten Zitat