Further to previous question, When I try to compile this I get the error incompatible type on this line:
Property player[i : integer] : TStringList read p;
I’m unsure why? Here is whole class:
unit Battle;
interface
uses
SysUtils,Dialogs,Classes,inifiles, StdCtrls;
type
TPlayers = class
Private
p : array[1..20] of TStringList;
FPlaceUnit: Boolean;
FTeamCount: Integer;
Public
Property player[i : integer] : 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;
{Host class}
THostPlayers = Class(TPlayers)
Private
FIsHost: string;
Public
constructor Create; override;
property IsHost : string read FIsHost write FIsHost;
End;
{Guest Class}
TGuestPlayers = Class(TPlayers)
Private
FIsGuest: string;
Public
constructor Create; override;
property IsGuest : string read FIsGuest write FIsGuest;
End;
implementation
uses
main;
{constructor}
constructor TPlayers.Create;
begin
p := TStringList.Create;
end;
constructor THostPlayers.Create;
begin
inherited; // Calls TPlayers.Create
IsHost := 'No';
PlaceUnit := true;
TeamCount :=0;
end;
constructor TGuestPlayers.Create;
begin
inherited; // Calls TPlayers.Create
IsGuest := 'No';
PlaceUnit := true;
TeamCount := 0;
end;
{ADD Player}
procedure TPlayers.AddPlayer(PlayerNo : integer; player : String);
var
CharINI : TIniFile;
begin
CharINI := Tinifile.Create(thisdir+'\char\charstats.ini');
CharINI.ReadSectionValues(player,player[PlayerNo]);
CharINI.Free;
end;
end.
First, the property ‘returns’ a TStringList and field p is an array of TStringlist so that’s why you get the incompatible types error.
You would expect that:
fixes this. But you can’t access array elements directly so you need a getter function: