是否可以在Delphi中使用Fluent调用样式自引用记录?

是否可以在Delphi中使用Fluent调用样式自引用记录?,第1张

概述目标是创建一个名为TURLString的类型,如下所示: var newURl : TURLString;begin newURL.Append('http://').Append('www.thehost.com').Append('path/on/server').Append('?'); ...lots of app logic... newURL.AppendPar 目标是创建一个名为TURLString的类型,如下所示:

var  newURl : TURLString;begin  newURL.Append('http://').Append('www.thehost.com').Append('path/on/server').Append('?');  ...lots of app logic...  newURL.AppendParam('name','value').Append('#').AppendParam('name','value');  ...more params added...  result := httpClIEnt.Get(newURL);end;

使用TURLString定义(注意它的记录):

//from actual code usedTURLString = recordprivate    FString : string;public    function Append(APart : string) : TURLString;    function AppendParam(AParam,AValue : string) : TURLString;end;function TURLString.Append(APart: string) : TURLString;begin  FString := FString + APart;  result := self;end;function TURLString.AppendParam(AParam,AValue: string): TURLString;begin  if (not Empty) then    FString := FString + URL_AMB;  FString := FString + AParam + '=' + AValue;  result := self;end;

当单步执行流体调用时,会附加值,但退出时它们将恢复为传递给第一个追加调用的第一个字符串,newURL等于’http://’,同时调试您看到的附加调用’http:// www .thehost.com /路径/ /服务器?名称=值#name =价值”.

这个概念是否可以带有记录?

解决方法 如果使用类似记录的值类型,则需要将最终返回的结果分配给变量:

newURL := newURL.Append('http://').Append('www.thehost.com');

如果您使用类实例之类的引用类型,则可以使用您在问题中使用的语法.

引用类型方法将数据类型视为可变,而对于值类型,最好实现不可变数据类型.

总结

以上是内存溢出为你收集整理的是否可以在Delphi中使用Fluent调用样式自引用记录?全部内容,希望文章能够帮你解决是否可以在Delphi中使用Fluent调用样式自引用记录?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1268170.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存