Peter Kiers
asked on
Force the user to put text in the inputquery.
Hi,
I have this procedure below where the user can set his password twice
in 2 inputqueries, that uses a function to make sure that the user can not
send an empty password. So it force the user to put something in the input-
queries.
procedure TPropertiesDlg.PswChkBxCli ck(Sender: TObject);
var
InputStr1 : string;
InputStr2 : string;
begin
if PswChkBx.Checked then
begin
InputStr1 := GetInput('Password', 'Please enter new password:'); <========
if InputStr1 <> '' Then
begin
InputStr2 := GetInput('Password', 'Please confirm new password:'); <========
if InputStr2 <> '' then
begin
if InputStr1 <> InputStr2
then showmessage('The confirmation password was not correct. Password is unchanged.')
else
begin
if MainForm.SetPassword(Input Str2)
Then showmessage('Password successfully changed.')
Else ShowMessage('Password could not be changed!');
Exit;
end;
end;
end;
end;
MainForm.SetPassword('');
PswChkBx.Checked:=False;
end;
function TPropertiesDlg.GetInput(aC aption, aPrompt: String): String;
var
ok: Boolean;
begin
Result := '';
repeat
PostMessage(Handle, InputBoxMessage, 0, 0);
ok := InputQuery(aCaption, aPrompt, Result);
if ok and (Result = '') THEN
showmessage ('Please enter a password.');
until(not ok or (Result <> ''));
end;
In this procedure below the programm looks if a database is protected
or not. If it does an inputquery appears where the user can enter
his/her password. But I want to use the same function in this procedure also.
So when the database is protected and the inputquery appears. The user can not
press the OK-button if the editfield of the inputquery is empty.
procedure TMainform.OpenDatabase;
var
i: integer;
begin
if not IsLogin('') then
begin
PostMessage(Handle, InputBoxMessage, 0, 0);
if not IsLogin(InputBox('Password ', 'Please enter password:', '')) then <=========
begin
showmessage('Invalid Password');
Exit;
end;
end;
with PageControl1 do for i:=Pagecount -1 downto 0 do pages[i].Free;
ADOTable1.Open;
ADOTabs.Open;
LoadTree;
end;
Who knows the answer and is willing to help me?
Greetings,
Peter Kiers
I have this procedure below where the user can set his password twice
in 2 inputqueries, that uses a function to make sure that the user can not
send an empty password. So it force the user to put something in the input-
queries.
procedure TPropertiesDlg.PswChkBxCli
var
InputStr1 : string;
InputStr2 : string;
begin
if PswChkBx.Checked then
begin
InputStr1 := GetInput('Password', 'Please enter new password:'); <========
if InputStr1 <> '' Then
begin
InputStr2 := GetInput('Password', 'Please confirm new password:'); <========
if InputStr2 <> '' then
begin
if InputStr1 <> InputStr2
then showmessage('The confirmation password was not correct. Password is unchanged.')
else
begin
if MainForm.SetPassword(Input
Then showmessage('Password successfully changed.')
Else ShowMessage('Password could not be changed!');
Exit;
end;
end;
end;
end;
MainForm.SetPassword('');
PswChkBx.Checked:=False;
end;
function TPropertiesDlg.GetInput(aC
var
ok: Boolean;
begin
Result := '';
repeat
PostMessage(Handle, InputBoxMessage, 0, 0);
ok := InputQuery(aCaption, aPrompt, Result);
if ok and (Result = '') THEN
showmessage ('Please enter a password.');
until(not ok or (Result <> ''));
end;
In this procedure below the programm looks if a database is protected
or not. If it does an inputquery appears where the user can enter
his/her password. But I want to use the same function in this procedure also.
So when the database is protected and the inputquery appears. The user can not
press the OK-button if the editfield of the inputquery is empty.
procedure TMainform.OpenDatabase;
var
i: integer;
begin
if not IsLogin('') then
begin
PostMessage(Handle, InputBoxMessage, 0, 0);
if not IsLogin(InputBox('Password
begin
showmessage('Invalid Password');
Exit;
end;
end;
with PageControl1 do for i:=Pagecount -1 downto 0 do pages[i].Free;
ADOTable1.Open;
ADOTabs.Open;
LoadTree;
end;
Who knows the answer and is willing to help me?
Greetings,
Peter Kiers
Also to make it more clear you start with your "mybutton.enabled:=false" and the code on the "onkeypress" on your form should be like that:
procedure TMainForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
myButton.enabled:=(Trim(inputStr1)=Trim(inputStr2));
end;
// or the more easy to understand but less code-optimised is this
procedure TMainForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Trim(inputStr1)=Trim(inputStr2) then
myButton.enabled:=true
else
myButton.enabled:=false;
end;
ASKER
This is not what I want. My code works perfect. The only thing i want is the use
the same GetInput-function check in the OpenDatabase-procedure.
Peter
the same GetInput-function check in the OpenDatabase-procedure.
Peter
you need an initialized instance of TPropertiesDlg before calling the OpenDataBase
let's say
frmPropertyDlg:TProperties Dlg;
let's say
frmPropertyDlg:TProperties
procedure TMainform.OpenDatabase;
var
i: integer;
begin
if not IsLogin('') then
begin
PostMessage(Handle, InputBoxMessage, 0, 0);
if not IsLogin(frmPropertyDlg.GetInput('Password', 'Please enter password:')) then
begin
showmessage('Invalid Password');
Exit;
end;
end;
with PageControl1 do for i:=Pagecount -1 downto 0 do pages[i].Free;
ADOTable1.Open;
ADOTabs.Open;
LoadTree;
end;
I would recommend that this GetInput function be a member of your main form instead of your property form to be sure it's available always.
ASKER
Hi,
I have declared the same function in the mainform also.
So i quess it have to be like this:
procedure TMainform.OpenDatabase;
var
i: integer;
begin
if not IsLogin('') then
begin
PostMessage(Handle, InputBoxMessage, 0, 0);
if not IsLogin(GetInput('Password ', 'Please enter password:')) then
begin
showmessage('Invalid Password');
Exit;
end;
end;
with PageControl1 do for i:=Pagecount -1 downto 0 do pages[i].Free;
ADOTable1.Open;
ADOTabs.Open;
LoadTree;
end;
I have declared the same function in the mainform also.
So i quess it have to be like this:
procedure TMainform.OpenDatabase;
var
i: integer;
begin
if not IsLogin('') then
begin
PostMessage(Handle, InputBoxMessage, 0, 0);
if not IsLogin(GetInput('Password
begin
showmessage('Invalid Password');
Exit;
end;
end;
with PageControl1 do for i:=Pagecount -1 downto 0 do pages[i].Free;
ADOTable1.Open;
ADOTabs.Open;
LoadTree;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have tested it and it works for me....
Greetings, Peter Kiers
Greetings, Peter Kiers
change
if InputStr1 <> '' Then
to
if Trim(InputStr1) <> '' Then
Now if you don't want to press the OK button, have it initially disabled (mybutton.enabled:=false;)
When the trimmed passwords match then change (mybutton.enabled:=true;)
To have this change your "onkeypress" of your FORM to check the textfields if they match everytime you have a key pressed. To make keypressed fire on the form regardless on what control you are typing you have to set the property of your form "keypreview" to true.
Other than that, I don't understand where your problem is.