![]() |
SetLength: AV
Hi,
Das ganze kommt mir seltsam vor... Also das ganze sieht so aus:
Delphi-Quellcode:
Aufgerufen wirds im Hauptprogramm so:
TPlantation = class(TBuilding)
//... end; TPlantations = Array of TPlantation; TBuild = class private FOwner: TPlayer; procedure AddPlantation(AName: String); public constructor Create(AOwner: TPlayer); property Owner: TPlayer read FOwner; procedure Plantation(AName: String); destructor Destroy; override; end; TPlayer = class private FBuild: TBuild; FPlantations: TPlantations; //.. public constructor Create; property Build: TBuild read FBuild; property Plantations[Index: Integer]: TPlantation read GetPlantation write SetPlantation; //... end; constructor TPlayer.Create; begin inherited Create; FBuild := TBuild.Create(Self); end; procedure TBuild.Plantation(AName: String); begin if FOwner.Money >= UNIT_COSTS[UD_PLANTATION] then begin AddPlantation(AName); dec(FOwner.FMoney,UNIT_COSTS[UD_PLANTATION]); end else MessageDlg('Sie haben nicht genug Geld!',mtInformation,[mbOK],0); end; procedure TBuild.AddPlantation(AName: String); begin SetLength(FOwner.FPlantations,Length(FOwner.FPlantations)+1); // Es knallt with FOwner.FPlantations[High(FOwner.FPlantations)].Create(FOwner) do Name := AName; end;
Delphi-Quellcode:
Ich versteh das Problem nicht so ganz :|
Player := TPlayer.Create;
Player.Build.Plantation('Test'); //.. Da dürfte doch eigentlich nix schief gehn oder?... Gruß Neutral General |
Re: SetLength: AV
*räusper*
Erm... Die Sache hat sich erledigt.. :oops: Aus irgendeinem Grund hab ich an einer Stelle
Delphi-Quellcode:
statt
Instanz.Create;
Delphi-Quellcode:
geschrieben... :oops: :wall:
Instanz := Klasse.Create;
Gruß Neutral General |
Re: SetLength: AV
Wie war das mit Arrays und wiederholter sukzessiver Verlängerung :zwinker: ?
|
Re: SetLength: AV
:mrgreen:
Ach jooo^^ Ich hab immerhin ne Variable gespart *g* Was für Nachteile hat das jetzt eigentlich außer das es länger dauert? |
Re: SetLength: AV
Es verbraucht mehr Speicher :mrgreen: .
Für wirkliche Vorteile halte ich erweiterte Methoden (Insert, Remove), automatische Vergrößerung und OwnsObjects. Zitat:
|
Re: SetLength: AV
Ehm vergiss es :mrgreen:
Thx für die Tipps^^ |
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:49 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-2025 by Thomas Breitkreuz