预期语句,但函数代码中发现函数错误 [英] Statement expected but Function found error in my function code

查看:37
本文介绍了预期语句,但函数代码中发现函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我创建的用于验证用户输入是否在范围内的代码模块,但是此错误始终出现在期望的语句但找到了功能"的下方,有人有想法吗?非常感谢

So below is the module of code I have created to verify a user input is between a range but this error keeps appearing below it ' statement expected but function found', any ideas anyone? Many thanks

function get_choice(var Options: integer): integer;
      var
      choice: integer;

      begin
        while (true) do
          begin
              write('choose option 1 to', Options);

              try
                readln(choice);
                if (choice>=1) and (choice <=Options) then
                    get_choice := choice
                else
                    write('invalid range');
              except
                 write('not a number');
          end;
      end;

推荐答案

您错过了 end :

              try
                readln(choice);
                if (choice>=1) and (choice <=Options) then
                    get_choice := choice
                else
                    write('invalid range');
              except
                 write('not a number');
              end;
         end
      end;

Try try..except 块必须有自己的结尾.

Try try..except block must have its own end.

这篇关于预期语句,但函数代码中发现函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