Shelbyville
MIS
Can anyone see why the code below will work when it is a click event in a filelistbox but not when it is in the click event of a button? It hangs with an "Invalid argument to date encode" error when it hits the FileDateTime:= DateToStr(FileDateToDateTime . . . line. And also, the button even works as long as you click the fileListbox first for any given directory. (All it does is get the date portion of the date time stamp of a file.)
Again no problem when I click the filelistbox - only with the button and only if I click the button first for any given directory.
Here's the code
{******** this works }
procedure TForm1.FileListBox1Click(Sender: TObject);
var
FileDateTime: String;
i : Integer;
FileName : String;
begin
for i := 0 to FileListbox1.Items.count -1 do
begin
FileDateTime:= DateToStr(FileDateToDateTime(FileAge(FileListBox1.FileName)));
RichEdit1.Lines.Add(FileDateTime);
FileListBox1.ItemIndex := i;
end;
end;
{********* this doesn't work **}
procedure TForm1.Button1Click(Sender: TObject);
var
FileDateTime: String;
i : Integer;
FileName : String;
begin
for i := 0 to FileListbox1.Items.count -1 do
begin
FileDateTime:= DateToStr(FileDateToDateTime(FileAgeFileListBox1.FileName)));
RichEdit1.Lines.Add(FileDateTime);
FileListBox1.ItemIndex := i;
end;
end;
This is in Delphi 5.0 and for what it is worth I cut and pasted to get it to the click even on the button.
thanks
Again no problem when I click the filelistbox - only with the button and only if I click the button first for any given directory.
Here's the code
{******** this works }
procedure TForm1.FileListBox1Click(Sender: TObject);
var
FileDateTime: String;
i : Integer;
FileName : String;
begin
for i := 0 to FileListbox1.Items.count -1 do
begin
FileDateTime:= DateToStr(FileDateToDateTime(FileAge(FileListBox1.FileName)));
RichEdit1.Lines.Add(FileDateTime);
FileListBox1.ItemIndex := i;
end;
end;
{********* this doesn't work **}
procedure TForm1.Button1Click(Sender: TObject);
var
FileDateTime: String;
i : Integer;
FileName : String;
begin
for i := 0 to FileListbox1.Items.count -1 do
begin
FileDateTime:= DateToStr(FileDateToDateTime(FileAgeFileListBox1.FileName)));
RichEdit1.Lines.Add(FileDateTime);
FileListBox1.ItemIndex := i;
end;
end;
This is in Delphi 5.0 and for what it is worth I cut and pasted to get it to the click even on the button.
thanks