我们在从Delphi 7转换时摒弃了ShortString。我希望让这个过程尽可能轻松,所以我们想改变ShortString为一些以同样方式运作的记录。以下是它的声明(还有更多内容,但这是基本结构,突出了问题):
TShortStringRec = record
private
FStuff: array [0..49] of Char;
public
class operator Implicit(AStuff: TShortStringRec): String;
class operator Implicit(S1: String): TShortStringRec;
end;
这对于向记录设置字符串的工作很好。但是像format
这样的函数将const array of const
作为其参数。有没有什么方法可以将隐式转换为我们想要传递到常量数组中的内容?
function FunkyFunc : string;
var
ssr : TShortStringRec;
begin
ssr := 'Wall';
result := format('Hello %s', [ssr]); //<---error here
end;
在编译时会出现语法错误,因为“ssr”不是您可以在其中一个数组上使用的参数类型。
variant
的作用吗? - Johan