Legacy Layout v Layout Designer code
Another issue concerning coding is thematic and cartographic legend layer support for legacy code. If you look up cartographic legend in MapBasic Help you will find code which was developed for the legacy layout format. Below is a section from the Create Cartographic Legend section.
S_title="Theme Legend of " + WindowInfo (I_map_id, WW_INFO_NAME)
By using a note statement you can ascertain the legend name using the first section of the code snippet as shown in the screen below.