gpt4 book ai didi

delphi - 向过程传递无限数量的参数

转载 作者:行者123 更新时间:2023-12-03 14:34:56 24 4
gpt4 key购买 nike

在Delphi中程序write可以处理:

write(TF,st1)

write(TF,st1,st2,st3,st4);

我想声明一个也可以做到这一点的过程,语法是什么?

以及以下选项:

write(TF,[st1,st2,st3])

虽然我知道该怎么做,但不太理想。

主要目的是将ShortString传递到函数中,该函数将从文件中进行读取调用,并按照定义的shortString长度进行读取。然而,在将其作为变体或开放数组传递后,shortString 会失去其“大小”并变为 255,这使得此传递对我来说无法使用。但如果你想传递开放数组,答案仍然得到。

最佳答案

只是为了补充 Cosmin 的答案:如果参数列表具有不同类型,您可以使用变体开放数组参数(也称为“const 数组”)。 More on Delphi documentation.

示例(来自 documentation ):

function MakeStr(const Args: array of const): string;
var
I: Integer;
begin
Result := '';
for I := 0 to High(Args) do
with Args[I] do
case VType of
vtInteger: Result := Result + IntToStr(VInteger);
vtBoolean: Result := Result + BoolToStr(VBoolean);
vtChar: Result := Result + VChar;
vtExtended: Result := Result + FloatToStr(VExtended^);
vtString: Result := Result + VString^;
vtPChar: Result := Result + VPChar;
vtObject: Result := Result + VObject.ClassName;
vtClass: Result := Result + VClass.ClassName;
vtAnsiString: Result := Result + string(VAnsiString);
vtCurrency: Result := Result + CurrToStr(VCurrency^);
vtVariant: Result := Result + string(VVariant^);
vtInt64: Result := Result + IntToStr(VInt64^);
end;
end;

关于delphi - 向过程传递无限数量的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6807066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com