要编码的组合框值
Combobox value to code
我是 Pascal 的新手,我已经读过一些关于它的资料,但对我来说仍然很难。我想创建一个简单的密码生成器,并调整字符数。
我找到了一个可以为我生成随机密码的函数,它是这样的:
function RandomPassword(PLen: Integer): string;
var
str: string;
begin
Randomize;
//string with all possible chars
str := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
Result := '';
repeat
Result := Result + str[Random(Length(str)) + 1];
until (Length(Result) = PLen)
end;
这是将字符串打印到备忘录的代码:
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Caption := RandomPassword(10);
end;
我还有一个 TComboBox,我想使用组合框中的值来选择字符数 (6-32)。在这种情况下,字符数是 10,但我想使用 Combobox 中的值而不是预先确定的数字。谁能帮我?非常感谢!
您可以 select 这样的组合框值:
RandomPassword(StrToInt(ComboBox.Items[ComboBox.ItemIndex]))
ComboBox.ItemIndex
returns select 组合框项的索引
ComboBox.Items[]
用于 select 组合框中的项目。
使用 StrToInt()
是因为组合框值是一个字符串,您必须将其更改为整数
我是 Pascal 的新手,我已经读过一些关于它的资料,但对我来说仍然很难。我想创建一个简单的密码生成器,并调整字符数。
我找到了一个可以为我生成随机密码的函数,它是这样的:
function RandomPassword(PLen: Integer): string;
var
str: string;
begin
Randomize;
//string with all possible chars
str := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
Result := '';
repeat
Result := Result + str[Random(Length(str)) + 1];
until (Length(Result) = PLen)
end;
这是将字符串打印到备忘录的代码:
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Caption := RandomPassword(10);
end;
我还有一个 TComboBox,我想使用组合框中的值来选择字符数 (6-32)。在这种情况下,字符数是 10,但我想使用 Combobox 中的值而不是预先确定的数字。谁能帮我?非常感谢!
您可以 select 这样的组合框值:
RandomPassword(StrToInt(ComboBox.Items[ComboBox.ItemIndex]))
ComboBox.ItemIndex
returns select 组合框项的索引
ComboBox.Items[]
用于 select 组合框中的项目。
StrToInt()
是因为组合框值是一个字符串,您必须将其更改为整数