Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Fehlermeldung bei Parent-Zuweisung von einer array of TGroupbox (https://www.delphipraxis.net/195150-fehlermeldung-bei-parent-zuweisung-von-einer-array-tgroupbox.html)

GeldoderBambo 6. Feb 2018 20:07

Fehlermeldung bei Parent-Zuweisung von einer array of TGroupbox
 
Servus Leute

folgendes Problem:

Im Hauptformular (Form1) erzeuge ich per Buttonclick zur Laufzeit beliebig viele Groupboxen (array of TGroupbox) in Form6.
Delphi-Quellcode:
SetLength(Groupbox4list, i+1);
  Groupbox4list[i] := TGroupbox.Create(Form6);
  Groupbox4list[i].Parent := Form6;
  Groupbox4list[i].Top := 47;
  Groupbox4list[i].Left := 95;
  Groupbox4list[i].Height := 317;
  Groupbox4list[i].Width := 171;
  Groupbox4list[i].Caption := 'Strang ' + IntToStr(i);
  Groupbox4list[i].Anchors := [akBottom,akTop];
  Groupbox4list[i].Font.Style := [fsBold];
Funktioniert alles wunderbar.

Nun möchte ich über einen Buttonclick von Form2 aus, auf den oben erzeugten Groupboxen, nochmals Groupboxen erzeugen:
Delphi-Quellcode:
procedure TForm2.Button2Click(Sender: TObject);

begin

SetLength(Groupbox5list, Form1.i+1);
  Groupbox5list[Form1.i] := TGroupbox.Create(Form6);
  Groupbox5list[Form1.i].Parent := Form6.Groupbox4list[1];
  Groupbox5list[Form1.i].Top := 47;
  Groupbox5list[Form1.i].Left := 95;
  Groupbox5list[Form1.i].Height := 317;
  Groupbox5list[Form1.i].Width := 171;
  Groupbox5list[Form1.i].Caption := 'Strang ' + IntToStr(Form1.i);
  Groupbox5list[Form1.i].Font.Style := [fsBold];

end;
Fehlermeldung in dieser Zeile: (Groupbox5list[Form1.i].Parent := Form6.Groupbox4list[1];): "Zugriffsverletzung bei Adresse 005E600F in Modul..."

Wenn ich den Parent folgendermaßen, auf eine "statische" Groupbox ändere:
Delphi-Quellcode:
SetLength(Groupbox5list, Form1.i+1);
  Groupbox5list[Form1.i] := TGroupbox.Create(Form6);
  Groupbox5list[Form1.i].Parent := Form6.Groupbox1;
  Groupbox5list[Form1.i].Top := 47;
  Groupbox5list[Form1.i].Left := 95;
  Groupbox5list[Form1.i].Height := 317;
  Groupbox5list[Form1.i].Width := 171;
  Groupbox5list[Form1.i].Caption := 'Strang ' + IntToStr(Form1.i);
  Groupbox5list[Form1.i].Font.Style := [fsBold];
funktioniert es auch.

Außerdem funktioniert mein Vorhaben, wenn ich "Groupbox4list.Parent := Form1" anstatt "Groupbox4list.Parent := Form6" schreibe.

Ich hoffe ich habe mich halbwegs verständlich ausgedrückt :D
Vielen Dank schon mal für eure Mühe!



Form1 Kopf:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls,
  System.Actions, Vcl.ActnList, Vcl.Grids;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Button1: TButton;
    GroupBox3: TGroupBox;
    Memo1: TMemo;
    Memo2: TMemo;
    Memo3: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Panel1: TPanel;
    GroupBox4: TGroupBox;
    GroupBox5: TGroupBox;
    ComboBox1: TComboBox;
    CheckBox1: TCheckBox;
    Memo4: TMemo;
    Memo5: TMemo;
    Memo6: TMemo;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    GroupBox6: TGroupBox;
    Memo7: TMemo;
    Memo8: TMemo;
    Label16: TLabel;
    Button2: TButton;
    ComboBox2: TComboBox;
    Label17: TLabel;
    Label18: TLabel;
    Panel2: TPanel;
    Label19: TLabel;
    Button4: TButton;
    Button5: TButton;
    Button8: TButton;
    Button9: TButton;
    ScrollBox1: TScrollBox;
    Button3: TButton;
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure ButtonlistClick(Sender: TObject);
    procedure Button2listClick(Sender: TObject);
    procedure PanellistClick(Sender: TObject);
    procedure Panel2listClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }

  public
    { Public-Deklarationen }
    Groupbox4list:array of TGroupbox;
    Groupbox5list:array of TGroupbox;
    Button3list :array of TButton;
    panel2list :array of TPanel;
    Scrollboxlist :array of TScrollbox;

    function Spitzendurchfluss (x, y, z, VR: real) : real;
    var x, y, z, VR, VS :real;
    i,p :integer;
    Memozahl : Integer;

  end;

  type
  TGebäudetyp = record
      Bezeichnung : string;
      consta : real;
      constb : real;
      constc : real;

  end;

  TEntnahmestelle = record
    Bezeichnung: string;
    Nennweite: integer;
    Mindestfließdruck: real;
    Berechnungsdurchfluss: real;
    PWH : boolean;
  end;



