[SOLVED] Bug in chair or in FileNameEdit? lazarus / 31-LCL ---------------------------------------------------------------------- BigChimp · 2013-04-16 08:05 (Laz 1.0.8/fpc 2.6 x86 and Laz trunk/fpc 2.7 x64, win) Hi, running this code with a filenameedit: Code: [Select]procedure TForm1.FileNameEdit1AcceptFileName(Sender: TObject; var Value: String   ); begin   SynMemo1.Lines.LoadFromFile(FileNameEdit1.FileName); end; fails! When clicking on the icon next to the filenameedit, and selecting a file (with a filemask, don't know if that matters here), the text of the filenameedit is not changed. I then get a "cannot find file ''" warning. However, when I type/copy an existing filename, then press the icon and select the same filename, the control works and I get a proper filename returned. Is it a stupid mistake in my coding or is the filenameedit control buggy? Project attached. ---------------------------------------------------------------------- typo · 2013-04-16 11:09 You need to use the parameter Value from FileNameEdit1AcceptFileName instead of FileNameEdit1.FileName. ---------------------------------------------------------------------- Blaazen · 2013-04-16 11:20 Yes, typo is right. It is by design. Look at this: Code: [Select]procedure TFileNameEdit.SaveDialogResult(AKind: TDialogKind; D: TCommonDialog); var   FN: String; begin   case AKind of     dkOpen, dkPictureOpen :     begin       FilterIndex := TOpenDialog(D).FilterIndex;       FN := TOpenDialog(D).FileName;       if (FN <> '') then       begin         if Assigned(OnAcceptFileName) then           OnAcceptFileName(Self, FN);       end;       if (FN <> '') then       begin         // set FDialogFiles first since assigning of FileName trigger events         FDialogFiles.Text := TOpenDialog(D).Files.Text;         FileName := FN;       end;     end;     dkSave, dkPictureSave :     begin       FileName := TSaveDialog(D).FileName;       FilterIndex := TSaveDialog(D).FilterIndex;       FDialogFiles.Clear;     end;   end; end;Event "OnAcceptFileName" is triggered and property FileName is assigned 6 lines later. ---------------------------------------------------------------------- BigChimp · 2013-04-16 12:24 Thanks guys! Had indeed overlooked the Value parameter. Still, I suppose it makes sense to have the filename property assigned before the OnAcceptFileName is triggered... after all the filename does not change any more. Interested to see how the devs react to 24281: TFileNameEdit.OnAcceptFileName gets empty filename when using the editbutton Whatever, using value is obviously the right way of working with it. Thanks again! ---------------------------------------------------------------------- Blaazen · 2013-04-16 12:30 Looking at the code, "Value" is passed by reference, it is expected that it can be modified in OnAcceptFileName handler. I don't know why it is. Maybe Delphi compatibility? ---------------------------------------------------------------------- BigChimp · 2013-04-16 12:35 Yes, that would be the only valid reason, IMO. To me, OnAccept... implies the filename is already accepted and won't change. ---------------------------------------------------------------------- bmy92 · 2013-04-17 10:36 If you change Value in OnAcceptFileName handler, then FileNameEdit1.FileName will be updated accordingly at exit of the event routine. So you can reject the chosen file (e.g. clear Value), or change it if you want. ---------------------------------------------------------------------- BigChimp · 2013-04-17 10:51 @bmy92: thanks... so the OnAcceptFilename naming is just something I have to get used to Closing the bug report.