为什么我不能在接收数组参数的函数中使用SetLength? [英] Why can I not use SetLength in a function which receives an array parameter?

查看:99
本文介绍了为什么我不能在接收数组参数的函数中使用SetLength?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下函数来设置动态数组的长度,该数组是var参数. 当我尝试编译代码时,只有一个错误:

I am trying to use the following function to set the length of a dynamic array which is a var param. There is only an error when I try to compile the code:

[dcc64错误] lolcode.dpr(138):E2008不兼容的类型

[dcc64 Error] lolcode.dpr(138): E2008 Incompatible Types

function execute(var command : array of string) : Boolean;
begin
  // Do something
  SetLength(command,0);
end;

推荐答案

定义类型

type
  TStringArray = array of string;

你可以做

function Execute(var StringArray: TStringArray): boolean;
begin
  // Do something
  SetLength(StringArray, 0);
end;

这篇关于为什么我不能在接收数组参数的函数中使用SetLength?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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