Autor Beitrag
Ratchet
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Windows7 x86
D5 Ent., D2006 Arch.
BeitragVerfasst: Mo 12.09.05 16:01 
Ich habe eine Testkomponente mit einer eigenen Collection erstellt. Nur habe ich jetzt das Problem dass wenn ich die Komponente auf die Form setzte und dann den Editor der Collection öffnen will, die Meldung "Ungültige Auswahl 'THairs' hat keinen Besitzer" bekomme. Ich habe meinen Code schon mit dem von TParams verglichen aber ich sehe den Fehler einfach nicht. Jemand von euch eine Idee was es sein könnte?

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
unit TestComponent;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  THair = class (TCollectionItem)
  private
    FLength: Integer;
  published
    property Length: Integer read FLength write FLength;
  end;

 THairs = class (TCollection)
 private
   FOwner: TPersistent;
   function GetItem(Index: Integer): THair;
 public
   constructor Create(Owner: TPersistent); overload;
   function Add: THair;
   property Item[Index: Integer]: THair read GetItem;
 end;

  TTestComponent = class(TComponent)
  private
    fHairs: THairs;
  protected
    { Protected-Deklarationen }
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Hairs: THairs read fHairs write fHairs;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Beispiele', [TTestComponent]);
end;

{ TTestComponent }

constructor TTestComponent.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  fHairs := THairs.Create(Self);
end;

function THairs.Add: THair;
begin
  result := inherited Add as THair;
end;

constructor THairs.Create(Owner: TPersistent);
begin
  FOwner := Owner;
  inherited Create(THair);
end;

function THairs.GetItem(Index: Integer): THair;
begin
  result := inherited Items[Index] as THair;
end;

end.



Moderiert von user profile iconUGrohne: Topic aus VCL (Visual Component Library) verschoben am Di 13.09.2005 um 04:27
Amateur
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 777

(Win98, WinMe) WinXP Prof
D3 Prof, D6 Pers, D2k5 Pers., Turbo C++ Explorer
BeitragVerfasst: Mo 12.09.05 16:11 
ich würde ma sagen du musst den parent zuweisen. also sowas: hairs.parent:=self;

_________________
"Kein dummes Gerede. Kein Rumrätseln. Denkt an nichts anderes mehr, nur noch an das, was vor euch liegt. Das ist die wahre Herausforderung. Ihr müßt euch vor euch selbst schützen, Leute." (Rennes in "Cube")
Beiträge: >700
Ratchet Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Windows7 x86
D5 Ent., D2006 Arch.
BeitragVerfasst: Mo 12.09.05 16:26 
Da Hairs von TCollection abgeleitet ist, und dies keine visuelle Komponente ist gibt es dort keinen Parent. Owner wäre hier richtiger aber den setzte ich ja.
Amateur
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 777

(Win98, WinMe) WinXP Prof
D3 Prof, D6 Pers, D2k5 Pers., Turbo C++ Explorer
BeitragVerfasst: Mo 12.09.05 16:30 
hm haste es denn mal probiert? also mir fällt nix weiter ein als parent. parent is ja die klasse von der es abgeleitet is oder?
bin da noch net so bewandert. kommt erst noch im info unterricht und das meiste hab ich mir selbst beigebracht aber könnte ja sein. probiers aus und wenns net geht kann dir sicher jemand anders weiterhelfen

_________________
"Kein dummes Gerede. Kein Rumrätseln. Denkt an nichts anderes mehr, nur noch an das, was vor euch liegt. Das ist die wahre Herausforderung. Ihr müßt euch vor euch selbst schützen, Leute." (Rennes in "Cube")
Beiträge: >700
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Mo 12.09.05 16:34 
In der Delphi-Hilfe steht, dass man ein TCollectionItem nicht per Create erzeugen soll, sondern über die Add-Methode der Collection!

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!
Ratchet Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Windows7 x86
D5 Ent., D2006 Arch.
BeitragVerfasst: Mo 12.09.05 23:39 
Leute, Leute... habt ihr meinste Posts überhaupt gelesen?

1. Parent gibt es nicht
2. Ich erzeuge keinen TCollectionItem, ich erzeuge eine TCollection (siehe Quellcode)!
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Mo 12.09.05 23:45 
...was auf jeden Fall mal wieder zeigt, dass ungünstig gewählte Namen (THair & THairs) schnell zu Verwechslungen führen kann! :wink:

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!
Ratchet Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Windows7 x86
D5 Ent., D2006 Arch.
BeitragVerfasst: Di 13.09.05 07:18 
Tja das ist aber Standard:

TCheckConstraints TCheckConstraint
TCookieCollection TCookie
TCoolBands TCoolBand
TDataBindings TDataBindItem
TDBGridColumns TColumn
TDependencies TDependency
TDisplayDims TDisplayDim
TFieldDefs TFieldDef
THeaderSections THeaderSection
TIndexDefs TIndexDef
THTMLTableColumns THTMLTableColumn
TListColumns TListColumn
TParams TParam
TParameters TParameter
TServerCollection TServerItem
TStatusPanels TStatusPanel
TWorkAreas TWorkArea
TWebActionItems TWebActionItem
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 13.09.05 08:55 
evtl. hilft dieser Hinweis aus der Hilfe:
Zitat:
Hinweis: Wenn Sie eine Komponente von TCollection ableiten, die von einem anderen Steuerelement verwendet wird, muss die als protected deklarierte Methode GetOwner der Kollektion überschrieben werden, damit die Methode im Objektinspektor angezeigt wird.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Ratchet Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Windows7 x86
D5 Ent., D2006 Arch.
BeitragVerfasst: Di 13.09.05 09:33 
Lesen müsste man können ^^
Dankeschön!