如何限制目录编辑框的用户输入? [英] How to restrict user input of the directory edit box?
问题描述
我需要防止用户在目录编辑框中输入的路径的末尾输入.
.
I need to prevent users from entering .
at the end of the path entered in the directory edit box.
例如,路径不能为:
C:\Program Files\InnoSetup.
如何验证目录编辑框的输入,或者如何防止用户在路径末尾输入.
?
How can I validate the directory edit box input, or how can I prevent users from entering .
to the end of the path ?
推荐答案
要自动删除目标目录末尾的所有点,可以使用此脚本.您尚未回答我的问题,即在路径末尾找到一个点时要做什么,所以我选择了这种方式来显示.请注意,这将删除文件夹字符串末尾的所有点,因此将从以下路径中删除:
To automatically delete all dots from the end of a target directory, you can use this script. You haven't answered my question, what you want to do when a dot is found at the end of the path, so I chose just this way to show up. Note that this will delete all dots from the end of a folder string, so from a path like:
C:\Program Files (x86)\My Program.....
此脚本制作:
C:\Program Files (x86)\My Program
这是脚本:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[code]
procedure OnDirEditChange(Sender: TObject);
var
S: string;
begin
S := WizardDirValue;
if (Length(S) > 0) and (S[Length(S)] = '.') then
begin
MsgBox('Last char(s) of the entered target folder is "."' + #13#10 +
'All "." chars from the end will be deleted!', mbInformation, MB_OK);
while (Length(S) > 0) and (S[Length(S)] = '.') do
Delete(S, Length(S), 1);
WizardForm.DirEdit.Text := S;
end;
end;
procedure InitializeWizard;
begin
WizardForm.DirEdit.OnChange := @OnDirEditChange;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
// this is just a paranoid event trigger, in case the DefaultDirName
// would be able to contain dots at the end, what can't at this time
if CurPageID = wpSelectDir then
OnDirEditChange(nil);
end;
当然,还有其他验证路径的方法,例如让用户输入最后带有点的路径,并在向导中转到下一步时进行验证等.但是,您只是没有指定如何编写验证的意思.问题.
There are of course another ways to validate the path, you can e.g. let the user enter the path with dots at the end and validate it when you move to the next step in the wizard etc. But you just didn't specified what do you mean with your how to write validation question.
这篇关于如何限制目录编辑框的用户输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!