English 中文(简体)
在 Delphi 中索引化的属性 - 初学者正在使游戏对象中多个玩家对象可以访问
原标题:Indexed property in Delphi - beginner is making multiple Player objects accessible in a Game object
  • 时间:2012-05-26 11:10:59
  •  标签:
  • delphi

我是初学者戴尔菲的用户。我有这个循环,而不是只有一个玩家(玩家1),我希望有许多玩家,写成玩家。我编辑了班级,让我添加

   while i < FMyPlayers.TeamCount do
    begin
       buttonSelected := MessageDlg( Placeing Unit:  +FMyPlayers.Player[i].Values[ name ]+ . ,mtError, mbOKCancel, 0);
          if buttonSelected = mrCancel then exit;
       imageyouwant.LoadFromFile(thisdir+ char +FMyPlayers.Player[i].Values[ picon ]);
       Hexmap1.ImageAHex(ImageYouWant , bsSolid, position);
       FMyPlayers.Player[i].Add( pos= +inttostr(position.x)+inttostr(position.Y));
       FMyPlayers.PlaceUnit := false;
    end;

但是现在在我的班上,我犯错

      property Player: array[1..20] of TStringList read P;

我的MYPPlayle类如下:

TPlayers = class
Private
  p : array[1..20] of TStringList;
  FPlaceUnit: Boolean;
  FTeamCount: Integer;
Public
  property Player: array[1..20] of TStringList read P;
  property PlaceUnit : Boolean read FPlaceUnit write FPlaceUnit;
  procedure AddPlayer (PlayerNo : integer; player : String);
  property TeamCount : Integer read FTeamCount write FTeamCount;

 constructor Create;   virtual;
End;
最佳回答

看来你的班级不是从头开始设计的

uses Generics.Collections;


TPlayer = class
 // add player related properties & routines here
end;

TGame = class
 protected  
   // all fields go here
   FPlayers : TObjectList<TPlayer>;

 public

   function AddPlayer(settings : TStringList) : TPlayer; 

   property Player[index:Integer]:TPlayer read GetPlayer;
end;
问题回答

暂无回答




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签