Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Problem mit TColletion zur Designzeit (https://www.delphipraxis.net/41251-problem-mit-tcolletion-zur-designzeit.html)

static_cast 28. Feb 2005 16:53


Problem mit TColletion zur Designzeit
 
Hi,

ich habe ein Problem und zwar versuche ich mit einer TCollection ein TCollectionItems eine Liste zu erstellen die man zur Designzeit im OI bearbeiten kann. Er öffnet einfach nicht das Fenster zum bearbeiten :( Aber funktionieren tut es soweit ich habe es ausporbiert ich kann zur laufzeits Items erstellen und auf sie zugreifen, nur zur Designzeit geht es nicht.

Der Code ist folgender:

Delphi-Quellcode:
  { TAccount }

  TAccount = class(TCollectionItem)
  private
    FValue: String;
    procedure SetValue(const Value: String);
  protected
  public
    constructor Create(ACollection: TCollection); override;
  published
    property Value:String read FValue write SetValue;
  end;

  { TAccounts }

  TAccounts = class(TCollection)
  private
    FOwner: TPersistent;
    function GetItem(Index: Integer): TAccount;
    procedure SetItem(Index: Integer; Value: TAccount);
  protected
    function GetOwner: TPersistent; override;
  public
    constructor Create(Owner: TPersistent);
    function Add: TAccount;
    property Items[Index: Integer]: TAccount read GetItem write SetItem; default;
  end;

  { TAccountProperties }

  TAccountProperties = class(TPersistent)
  private
    FVisibleAccounts: TAccountTypes;
    FAccounts: TAccounts;
    procedure SetVisibleAccounts(const Value: TAccountTypes);
    procedure SetAccounts(Value: TAccounts);
  protected
  public
    constructor Create;
    destructor Destroy; override;
  published
    property Accounts:TAccounts read FAccounts write SetAccounts;
    property VisibleAccounts:TAccountTypes read FVisibleAccounts write SetVisibleAccounts;
  end;
Delphi-Quellcode:
{ TAccountProperties }

constructor TAccountProperties.Create;
begin
  FAccounts:=TAccounts.Create(Self);
  VisibleAccounts:=atAll;
end;

destructor TAccountProperties.Destroy;
begin
  FreeAndNil(FAccounts);
  inherited;
end;

procedure TAccountProperties.SetAccounts(Value: TAccounts);
begin
  FAccounts.Assign(Value);
end;

procedure TAccountProperties.SetVisibleAccounts(const Value: TAccountTypes);
begin
  FVisibleAccounts:=Value;
end;

{ TAccount }

constructor TAccount.Create(ACollection: TCollection);
begin
  inherited Create(ACollection);
end;

procedure TAccount.SetValue(const Value: String);
begin
  FValue := Value;
end;

{ TAccounts }

function TAccounts.Add: TAccount;
begin
  Result := TAccount(inherited Add);
end;

constructor TAccounts.Create(Owner: TPersistent);
begin
  inherited Create(TAccount);
  FOwner:=Owner;
end;

function TAccounts.GetItem(Index: Integer): TAccount;
begin
  Result := TAccount(inherited GetItem(Index));
end;

function TAccounts.GetOwner: TPersistent;
begin
  Result := FOwner;
end;

procedure TAccounts.SetItem(Index: Integer; Value: TAccount);
begin
  inherited SetItem(Index, Value);
end;
Grüße,
Daniel.

P.S.: bin @work und hier benutzen wir Delphi 5 Pro (wenn das von relevants ist ;) )

Jens Schumann 28. Feb 2005 17:11

Re: Problem mit TColletion zur Designzeit
 
Hallo,
versuchs es mal mit
Delphi-Quellcode:
constructor TAccountProperties.Create;
begin
  FAccounts:=TAccounts.Create(TAccount); // Der Parameter ist der Unterschied
  VisibleAccounts:=atAll;
end;

static_cast 28. Feb 2005 18:31

Re: Problem mit TColletion zur Designzeit
 
Hi,

hmmm nun ja:
Zitat:

[Error] TestComponente.pas(83): Incompatible types: 'TPersistent' and 'Class reference'
geht nicht :?


//Edit: aber eigentlich ist das doch eh egal denn:

Delphi-Quellcode:
constructor TAccounts.Create(Owner: TPersistent);
begin
  inherited Create(TAccount); // <---- hier wird der originale aufgerufen
  FOwner:=Owner;
end;

Jens Schumann 28. Feb 2005 18:41

Re: Problem mit TColletion zur Designzeit
 
Hallo,
mein Vorschlag kann auch nicht funktionieren. Habe mich in der Zeile vertan.
Kannst Du TAccountProperties im OI sehen?

Jens Schumann 28. Feb 2005 18:43

Re: Problem mit TColletion zur Designzeit
 
Hallo,
Delphi-Quellcode:
constructor TAccountProperties.Create;
begin
  inherited Create; // fehlt bei Dir
  FAccounts:=TAccounts.Create(Self);
  VisibleAccounts:=atAll;
end;

static_cast 28. Feb 2005 19:12

Re: Problem mit TColletion zur Designzeit
 
Liste der Anhänge anzeigen (Anzahl: 1)
Also TAccountProperties ist im OI zu sehen.

Hier mal der Source der TestCompo womit ich auch gerade hier nebenbei zu Hause teste... ich hab echt keine Idee woran es liegt.

static_cast 1. Mär 2005 09:01

Re: Problem mit TColletion zur Designzeit
 
So ich hab nochmal nachgeschaut und nach einem ganz einfachen Bsp. gesucht, wobei ich einen gut beschriebenen Artikel auf der Borland Seite gefunden habe: http://bdn.borland.com/article/0,1410,16647,00.html

Habe dann mal den Source (von TMyCollectionItem und TMyCollection) genommen und 1 zu 1 in meinen übertragen damit es in TAccountProperties vorhanden ist, Ergebnis: es geht auch nicht, wenn ich im OI TAccountProperties aufklappe und dann TAccounts bearbeiten will passiert nicht, es erscheint einfach kein Fenster zum bearbeiten der Collection.

Kann es sein das eine TCollection nicht in einem TPersistent "funktioniert" wie es mein TAccountProperties ja ist?

static_cast 2. Mär 2005 09:25

Re: Problem mit TColletion zur Designzeit
 
Keiner weiter eine Idee was des Problems Ursache ist oder sein kann?

maximov 2. Mär 2005 09:36

Re: Problem mit TColletion zur Designzeit
 
Ich habs jetzt nicht getestet und ist nur ne vermutung: mach die AccountProperties property mal read-only:
Delphi-Quellcode:
  property AccountProperties:TAccountProperties read FAccountProperties;
ohne gewehr.

Und nein ich glaube nicht, das es an TPersistent liegen kann.

static_cast 2. Mär 2005 11:01

Re: Problem mit TColletion zur Designzeit
 
Liste der Anhänge anzeigen (Anzahl: 1)
Es hat nichts gebracht, funktioniert genausowenig!

Aber ich habe es mal versucht ohne TAccountProperties direkt an die Komponente anzubinden und zu nutzen, und siehe da, es geht, warum? Dann muss es ja doch an dem TPersistent bzw an TAccountProperties liegen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:00 Uhr.
Seite 1 von 2  1 2      

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