4

我需要防止用户.在目录编辑框中输入的路径末尾输入。

例如,路径不能是:

C:\Program Files\InnoSetup.

如何验证目录编辑框输入,或者如何防止用户进入.路径末尾?

4

1 回答 1

1

要自动删除目标目录末尾的所有点,您可以使用此脚本。您还没有回答我的问题,当在路径的尽头找到一个点时您想做什么,所以我选择了这种方式来显示。请注意,这将删除文件夹字符串末尾的所有点,因此从如下路径中删除:

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;

当然还有另一种验证路径的方法,例如,您可以让用户在最后输入带有点的路径,并在您进入向导的下一步等时验证它。但是您只是没有指定您要做什么意思是你如何写验证问题。

于 2012-10-17T10:17:13.190 回答