Why moving ItemIndex of FileListBox in runtime, filelistbox1.FileName is blank lazarus / 16-Databases ---------------------------------------------------------------------- asdf · 2012-12-04 09:51 Code: [Select]var u: integer; load1: string; begin for u:=0 to filelistbox1.Count-1 do begin;     filelistbox1.ItemIndex:=u;     load1:= filelistbox1.FileName;     memo1.Append('1. u = '+inttostr(u));     memo1.Append('2. Load1 = '+load1);     memo1.Append('3. '+filelistbox1.FileName;     memo1.Append(' ');                        Why moving ItemIndex by 'u' gave the 'filelistbox1.FileName' blank ? On the other hand, clicking on it by mouse, it gave the correct filename. ---------------------------------------------------------------------- User137 · 2012-12-04 10:47 If you check the components code internally, filename is made like this: Code: [Select]FFileName:= FDirectory+DirectorySeparator+FFileName; So if you don't want to call FileListBox1.UpdateFileList; , which i don't recommend (because that command may be slow, especially if directory is large), you can change the code to roughly this: Code: [Select]for u:=0 to filelistbox1.Count-1 do begin;     load1:= filelistbox1.Directory + DirectorySeparator + filelistbox1.Items[u]; edit: And also, what you found is a bug. There is no setter function to Itemindex property, so filename isn't updated realtime. It could be event-driven, Application.Processmessages might update it too. ---------------------------------------------------------------------- asdf · 2012-12-04 22:29 If so, do I have to change 'all' I have ever written like this ... Code: [Select]    load1:= filelistbox1.FileName; to be like this ... Code: [Select]load1:= filelistbox1.Directory + DirectorySeparator + filelistbox1.Items[u];  ? ---------------------------------------------------------------------- User137 · 2012-12-04 23:33 You have a for-loop which goes through all the files. Itemindex was never intended to be changed like that, and so often. So it is much better and faster way to use the .Items[] property. If you don't change Itemindex in code, then you should be ok to use .Filename. There's internal function UpdateSelectedFileName; but it's private, and so you can't use it. UpdateFileList; does that, but it also searches the entire folder for files, so that's why i don't recommend using that in a for-loop, especially one that depends on amount of files in that folder. ---------------------------------------------------------------------- asdf · 2012-12-04 23:55 Thank you so much  .