Einzelnen Beitrag anzeigen

einbeliebigername

Registriert seit: 24. Aug 2004
140 Beiträge
 
Delphi XE8 Professional
 
#5

AW: TStringList(en) in DMF serialisieren

  Alt 1. Okt 2016, 08:03
Hallo,

so gehts
Delphi-Quellcode:
unit TestComp;

interface

uses
  System.Classes;

type

  TTestComp = class(TComponent)
  private
    fX1: String;
    fX2: Word;
    fX3: String;
    fSL_A: TStringList;
    fSL_B: TStringList;
    fSL_C: TStringList;
    fSL_D: TStringList;
    procedure SetSL_A(const Value: TStringList);
    procedure SetSL_B(const Value: TStringList);
    procedure SetSL_C(const Value: TStringList);
    procedure SetSL_D(const Value: TStringList);
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property X1: String read fX1 write fX1;
    property X2: Word read fX2 write fX2;
    property X3: String read fX3 write fX3;
    property SL_A: TStringList read fSL_A write SetSL_A;
    property SL_B: TStringList read fSL_B write SetSL_B;
    property SL_C: TStringList read fSL_C write SetSL_C;
    property SL_D: TStringList read fSL_D write SetSL_D;
  end;

procedure Register;

implementation

uses
  System.SysUtils;

procedure Register;
begin
  RegisterComponents('TestComp', [TTestComp]);
end;

{ TTestComp }

constructor TTestComp.Create(AOwner: TComponent);
begin
  inherited;
  fSL_A := TStringList.Create;
  fSL_B := TStringList.Create;
  fSL_C := TStringList.Create;
  fSL_D := TStringList.Create;
end;

destructor TTestComp.Destroy;
begin
  FreeAndNil(fSL_A);
  FreeAndNil(fSL_B);
  FreeAndNil(fSL_C);
  FreeAndNil(fSL_D);
  inherited;
end;

procedure TTestComp.SetSL_A(const Value: TStringList);
begin
  fSL_A.Assign(Value);
end;

procedure TTestComp.SetSL_B(const Value: TStringList);
begin
  fSL_B.Assign(Value);
end;

procedure TTestComp.SetSL_C(const Value: TStringList);
begin
  fSL_C.Assign(Value);
end;

procedure TTestComp.SetSL_D(const Value: TStringList);
begin
  fSL_D.Assign(Value);
end;

end.
Problem ist der Designtime-Editor. Der gibt ein neues Objekt (vermutlich TMemo.Lines) ins Property und geht davon aus das die Componente die Referenz nicht übernimmt und gibt es anschliesend frei.

einbeliebigername.
  Mit Zitat antworten Zitat