AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

SetLength: AV

Ein Thema von Neutral General · begonnen am 16. Feb 2007 · letzter Beitrag vom 16. Feb 2007
Antwort Antwort
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

SetLength: AV

  Alt 16. Feb 2007, 16:27
Hi,

Das ganze kommt mir seltsam vor... Also das ganze sieht so aus:

Delphi-Quellcode:
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;
Aufgerufen wirds im Hauptprogramm so:

Delphi-Quellcode:
Player := TPlayer.Create;
Player.Build.Plantation('Test');
//..
Ich versteh das Problem nicht so ganz
Da dürfte doch eigentlich nix schief gehn oder?...

Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#2

Re: SetLength: AV

  Alt 16. Feb 2007, 16:52
*räusper*

Erm... Die Sache hat sich erledigt..
Aus irgendeinem Grund hab ich an einer Stelle

Instanz.Create; statt

Instanz := Klasse.Create; geschrieben...

Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Benutzerbild von Khabarakh
Khabarakh

Registriert seit: 18. Aug 2004
Ort: Brackenheim VS08 Pro
2.876 Beiträge
 
#3

Re: SetLength: AV

  Alt 16. Feb 2007, 17:47
Wie war das mit Arrays und wiederholter sukzessiver Verlängerung ?
Sebastian
Moderator in der EE
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#4

Re: SetLength: AV

  Alt 16. Feb 2007, 17:52

Ach jooo^^ Ich hab immerhin ne Variable gespart *g*

Was für Nachteile hat das jetzt eigentlich außer das es länger dauert?
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Benutzerbild von Khabarakh
Khabarakh

Registriert seit: 18. Aug 2004
Ort: Brackenheim VS08 Pro
2.876 Beiträge
 
#5

Re: SetLength: AV

  Alt 16. Feb 2007, 18:06
Es verbraucht mehr Speicher .
Für wirkliche Vorteile halte ich erweiterte Methoden (Insert, Remove), automatische Vergrößerung und OwnsObjects.
Zitat von Neutral General:
Ich hab immerhin ne Variable gespart *g*
?
Sebastian
Moderator in der EE
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#6

Re: SetLength: AV

  Alt 16. Feb 2007, 18:09
Ehm vergiss es

Thx für die Tipps^^
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:25 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz