Einzelnen Beitrag anzeigen

Relicted

Registriert seit: 24. Jan 2006
Ort: Iserlohn
646 Beiträge
 
Delphi 10.4 Sydney
 
#15

Re: Wie arbeite ich mit "Klassen"-Listen

  Alt 25. Apr 2008, 15:49
ich habe mal kurz mein minitool angeschmissen.

Delphi-Quellcode:
unit SatzList;
                                                                                        
interface
                                                                                        
uses
  Contnrs,
  Satz;
                                                                                        
type
  TSatzList = class( TObjectList )
  protected
    //* Protected functions..
    function GetItem(Index: Integer): TSatz; reintroduce;
    procedure SetItem(Index: Integer; const Value: TSatz); reintroduce;
  public
    //* Constructors.. don't forget to call "inherited"
    //constructor Create; overload;
    //constructor Create(AOwnsObjects: Boolean); overload;
                                                                                        
    //* List Functions & Propertys
    function Add(AObject: TSatz): Integer; reintroduce;
    function Extract(Item: TSatz): TSatz; reintroduce;
    function Remove(AObject: TSatz): Integer; reintroduce;
    function IndexOf(AObject: TSatz): Integer; reintroduce;
    procedure Insert(Index: Integer; AObject: TSatz); reintroduce;
    function First: TSatz; reintroduce;
    function Last: TSatz; reintroduce;
                                                                                        
    property Items[Index: Integer]: TSatz read GetItem write SetItem; default;
                                                                                        
    //* Insert your own functions here...
  end;
                                                                                        
implementation
                                                                                        
{ TSatzList }                                                                  
                                                                                        
function TSatzList.Add(AObject: TSatz): Integer;
begin
  result := inherited Add( AObject );
end;
                                                                                        
function TSatzList.Extract(Item: TSatz): TSatz;
begin
  result := inherited Extract( Item ) as TSatz;
end;
                                                                                        
function TSatzList.First: TSatz;
begin
  result := inherited First as TSatz;
end;
                                                                                        
function TSatzList.GetItem(Index: Integer): TSatz;
begin
  result := inherited GetItem( Index ) as TSatz;
end;
                                                                                        
function TSatzList.IndexOf(AObject: TSatz): Integer;
begin
  result := inherited IndexOf( AObject );
end;
                                                                                        
procedure TSatzList.Insert(Index: Integer; AObject: TSatz);
begin
  inherited Insert(Index,AObject);
end;
                                                                                        
function TSatzList.Last: TSatz;
begin
  result := inherited Last as TSatz;
end;
                                                                                        
function TSatzList.Remove(AObject: TSatz): Integer;
begin
  result := inherited Remove(AObject);
end;
                                                                                        
procedure TSatzList.SetItem(Index: Integer;
  const Value: TSatz);
begin
  inherited SetItem(Index,Value);
end;
                                                                                        
end.
That's the way i alway do. eine typisierte TObjectList. Finde ist das einfachste was man machen kann.
habe mir das tool "mal eben" geschrieben weil ich keine lust auf das dauernde ersetzen etc hatte. basisklasse eingeben start drücken fertig werden daher mal schnell die "lösung" bereitstell

gruß
reli
  Mit Zitat antworten Zitat