![]() |
AW: TCollection & TCollectionitem Tutorial
Ok, ich hab hier ein Beispiel von embarcadero:
Delphi-Quellcode:
Was ich nicht verstehe, wenn ich Panels.Add Aufrufe...muss ich da kein Parameter übergeben?
procedure TForm1.Button1Click(Sender: TObject);
var PanelIndex : Integer; begin with StatusBar1 do begin Panels.BeginUpdate; PanelIndex := StatusBar1.Panels.Count - 1; try Panels.Add; Inc(PanelIndex); Panels.Items[PanelIndex].Text := 'Panel' + IntToStr(PanelIndex); finally Panels.EndUpdate; end; end; end; |
AW: TCollection & TCollectionitem Tutorial
@der schöne Günther...das ist die ganze aufgabenbeschreibung
|
AW: TCollection & TCollectionitem Tutorial
Zitat:
Wie immer hilft ein Blick in den Quelltext:
Delphi-Quellcode:
function TCollection.Add: TCollectionItem;
begin Result := FItemClass.Create(Self); Added(Result); end; |
AW: TCollection & TCollectionitem Tutorial
Zitat:
Zitat:
|
AW: TCollection & TCollectionitem Tutorial
Oh habe ich übersehen, muss leider mit dem Handy tippen.
A component that organized the Threads and their Output a: Use TCollection with its methods "Changed" and "Update" |
AW: TCollection & TCollectionitem Tutorial
Also wird mit der Update Methode einfach ein neues Item erzeugt und an die letzte Stelle der Liste eingefügt?
|
AW: TCollection & TCollectionitem Tutorial
Zitat:
|
AW: TCollection & TCollectionitem Tutorial
Zitat:
|
AW: TCollection & TCollectionitem Tutorial
Probiere das folgende Konsolenprogramm mal aus, vielleicht hilft dir das weiter:
Delphi-Quellcode:
program Project3;
{$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, System.Classes; type TMyCollectionItem = class(TCollectionItem) private // hier kannst du auch eigene Felder und Methoden definieren protected function GetDisplayName: string; override; end; TMyCollection = class(TCollection) protected procedure Update(Item: TCollectionItem); override; procedure SetItemName(Item: TCollectionItem); override; procedure Notify(Item: TCollectionItem; Action: TCollectionNotification); override; public procedure BeginUpdate; override; procedure EndUpdate; override; end; procedure TMyCollection.BeginUpdate; begin inherited; Writeln('BeginUpdate'); end; procedure TMyCollection.EndUpdate; begin inherited; Writeln('EndUpdate'); end; procedure TMyCollection.Notify(Item: TCollectionItem; Action: TCollectionNotification); begin inherited; case Action of cnAdded: Writeln(Item.DisplayName + ' added'); cnExtracting: Writeln(Item.DisplayName + ' extracing'); cnDeleting: Writeln(Item.DisplayName + ' deleting'); end; end; procedure TMyCollection.SetItemName(Item: TCollectionItem); begin inherited; Writeln(Item.DisplayName + ' ItemName'); end; procedure TMyCollection.Update(Item: TCollectionItem); begin inherited; if Assigned(Item) then begin // Ein einzelnes Item wurde befummelt Writeln(Item.DisplayName + ' updated'); end else // wenn Item = nil, dann ist die ganze Collection betroffen end; function TMyCollectionItem.GetDisplayName: string; begin Result := 'HuiBui: ' + IntToStr(Self.ID); end; procedure Main; var MyCollection: TMyCollection; MyItem: TCollectionItem; I: Integer; Something: string; begin MyCollection := TMyCollection.Create(TMyCollectionItem); try MyCollection.BeginUpdate; try for I := 0 to 10 - 1 do begin MyItem := MyCollection.Add; end; finally MyCollection.EndUpdate; end; Something := ''; for I := 0 to MyCollection.Count - 1 do begin MyItem := MyCollection.Items[I]; Something := Something + MyItem.DisplayName + ' '; end; Writeln(Something); MyCollection.Items[5].DisplayName := 'asdf'; MyCollection.Delete(5); finally MyCollection.Free; end; end; begin try Main; Readln; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. end. |
AW: TCollection & TCollectionitem Tutorial
Okay super, vielen danke ..das nehm ich mir jetzt mal genau unter die Lupe.
Create and destroy Threads Start and Stop Threads Configure the thread interval Print the Output of the Threads Aber mit Threads hatte ich echt noch nie etwas zu tun, deswegen hab ich das erstmal hinten angestellt |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:34 Uhr. |
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 by Thomas Breitkreuz