Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid Argument when used in Button But Not FileListBox

Status
Not open for further replies.
Jan 22, 2003
73
US
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
 
When showing program code in a posting such as yours please use Copy and Paste as this avoids errors such as the missing open parenthesis in the second
Code:
FileDateTime:= DateToStr(FileDateToDateTime(FileAge[red]([/red]FileListBox1.FileName)));
Also it makes life easier for those of us who are going to spend time helping you if you can use TGML to format the program code (as above).

The reason that the Button1Click gives an "Invalid argument to date encode" is that the FileListBox doesn't have a file selected so that the filename variable contains an empty string.

[red]You could have easily found this yourself by putting a breakpoint on the above code and examining the FileListBox1.FileName property in the debugger.[/red]

Andrew
Hampshire, UK
 
Shelbyville, Did my reply solve the problem?

Andrew
Hampshire, UK
 
Indeed it did. sorry for the delay - other problems, other projects. But thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top