Maik, here is a working version your script with a minimal amount of changes to make it work.
First, your handler (sub-routine) was not explicitly returning a value, as the version below does, but your run handler was accessing the last appleScript result, which is global. So it seemed as if there was
a return value.
Second, as others pointed out your variable name was the same as your handler name which confuses appleScript.
HTH,
Ed
use AppleScript
version "2.4"
-- Yosemite (10.10) or later
use scripting additions
on
run
set
the_List to {}
activate
set
the_Files to (choose file
with prompt "Please select a file to process:"
with multiple selections allowed)
repeat
with f from 1 to (count
of the_Files)
set
the_File to (the_Files's
item
f)
set
the_List's end to the_File
end
repeat
display dialog ("the_Files: " &
the_Files & "
the_List: " &
the_List)
end
run
on the_Name(the_File)
tell
application "Finder"
set
fileName to name
of the_File
end
tell
return
fileName
end the_Name