Delphi中如何使用SuperObject调用使用Object作为参数的方法?
我们可以使用 SuperObject 库通过名称调用某个对象的方法,并使用 SOInvoker 方法将其参数作为 json 字符串,如下所示 answer
我想知道如何发送创建的对象作为参数。我尝试发送它,
LObjectList := TObjectList.Create;
LSuperRttiCtx := TSuperRttiContext.Create;
LSuperObjectParameter := LObjectList.ToJson(LSuperRttiCtx);
SOInvoke(MyInstantiatedObject, 'MyMethod', LSuperObjectParameter);
但在 MyMethod 中,LObjectList 引用丢失了。
我做错了什么?
可以在此处下载超级对象库
We can use the SuperObject library to invoke methods of a certain object by its name and giving its parameters as a json string using the SOInvoker method like in this answer
I'd like to know how do I send a created object as a parameter. I tried to send it like
LObjectList := TObjectList.Create;
LSuperRttiCtx := TSuperRttiContext.Create;
LSuperObjectParameter := LObjectList.ToJson(LSuperRttiCtx);
SOInvoke(MyInstantiatedObject, 'MyMethod', LSuperObjectParameter);
but inside MyMethod the LObjectList reference is lost.
What am I doing wrong?
The superobject library can be downloaded here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用记录数组而不是对象列表,它将起作用。
如果您仍然想使用对象列表,则必须像这样编写编码器和解码器。我已经为 TObjectList 编写了编码器/解码器,您必须对对象执行相同的操作并将类名嵌入到某处。
It will works if you use array of records intead of object list.
If you still want to use object list you will have to write encoders and decoders like this. I have written encoder/decoder for TObjectList, you will have to do the same for your objects and embed the class name somewhere.