This forum is temporaily read-only. All existing discussions remain available for reference. For new questions, bug reports or support requests, please contact us at mail@lmdsupport.com.

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

  • 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.