var
  Form1: TForm1;
  Gebäudeliste : TGebäudeliste;
  Gebäudetyp : TGebäudetyp;
  Entnahmeliste : TEntnahmeliste;
  Entnahmestelle : TEntnahmestelle;
  j :integer;



implementation


uses Math, Unit2, Unit3, Unit4, Unit5, Unit6, Unit7;
{$R *.dfm}

Form6 Kopf:
Delphi-Quellcode:
unit Unit6;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;

type
  TForm6 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Button1: TButton;
    Button2: TButton;
    GroupBox2: TGroupBox;
    Panel5: TPanel;
    Label19: TLabel;
  private

    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  //Stränge Eingabe Form 6
  Groupbox4list :array of TGroupbox;
  Scrollboxlist :array of TScrollbox;
  Groupbox5list :array of TGroupbox;
  Button3list :array of TButton;
  //Panel Stränge für Auswahl
  panel2list :array of TPanel;
  end;

var
  Form6: TForm6;

implementation

{$R *.dfm}

uses Unit1, Unit5, unit2;

Redeemer 6. Feb 2018 21:48

AW: Fehlermeldung bei Parent-Zuweisung von einer array of TGroupbox
 
Alles, was nicht String im Namen hat, beginnt bei 0. Wenn dein Array 1 Element hat, gibt es kein Element 1.

hoika 6. Feb 2018 22:27

AW: Fehlermeldung bei Parent-Zuweisung von einer array of TGroupbox
 
Hallo,
was ein Durcheinander.
Warum haben die Variablen keine anständigen Namen (was ist denn Form1, GroupBox4).

Vielleicht ist das aber Deine Strategie eines Minimal-Beispiels. Dann wäre da 100.% richtig!

Poste mal bitte ein Minimalbeispiel, was deinen Fehler genau erzeugt
(Zip-Datei mit allen Dateien (außer natürlich der Exe-Datei selbst).

hsg 7. Feb 2018 07:14

AW: Fehlermeldung bei Parent-Zuweisung von einer array of TGroupbox
 
Wenn ich das Chaos richtig überblickt habe, erzeugst du die GroupBox-Liste auf der Form1 und nicht auf Form6, daher ist das Array in Form6 nicht gefüllt => Zugriffsfehler.

Kann mich aber nur hoika anschließen: bei den vielen Namensgleichheiten kommt jeder Entwickler ja ins Schleudern.

freimatz 7. Feb 2018 09:14

AW: Fehlermeldung bei Parent-Zuweisung von einer array of TGroupbox
 
Außerdem: Bei solchen Fällen wie
Zitat:

Fehlermeldung in dieser Zeile: (Groupbox5list[Form1.i].Parent := Form6.Groupbox4list[1]: "Zugriffsverletzung bei Adresse 005E600F in Modul..."
1. zuerst einmal die Zeile in einfachere Zeilen zerlegen, also z.B. "Form6.Groupbox4list[1]" erstmal einer einfachen lokalen Variablen zuweisen
2. Debuggen

GeldoderBambo 7. Feb 2018 13:18

AW: Fehlermeldung bei Parent-Zuweisung von einer array of TGroupbox
 
Liste der Anhänge anzeigen (Anzahl: 1)
Erstmal vielen vielen Dank für Eure schnellen Antworten. Echt Super!:oops:

Meine nicht vorhandene Struktur ist echt eine Katastrophe, ich weiß:roll:. Werde in Zukunft versuchen das zu verbessern.


Habe jetzt mal ein Minimal Beispiel hochgeladen, wo ich das selbe Problem erzeuge.

Eventuell hat hsg ja schon das Problem erkannt. Allerdings wüsste ich dann immer noch nicht wie ich das lösen sollte :pale:.

Beste Grüße

Olli73 7. Feb 2018 13:31

AW: Fehlermeldung bei Parent-Zuweisung von einer array of TGroupbox
 
Zitat:

Zitat von GeldoderBambo (Beitrag 1393286)
Eventuell hat hsg ja schon das Problem erkannt. Allerdings wüsste ich dann immer noch nicht wie ich das lösen sollte :pale:.

Indem du beim Erstellen der ersten Groupbox(en) in Form1
Delphi-Quellcode:
Form6.Groupbox4list[1];
anstatt
Delphi-Quellcode:
Groupbox4list[1];
benutzt.

sko1 8. Feb 2018 06:12

AW: Fehlermeldung bei Parent-Zuweisung von einer array of TGroupbox
 
.. oder die Groupbox-Arrays global deklarieren in einer eigenen unit, die allen Forms bekannt gemacht wird...

Ciao
Stefan


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:37 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz