小编Qui*_*n96的帖子

我想通过单击另一个表单Delphi 7上的按钮来更改一个表单上标签的标题

我必须为学校开展预测游戏.为了让2个随机队伍互相对战我在表格1上做了以下代码:

procedure TfrmUserInput.FormCreate(Sender: TObject);
const
arrT1 : array[1..6] of string = ('Blue Bulls','Griquas','EP Kings','Sharks','Cheetahs','Valke');
arrT2 : array[1..6] of string = ('Lions','Pumas','Leopards','Western Province','Kavaliers','Eagles');
begin
Randomize;
sTeam1 := arrT1[Random(5)+1];
Randomize;
sTeam2 := arrT2[Random(5)+1];
lblT1Pred.Caption := (sTeam1 + ' predicted score :');
lblT2Pred.Caption := (sTeam2 + ' predicted score :');
rbTeam1.Caption := sTeam1;
rbTeam2.Caption := sTeam2;
end;
Run Code Online (Sandbox Code Playgroud)

在第二个表格中,我有以下内容:

procedure TfrmAdminInput.FormCreate(Sender: TObject);
begin
rbT1.Caption := sTeam1;
rbT2.Caption := sTeam2;
end;
Run Code Online (Sandbox Code Playgroud)

sTeam1和sTeam2是全局变量.

现在在第4个表单上,我点击一个按钮开始预测下一个游戏 - 因此我需要选择其他2个随机团队,起初我想创建重复数组并使用以下代码,但它给我一个问题'Undeclared identifier:lblT1Pred' - 这个问题对于lblT2Pred和第二个表单上的标签(rbT1.Caption和rbT2.Caption)以及表单1上的单选按钮标题是相同的.代码如下:

sTeam1 := arrT1[Random(5)+1];
sTeam2 := arrT2[Random(5)+1];
frmUserInput.lblT1Pred.Caption …
Run Code Online (Sandbox Code Playgroud)

forms delphi

0
推荐指数
1
解决办法
1703
查看次数

如何检查数据类型是否为数组?(C++)

所以我现在是一名学生并且已经进行了以下练习:编写一个在数组中打印元素的函数.数组通过参数发送到函数.如果此参数不是数组,则必须抛出类型invalid_argument的异常.在main()函数中测试函数.

所以我的代码目前如下:

#include <iostream>
#include <exception>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::invalid_argument;
using std::string;

template<class T>void printArray(T arr){
    try{
        arr.size();
    }
    catch(...){
        for (int i=0; i < sizeof(arr); i++){
            cout << arr[i] << endl;
        }
    }
    throw invalid_argument("Argument not of type array");
};

int main(){
    string arrChars[5] = {"1", "2", "3", "John", "5"};
    string s = "Jack";
    try{
        printArray(arrChars);
    }
    catch(invalid_argument &e){
        cout << "Error: " << e.what() << endl;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是在尝试了其他选项之后:

template<class …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
1755
查看次数

标签 统计

c++ ×1

delphi ×1

forms ×1