I have an array which I need to read the first value from the array and then read the following values once used.:
我有一个数组,我需要从数组中读取第一个值,然后在使用后读取以下值:
type
TMyCardRecord = record
CardSet:integer;
CardValue:integer;
CardPicture:TBitmap;
end;
Var
PlayerCards : array[1..12] of TMyCardRecord;
procedure TForm2.StartClick(Sender: TObject); //Start New Game Button
var
duplicate : boolean;
pc,p,i : integer;
y, filename : String;
begin
FileName:=('S1.bmp'); ;
for i := 1 to 12 do
begin
y := (playercards[i]+filename);
image1.Picture.LoadFromFile(y);
end;
When i try to add playercards[i]+filename
it says incompatible types: string
and TMyCardRecord
.
当我尝试添加playercards [i] + filename时,它表示不兼容的类型:string和TMyCardRecord。
How can i make it so that the value playercards[i]
is compatible? the playercards
array contains values which are based on their assigned image. I need the value to be converted to an integer
to work I think.
我怎样才能使值playercards [i]兼容? playercards数组包含基于其指定图像的值。我想要将值转换为整数才能工作。
1 个解决方案
#1
4
playercards[i]
is an instance of TMyCardRecord
. You are trying to add a a string to this instance of TMyCardRecord
. This addition of a string and a custom type is not defined.
That is what "incompatible types" means - Delphi doesn't have a clue how it can add a string and a record, because they're entirely different things, and addition between them is not defined.
playercards [i]是TMyCardRecord的一个实例。您正在尝试向此TMyCardRecord实例添加一个字符串。未定义此字符串和自定义类型的添加。这就是“不兼容类型”的含义 - 德尔福不知道如何添加字符串和记录,因为它们完全不同,并且它们之间的添加没有定义。
What you apparently want, is a file name based upon the specific card.
You need to retrieve the values that you want in the filename - probably the value of the card and the suit (CardValue
and CardSet
). Then you need to convert these to strings. You can use the IntToStr
command for this.
So: IntToStr(playercards[i].CardValue)
and IntToStr(playercards[i].CardSet)
.
您显然想要的是基于特定卡的文件名。您需要在文件名中检索所需的值 - 可能是卡片和套装(CardValue和CardSet)的值。然后你需要将这些转换为字符串。您可以使用IntToStr命令。所以:IntToStr(playercards [i] .CardValue)和IntToStr(playercards [i] .CardSet)。
The easiest way to go about this, is to create a function that takes these values and turns them into a string.
Then you add that string to filename
.
最简单的方法是创建一个获取这些值并将它们转换为字符串的函数。然后将该字符串添加到filename。
#1
4
playercards[i]
is an instance of TMyCardRecord
. You are trying to add a a string to this instance of TMyCardRecord
. This addition of a string and a custom type is not defined.
That is what "incompatible types" means - Delphi doesn't have a clue how it can add a string and a record, because they're entirely different things, and addition between them is not defined.
playercards [i]是TMyCardRecord的一个实例。您正在尝试向此TMyCardRecord实例添加一个字符串。未定义此字符串和自定义类型的添加。这就是“不兼容类型”的含义 - 德尔福不知道如何添加字符串和记录,因为它们完全不同,并且它们之间的添加没有定义。
What you apparently want, is a file name based upon the specific card.
You need to retrieve the values that you want in the filename - probably the value of the card and the suit (CardValue
and CardSet
). Then you need to convert these to strings. You can use the IntToStr
command for this.
So: IntToStr(playercards[i].CardValue)
and IntToStr(playercards[i].CardSet)
.
您显然想要的是基于特定卡的文件名。您需要在文件名中检索所需的值 - 可能是卡片和套装(CardValue和CardSet)的值。然后你需要将这些转换为字符串。您可以使用IntToStr命令。所以:IntToStr(playercards [i] .CardValue)和IntToStr(playercards [i] .CardSet)。
The easiest way to go about this, is to create a function that takes these values and turns them into a string.
Then you add that string to filename
.
最简单的方法是创建一个获取这些值并将它们转换为字符串的函数。然后将该字符串添加到filename。