BCB6:如何将表单的元素放入数组中?

发布于 2024-11-15 00:48:27 字数 142 浏览 7 评论 0原文

我正在 C++Builder6 中构建一个简单的游戏,并且我在 Form 上有 42 个 Image 对象...在启动时我希望禁用所有 Image 对象,所以我想知道我可以将它们全部放入一个数组中吗?简单地循环整个数组并使它们禁用?我知道一定有办法,但我只是编程新手:)

I'm building a simple game in C++Builder6 and I have 42 Image objects on a Form... At start-up I want all Image objects to be disabled, so I wonder can I put all of them in an array and simply loop thorough the entire array and make them Disabled? I know there must be a way, but I'm just new to programming :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漆黑的白昼 2024-11-22 00:48:27

您有多种选择。
第一:你可以声明

Image* array[40];

并动态构造图像。

for ( int i = 0 ; i < 40; ++i ) {
    image[i] = new Image(this); // where "this" is pointer to your form
    image[i]->Parent = this;

    // option below are optional
    image[i]->Height = 50;
    image[i]->Width = 50;
    image[i]->Left = 40;
    image[i]->Top = 100;
    image[i]->Tag = i;
    image[i]->OnClick = ButtonClick; // connect with method
}

第二个选项是声明

Image* array[40];

并手动设置所有值;

array[0] = Image1;
...
array[39] = Image40;

然后你将拥有数组中的所有图像,并且可以使用循环对所有图像执行某些操作

You have several options.
First: You can declare

Image* array[40];

And dynamically construct the image.

for ( int i = 0 ; i < 40; ++i ) {
    image[i] = new Image(this); // where "this" is pointer to your form
    image[i]->Parent = this;

    // option below are optional
    image[i]->Height = 50;
    image[i]->Width = 50;
    image[i]->Left = 40;
    image[i]->Top = 100;
    image[i]->Tag = i;
    image[i]->OnClick = ButtonClick; // connect with method
}

Second option is declare

Image* array[40];

and manually set all values;

array[0] = Image1;
...
array[39] = Image40;

Then you will have all image in array and you can use loop for doing something on all Image

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文