Olivier Olivier - 1 year ago 222
Pascal Question

Combobox value to code

I'm a Pascal newbie and I already read some stuff about it, but it is still pretty hard for me. I want to create a simple password generator, and adjust the number of characters.

I found a function that actually generates the random password for me, which is this:

function RandomPassword(PLen: Integer): string;
str: string;
//string with all possible chars
str := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
Result := '';
Result := Result + str[Random(Length(str)) + 1];
until (Length(Result) = PLen)

This is the code that prints the string to the Memo:

procedure TForm1.Button2Click(Sender: TObject);
Memo1.Caption := RandomPassword(10);

I also got a TComboBox, and I want to use the value from the combobox to chose the number of characters (6-32). The number of characters is in this case 10 but I want to use the value from the Combobox instead of a predetermined number. Who can help me? I'd appreciate it!

Answer Source

You can select the combobox value like this:


ComboBox.ItemIndex returns the index of select combobox item

ComboBox.Items[] is used to select a item in the combobox.

StrToInt() is used cause the combobox value is a string and you have to change it to integer

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download