Utf8ToString和较旧的Delphi版本 [英] Utf8ToString and older Delphi versions

查看:92
本文介绍了Utf8ToString和较旧的Delphi版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在旧版本和新版本的Delphi中都使用某些单元。自从最近的Delphi版本以来, Utf8Decode 引发了已弃用的警告,建议切换到 Utf8ToString 。问题是较旧的Delphi版本没有声明此功能,因此我应该使用哪个 {$ IFDEF} 标签来定义 Utf8Decode的包装器名为 Utf8String (或者也许是 Utf8ToWideString )?

I want to use some units in both older and newer versions of Delphi. Since a recent Delphi version, Utf8Decode throws a deprecated warning which advises to switch to Utf8ToString. Problem is older versions of Delphi don't declare this function, so which {$IFDEF}label should I use to define a wrapper around Utf8Decode named Utf8String (or perhaps Utf8ToWideString)?

或者换句话说:引入了哪个版本 Utf8ToString

Or in other words: which version was Utf8ToString introduced?

推荐答案

我想我可以用 $ IF 来实现它,以便调用代码可以使用新的RTL函数,也可以使用旧的不赞成使用的版本。因为新的 UTF8ToString 返回一个UnicodeString,所以我可以肯定地假定它是在Delphi 2009中引入的。

I think I would implement it with an $IF so that calling code can use either the new RTL function, or fall back on the older deprecated version. Since the new UTF8ToString returns a UnicodeString I think it is safe to assume that it was introduced in Delphi 2009.

{$IF not Declared(UTF8ToString)}
function UTF8ToString(const s: UTF8String): WideString;
begin
  Result := UTF8Decode(s);
end;
{$IFEND}

这篇关于Utf8ToString和较旧的Delphi版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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