为什么我的代码不显示我的 TButton 数组?
Why my code doesn't show my TButton's array?
我正在用 c++ builder 社区版制作一个简单的刽子手游戏,我的游戏由代表字母的按钮组成,如果字母没有出现在单词中,你就会失去生命,依此类推在...
但是,如果我为 abcedary 中的每个字母制作一个 TButton,我认为这有点重复我的代码。所以我决定制作一个 TButton 数组,令我惊讶的是,当我对所有内容进行编码并且它们中的任何一个都出现在我的表单中时:c。
如果有人能帮我一点忙我会很开心哈哈
Tgameclass...
class Tgame : public TForm
{
__published: // IDE-managed Components
TText *word;
private: // User declarations
TButton* chars[23];
public: // User declarations
__fastcall Tgame(TComponent* Owner);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
};
以及构造函数实现...
for(int i = 0; i < 23; ++i) {
this->chars[i] = new TButton(this);
this->chars[i]->Height = 33;
this->chars[i]->Width = 49;
this->chars[i]->Position->X = startX;
this->chars[i]->Position->Y = startY;
startX += difX;
startY += difY;
this->chars[i]->Opacity = 1;
this->chars[i]->Visible = true;
this->chars[i]->Text = "A";
}
您构建 TButton
设置其所有者(负责删除它的组件)。
this->chars[i] = new TButton(this);
但是您没有设置它的 Parent
,这是 TButton
将在其中直观显示的组件。所以,添加这一行:
this->chars[i]->Parent = this;
注意:Opacity
和 Visible
的默认值为 1
和 true
,因此您无需明确设置它们。
我正在用 c++ builder 社区版制作一个简单的刽子手游戏,我的游戏由代表字母的按钮组成,如果字母没有出现在单词中,你就会失去生命,依此类推在... 但是,如果我为 abcedary 中的每个字母制作一个 TButton,我认为这有点重复我的代码。所以我决定制作一个 TButton 数组,令我惊讶的是,当我对所有内容进行编码并且它们中的任何一个都出现在我的表单中时:c。 如果有人能帮我一点忙我会很开心哈哈
Tgameclass...
class Tgame : public TForm
{
__published: // IDE-managed Components
TText *word;
private: // User declarations
TButton* chars[23];
public: // User declarations
__fastcall Tgame(TComponent* Owner);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
};
以及构造函数实现...
for(int i = 0; i < 23; ++i) {
this->chars[i] = new TButton(this);
this->chars[i]->Height = 33;
this->chars[i]->Width = 49;
this->chars[i]->Position->X = startX;
this->chars[i]->Position->Y = startY;
startX += difX;
startY += difY;
this->chars[i]->Opacity = 1;
this->chars[i]->Visible = true;
this->chars[i]->Text = "A";
}
您构建 TButton
设置其所有者(负责删除它的组件)。
this->chars[i] = new TButton(this);
但是您没有设置它的 Parent
,这是 TButton
将在其中直观显示的组件。所以,添加这一行:
this->chars[i]->Parent = this;
注意:Opacity
和 Visible
的默认值为 1
和 true
,因此您无需明确设置它们。