Einzelnen Beitrag anzeigen

AJ_Oldendorf

Registriert seit: 12. Jun 2009
Ort: Stadthagen
384 Beiträge
 
Delphi 10.3 Rio
 
#1

Unterschied D2009 <-> XE7 Komponenten dynamisch erstellen auf Form -> Fehlermeldung

  Alt 23. Okt 2014, 11:04
Hallo zusammen,
kann mir mal bitte einer kurz sagen, warum der nachfolgende Code unter D2009 funktioniert und unter XE7 nicht mehr? Fehlermeldung bei AddCol ist dann: Element hat kein übergeordnetes Fenster

Unit1:
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.StdCtrls, Unit2;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    frm2 : TForm2;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Assigned(frm2) then
    frm2 := TForm2.Create(Application);

  if Assigned(frm2) then
    frm2.Show;
end;

end.
Unit2:
Delphi-Quellcode:
unit Unit2;

interface

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

type
  TMyVirtualStringTree = class(TVirtualStringTree)
  private
  public
    constructor Create(AOwner: TComponent); override;
  end;

type
  TForm2 = class(TForm)
    GroupBox1: TGroupBox;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    MyVst : TMyVirtualStringTree;
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
begin
  if not Assigned(MyVst) then
  begin
    MyVst := TMyVirtualStringTree.Create(Self);
    MyVst.Align := alClient;
    MyVst.Parent := GroupBox1;
    MyVst.Show;
  end;
end;

{ TMyVirtualStringTree }

constructor TMyVirtualStringTree.Create(AOwner: TComponent);

  procedure AddCol(aVst: TVirtualStringTree; aCaption: String; aWidth: Integer);
  begin
    with aVst.Header.Columns.Add do
    begin
      Text := aCaption;
      Width := aWidth;
    end;
  end;

begin
  inherited;

  NodeDataSize := SizeOf(Double);

  TreeOptions.PaintOptions :=
    [toShowButtons,
     toShowDropmark,
     toShowRoot,
     toShowHorzGridLines,
     toShowVertGridLines,
     toThemeAware,
     toUseBlendedImages] -
    [toShowTreeLines];

  Header.Options :=
    [hoColumnResize,
     hoDrag,
     hoShowHint,
     hoShowSortGlyphs,
     hoVisible];

  TreeOptions.SelectionOptions :=
    [toFullRowSelect];

  Header.Columns.Clear;

  AddCol(self, 'a', 150);
  AddCol(self, 'b', 150);
  AddCol(self, 'c', 150);
end;

end.
Viele Grüße

Edit:
Compilieren lässt es sich sowohl unter D2009 als auch unter XE7.
Nur beim D2009 sehe ich mein VirtualStringTree und erhalte keine Exception,
unter XE7 erhalte ich eine Exception und sehe keinen Tree.

Was wurde da geändert an den Delphi Versionen?

Geändert von AJ_Oldendorf (23. Okt 2014 um 11:07 Uhr)
  Mit Zitat antworten Zitat