3./ Password / Confirm on Exit
< Back – Một số ví dụ
A/. Password: tạo Password khi mở chương trình
Đặt Password bảo vệ. Khi chạy chương trình, sẽ hiện hộp thoại thông báo nhập Password, nếu đúng sẽ mở chương trình, nếu sau chương trình sẽ đóng lại
Tạo Password, sử dụng Dialog.PasswordInput
- Nhấn phải vào trang (Page1) > Properties > tab Script > On Show, nhập:
— the ‘correct’ password
real_password = “password”;— prompt the user to enter a password
user_password = Dialog.PasswordInput(“Password”, “Please enter the password: “, MB_ICONQUESTION);— compare the user’s password to the ‘correct’ password.
— If the user supplies the wrong password, exit the program.
if real_password ~= user_password then
Application.Exit();
endB./ Confirm on Exit: xác nhận trước khi đóng chương trìnhKhi nhấn nút Close (nút dấu chéo ở góc trên) của chương trình, hoặc các nút tự tạo để đóng chương trình sẽ hiện hộp thông báo xác nhận đóng chương trình - Nhấn Project > Global Functions, nhập
function QueryAllowProjectClose() –this function will be called when the program is exiting
confirmation = Dialog.Message(“Are you sure?”, “Are you sure that you want to exit?”, MB_YESNO, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
if confirmation == 6 then
— The yes button was pressed, allow program to close (return true)
return true;
else
— The yes button was NOT pressed, do NOT allow the program to close (Return false)
return false;
end
end - Ghi chú: Có thể phải dùng thêm Script đại khái như sau:
if QueryAllowProjectClose() then
Application.Exit();
end