Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Share Me

  • Please share this topic with your friends. Click any of the icons below:
  • Twitter
  • facebook
  • reddit
  • email

Strange behaviour in TElFileNameEdit.BtnClick

The Filedialog behave strang.
If you open the dialog with a set file, the dialog set the directory to the correct path.
If you change the directory and reopen the dialog, the first used directory is used instead of the directory of the actual file.

Please change following

var
  IssetIntern: Boolean;
begin
  ...

    else if (InitialDir = '') then
    begin
      IsSetIntern := True;
      SetInitialDir(LMDExtractFilePath(AFileName));
    end;

....

    FileDlg.FileName := LMDExtractFileName(AFileName);  // No change of AFileName-Variable

....

    // Reset to Initial Value
    if IsSetIntern and (LMDExtractFilePath(AFileName) = InitialDir) then
      SetInitialDir('');



Comments

  • 1 Comment sorted by Votes Date Added
  • Hi,

    I've changed the code of mentioned method to the following:

    procedure TElFileNameEdit.BtnClick(Sender: TObject);
    var
      AFileName: TLMDString;
      APath:     TLMDString;
      AParams:   TLMDString;
    begin
      if not ReadOnly then
      begin
        AParams := '';
        AFileName := Text;

        if ParseParameters and not FileExists(AFileName) and
           (Trim(AFileName) <> '') then
        begin
          GetParamStr(PLMDChar(Text), AFileName);
          if (Pos('"', Text) > 1) and (Length(Text) - Length(AFileName) > 2) then
            AParams := Copy(Text, Length(AFileName) + 1, Length(Text));
        end;

        APath := ExtractFilePath(AFileName);
        if DirectoryExists(APath) then
          InitialDir := APath;

        FileDlg.FileName := ExtractFileName(AFileName);
        FileDlg.Title := DialogTitle;

        TriggerBeforeDialogExecute(FileDlg);

        if FileDlg.Execute then
        begin
          Text := FileDlg.FileName + AParams;
          Modified := true;
          TriggerDialogExecute;
          Change;
        end;
      end;
    end;

    Hope, this will work correctly.
Sign In or Register to comment.