如何在Delphi 2010中使用IFont和IStrings?

如何在Delphi 2010中使用IFont和IStrings?,delphi,com,marshalling,delphi-2010,Delphi,Com,Marshalling,Delphi 2010,我想在Delphi2010中编写一个DCOM客户机/服务器,它使用IString在测试服务器中将Memo1.line(作为tstring)作为属性传递。服务器有一个TMemo组件,我想通过服务器的IMemoIntf设置或获取其Memo1.Lines属性。 1-In RIDL编辑器IStrings不适用于现成的Delphi 2010。因此,我首先注册了stdvcl40.dll,并将其添加到编辑器的“使用”部分,以便能够添加IStrings类型的属性。 2-然后我实现了两个函数Set_Text和Ge


我想在Delphi2010中编写一个DCOM客户机/服务器,它使用IString在测试服务器中将Memo1.line(作为tstring)作为属性传递。服务器有一个TMemo组件,我想通过服务器的IMemoIntf设置或获取其Memo1.Lines属性。

1-In RIDL编辑器IStrings不适用于现成的Delphi 2010。因此,我首先注册了stdvcl40.dll,并将其添加到编辑器的“使用”部分,以便能够添加IStrings类型的属性。

2-然后我实现了两个函数Set_Text和Get_Text来设置和获取服务器的Memo1.行,如下所示:

procedure TMemoIntf.Set_Text(const Value: IStrings);
begin
  SetOleStrings(Form1.GetText, Value);
end;


function TMemoIntf.Get_Text: IStrings;
begin
  GetOleStrings(Form1.GetText, Result);
end;
IMemoIntf是由TMemoIntf实现的接口。它自动定义如下:

// *********************************************************************//
// Interface: IMemoIntf
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {2B6BD766-5FB6-413F-B8E2-4AB05D87E669}
// *********************************************************************//
  IMemoIntf = interface(IDispatch)
    ['{2B6BD766-5FB6-413F-B8E2-4AB05D87E669}']
    function Get_Text: IStrings; safecall;
    procedure Set_Text(const Value: IStrings); safecall;
    property Text: IStrings read Get_Text write Set_Text;
  end;
TMemoIntf = class(TAutoObject, IMemoIntf)
protected
  function Get_Text: IStrings; safecall;
  procedure Set_Text(const Value: IStrings); safecall;
end;
和TMemoIntf如下:

// *********************************************************************//
// Interface: IMemoIntf
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {2B6BD766-5FB6-413F-B8E2-4AB05D87E669}
// *********************************************************************//
  IMemoIntf = interface(IDispatch)
    ['{2B6BD766-5FB6-413F-B8E2-4AB05D87E669}']
    function Get_Text: IStrings; safecall;
    procedure Set_Text(const Value: IStrings); safecall;
    property Text: IStrings read Get_Text write Set_Text;
  end;
TMemoIntf = class(TAutoObject, IMemoIntf)
protected
  function Get_Text: IStrings; safecall;
  procedure Set_Text(const Value: IStrings); safecall;
end;
当我在客户端调用fMemo.Set_Text时,一切正常,并且客户端将服务器备忘录内容设置为自己的内容,但当我调用fMemo.Get_Text以获取服务器备忘录内容时,我收到以下错误消息

客户端有一个显示服务器的专用字段fMemo和一个用于显示Set/Get_文本调用结果的备忘录1

TForm2 = class(TForm)
...
  btnSetText: TButton;
...
  btnGetText: TButton;
  Memo1: TMemo;
...
  procedure btnSetTextClick(Sender: TObject);
...
  procedure btnGetTextClick(Sender: TObject);
private
  fMemo : IMemoIntf;
end;

// it gives me the error
procedure TForm2.btnGetTextClick(Sender: TObject);
var
  Strings : IStrings;
begin
  Strings := fMemo.Get_Text;
  SetOleStrings(Memo1.Lines, Strings);
end;

// it works fine
procedure TForm2.btnSetTextClick(Sender: TObject);
var
  Strings : IStrings;
begin
  GetOleStrings(Memo1.Lines, Strings);
  fMemo.Set_Text(Strings);
end;
同样的想法也适用于IFont,但是当我实现相同的东西来使用TFont和TColor时,OLE_颜色工作得非常完美(我知道OLE_颜色直接作为一种自动编组类型受到支持,并且与这两种类型不同)。
我是做错了还是在Delphi 2010中
如何使用IFont和IStrings缓解Delphi 2010中的问题?

好的,我发现了问题所在,是我

.ridl文件的定义非常重要。对于“getter function”,参数“out”应该是“IStrings**”,对于“putter function”,参数应该是“IStrings*”。编译器会自动更新“TLB”文件,并向接口定义添加一个属性,在以前的“IMemoIntf”实现中,在这两个方向上一切都正常


我希望这对你有帮助。我不知道如何追加,如果有人感兴趣,请告诉我如何追加整个项目,看看我做了什么。

上述问题是在Windows 10 Pro 64位中测试的,有“combase.dll”错误。在Windows 7-Ultimate 32位中,错误发生在“ole32.dll”中。在这个测试中,我还需要注册“stdvcl40.dll”。好的,我在一个新接口的Get/Set函数中用“TStrings.Text”替换了“IStrings”,并使用了BSTR,因为COM支持它。这是一种变通方法,而不是缓解措施。找到一个原因对“IFont”也有帮助。有人知道专门为Delphi 2010编写的定制编组的好参考吗?我期待实施新的“IString”和“IFont”替换。或者正在浏览源代码,找出问题的原因。嗨,大卫,我的问题或我有什么问题吗?我的问题没有得到任何回答或评论。这正常吗。或者我需要做些什么来获得更多的打击?先谢谢你。好的,我已经找到了问题所在,是我。.ridl文件的定义非常重要。对于getter out,参数应该是“IStrings**”,对于putter,参数应该是“IStrings*”。编译器会自动更新“TLB”文件,并向接口定义添加一个属性,在以前的“IMemoIntf”实现中,在这两个方向上一切都正常。我希望这对你有帮助。我不知道如何附加,如果有人有兴趣告诉我如何附加完整的项目,看看我做了什么。请有人告诉我如何结束这个问题。