首页 > 解决方案 > 如何从 LCDHype 中的插件返回空格?

问题描述

我使用 Delphi 为 LCDHype 编写了一个插件,我想返回一个包含空格的字符串。这是一个例子:

...

implementation

...

var
  gReturnValue: String;

// Plugin.Foo.GetBar
function Library_GetBar(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
begin
  gReturnValue := 'This is a bar';

  result := PWideChar(gReturnValue);
end;

这些空格被应用程序以某种方式从字符串中删除,并且永远不会显示。

我该如何解决这个问题?


披露:我是 LCDHype 的作者

标签: stringdelphipluginspascal

解决方案


插件的返回值由 LCDHype 解析,这意味着返回值基本上是脚本代码。

这也意味着当您想要保留空格时必须返回一个字符串。字符串'以类似的字符开始和结束

'This is a bar'

在 Delphi 中,您需要转义'字符,因此值将是

'''This is a bar'''

您可以使用QuotedStr()转义'字符并正确引用字符串,例如:

uses SysUtils; // for QuotedStr()

...

function Library_GetBar(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
begin
  gReturnValue := QuotedStr('This is a bar');

  result := PWideChar(gReturnValue);
end;

推荐阅读