我需要阻止用户进入.在目录编辑框中输入的路径的末尾. 例如,路径不能是: C:\Program Files\InnoSetup. 如何验证目录编辑框输入,或者如何阻止用户输入.到路的尽头? 要自动删除目标目录末
例如,路径不能是:
C:\Program Files\InnoSetup.
如何验证目录编辑框输入,或者如何阻止用户输入.到路的尽头?
要自动删除目标目录末尾的所有点,可以使用此脚本.你没有回答我的问题,在路径末端找到一个点时你想做什么,所以我选择这种方式来显示.请注意,这将删除文件夹字符串末尾的所有点,因此从以下路径中删除: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;
当然还有另一种验证路径的方法,例如,让用户在结尾处输入带点的路径,并在移动到向导中的下一步时对其进行验证等.但是您没有指定您对如何编写验证问题的意思.