我使用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的作者
答案 0 :(得分:0)
插件的返回值由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;