Delphi-PRAXiS
Seite 2 von 3     12 3      

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 Komponenten-Entwicklung: xyz[i].name (https://www.delphipraxis.net/14892-komponenten-entwicklung-xyz%5Bi%5D-name.html)

Jens Schumann 17. Jan 2004 16:51

Re: Komponenten-Entwcilung: xyz[i].name
 
Hallo,
klar geht das. Da Du aber scheinbar Deinen Source nicht posten willst müsste ich jetzt
ein Beispiel selber machen. Also bitte zeige Deinen Source

lkz633 17. Jan 2004 16:54

Re: Komponenten-Entwcilung: xyz[i].name
 
Danke für deine Hilfe, hier mal der Source:

Code:
type tcontactitem = class
  private
    Fname: string;
    procedure Setname(const Value: string);
  public
    property name: string read Fname write Setname;
end;


type tContactItemList = class(TList)
  private
    function GetItems(Index: Integer): tcontactitem;
    procedure SetItems(Index: Integer; const Value: tcontactitem);
  public
    property Items[Index : Integer]: tcontactitem read GetItems write SetItems;default;
end;


type
  Toutextract = class(TComponent)
  private
    procedure SetOutlookVersion(const Value: outlookversion);
    function Getcontacts(Index: Integer): TContactItemlist;
    procedure Setcontacts(Index: Integer; const Value: TContactItemlist);
  protected
  public
    constructor create(AOwner: TComponent); override;
    destructor destroy;
    property contacts[Index : Integer]: TContactItemList read Getcontacts write Setcontacts;
  end;

Jens Schumann 17. Jan 2004 16:57

Re: Komponenten-Entwcilung: xyz[i].name
 
Hallo,
da scheint so einiges durcheinander zu sein. Ich bastel Dir mal ein Beispiel.
Bis gleich.

Jens Schumann 17. Jan 2004 17:10

Re: Komponenten-Entwcilung: xyz[i].name
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo,
studiere mal das Beispiel

lkz633 17. Jan 2004 17:44

Re: Komponenten-Entwcilung: xyz[i].name
 
Ich steh anscheinend grad auf dem Schlauch da ich es immer noch nicht hinbekomme:

Habe jetzt das hier:
Code:
type tcontactitem = class
  private
    Fname: string;
  public
    property name: string read Fname write Fname;
end;

type
  Toutextract = class(TComponent)
  private
    FList : TList;
    function Getcontacts(Index: Integer): TContactItem;
    function GetCount: Integer;
    procedure Setcontacts(Index: Integer; const Value: TContactItem);
  public
    constructor create(AOwner: TComponent); override;
    destructor destroy;override;
    property contacts[Index : Integer]: TContactItem read Getcontacts write Setcontacts; default;
    property Count : Integer read GetCount;
  end;
Also
Code:
Komponente.contacts[i].name
klappt jetzt, leider aber auch
Code:
Komponente.contacts.name
Warum?

Ausserdem sollte
Code:
komponente.contacts.count
funktionieren, es geht natürlich nicht sondern nur
Code:
komponente.count
aber wo soll ich denn sonst diese Deklaration hintun? Ich will ja auch nicht
Code:
contacts[1].count
Danke für deine Geduld und Mühe
lkz633

Jens Schumann 17. Jan 2004 17:55

Re: Komponenten-Entwcilung: xyz[i].name
 
Zitat:

Zitat von lkz633
Ausserdem sollte
Code:
komponente.contacts.count
funktionieren, es geht natürlich nicht

Das kann auch nicht funktionieren, da contacts vom Type Tcontactitem ist und Tcontactitem keine
Count property hat.

Zitat:

Zitat von lkz633
Code:
Komponente.contacts.name

Warum das klappt ist mir schleierhaft.

Wenn Du Deinen Code komplett (also mit Methoden usw) posten würdest schau ich mir das noch einmal an.

lkz633 17. Jan 2004 17:58

Re: Komponenten-Entwcilung: xyz[i].name
 
Zitat:

Zitat von Jens Schumann
Zitat:

Zitat von lkz633
Ausserdem sollte
Code:
komponente.contacts.count
funktionieren, es geht natürlich nicht

Das kann auch nicht funktionieren, da contacts vom Type Tcontactitem ist und Tcontactitem keine
Count property hat.

Genau dies will ich aber ja erreichen, deswegen meine ganzen Umwege mit einer zusätzlichen TContactList, da diese dann eine Count Eigenschaft hätte.

Ich würde also gerne sowohl

Code:
Komponnete.contacts[i].name;
als auch
Code:
Komponente.contacts.count
erreichen.

Geht dies dann gar nicht?

Gruss lkz633

Jens Schumann 17. Jan 2004 18:07

Re: Komponenten-Entwicklung: xyz[i].name
 
Hallo,
da Du keine Source rausrückst muss ich jetzt mit meinen Beispiel kommen

Delphi-Quellcode:
  TMyListItems = class;

  TMyListItem = class(TObject)
  private
    function GetCount: Integer;
  private
    FName: String;
    FMyListItems : TMyListItems;
  public
    constructor Create(MyListItems : TMyListItems);
    property Count : Integer read GetCount;
    property Name : String read FName write FName;
  end;

...

function TMyListItems.Add(const aName : String): TMyListItem;
begin
  Result:=TMyListItem.Create(Self);
  Result.Name:=aName;
  FList.Add(Result);
end;

...

function TMyListItem.GetCount: Integer;
begin
  If Assigned(FMyListItems) then
    Result:=FMyListItems.Count
    else
      Result:=-1; // Zeigt dass das TMyListItem in keiner Liste hängt
end;
Der Trick ist , in jedem TMyListItem sich den entsprechenden TMyListItems zu merken.

lkz633 17. Jan 2004 18:13

Re: Komponenten-Entwicklung: xyz[i].name
 
Aber dann kann ich doch immer noch nicht contacts.count machen oder?

Hier mein Code(mehr hab ich seit 3 Stunden nicht zustandegebracht :wall: )

Code:
type tcontactitem = class
  private
    Fname: string;
  public
    property name: string read Fname write Fname;
end;


type
  Toutextract = class(TComponent)
  private
    FList : TList;
    function Getcontacts(Index: Integer): TContactItem;
    function GetCount: Integer;
    procedure Setcontacts(Index: Integer; const Value: TContactItem);
  public
    constructor create(AOwner: TComponent); override;
    destructor destroy;override;
    property contacts[Index : Integer]: TContactItem read Getcontacts write Setcontacts; default;
    property Count : Integer read GetCount;
   end;

Jens Schumann 17. Jan 2004 18:16

Re: Komponenten-Entwicklung: xyz[i].name
 
Hallo,
Du hast mich immer noch nicht verstanden. Ich möchte die komplette unit !!!
Auch den Code für die Methoden !!! D.h. ich möchte z.B. sehen wie Du den Setter Setcontacts realisiert hast. Damit das ganze mal richtig testen kann.


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:28 Uhr.
Seite 2 von 3     12 3      

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