代码之家  ›  专栏  ›  技术社区  ›  ViRuSTriNiTy

如何从lcdhype中的插件返回空格?

  •  -4
  • ViRuSTriNiTy  · 技术社区  · 6 年前

    我用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的作者

    1 回复  |  直到 6 年前
        1
  •  0
  •   ViRuSTriNiTy    6 年前

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

    这也意味着你必须返回 一串 当你想保留这些空间时。一 一串 以开头和结尾 ' 像个人物

    'This is a bar'
    

    在德尔福你需要逃离 因此,值为

    '''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;