"Does't work" is not a very descriptive error message...
Your code by itself looks correct. Depending on what else is in your source file, you may have a compilation error, though, because GeneratePassword is called before it is implemented. Move the code of function "GeneratePassword" before "TForm.ButtonGenerateClick"