Delphi记录助手为double
情况
我写了一个类似于二级方程的类.您可以找到here该类的完整代码,但它与该问题不太相关. type TArrayOfDouble = array of array of double; type TEqSecGrado = class private //variables a,b,c: double; delta: double; solutions: TArrayOfDouble; solRealCount: integer; solImaginaryCount: integer; class var currentIstances: integer; class var totalIstances: integer; //methods function getDelta(const vala,valb,valc: double): double; overload; public constructor Create(const a,c: double); destructor Destroy; override; //methods function getDelta: double; overload; function getSolutions: TArrayOfDouble; virtual; //properties property valueOfA: double read a; property valueOfB: double read b; property valueOfC: double read c; property realSolutionsCount: integer read solRealCount; property imaginarySolutionsCount: integer read solImaginaryCount; class property currentEquationsCount: integer read currentIstances; class property totalEquationsCount: integer read totalIstances; end; 我想创建一个名为TArrayOfDouble的新类型,它将包含我方程的解.在主窗体中,我以这种方式使用类: procedure TForm3.Button1Click(Sender: TObject); var solver: TEqSecGrado; soluzioni: TArrayOfDouble; begin //f(x) = 3x^2 - x - 2 -> [sol.1 = 1 | sol.2 = -0,666666666666667] solver := TEqSecGrado.Create(3,-1,-2); try soluzioni := solver.getSolutions; //soluzioni[0][0] = 1; soluzioni[0][1] = 0; //soluzioni[1][0] = -0,666666666666667; soluzioni[1][1] = 0; finally solver.Free; end; end; 现在我在soluzioni中有结果,我可以输出它们. (我已经使用了一个矩阵,因为在第一个地方我提出了真正的解决方案,在这种情况下为1和-0.67,如果需要,在第二个运动中使用虚拟解决方案). 题 当我输出解决方案时,我想将它们转换为分数.我想做像soluzioni [a] [b] .toFraction这样的事情.所以我以为我可以使用记录助手来实现双倍. type TSupport = record helper for Double function toFraction: string; function toString: string; //I have added this LATER end; 在这里,我怀疑.一旦我创建了TSupport和toFraction方法,我就可以调用soluzioni [0] [0] .toFraction但我无法调用soluzioni [i] [0] .toString. 为了解决我的问题,我决定添加函数toString,一切正常.记录助手是否隐藏了所有其他方法?如果我删除了记录助手,我可以像往常一样再次使用toString方法. 我知道帮助器是一种在不使用继承的情况下扩展类的方法,但为什么我只能使用我在助手中声明的方法? 解决方法
类和记录助手的限制是一次只能激活一个. Double的ToString方法实际上是在Delphi RTL提供的记录助手中实现的.将助手附加到类型后,RTL助手不再处于活动状态.
documentation说:
这是一个长期存在的问题,自从助手被引入以来,Embarcadero就已经知道了这个问题.在很长一段时间里,他们没有解决这个问题,而且我认为你应该假设他们永远不会这样做. 所以,你有两个选择: >附上您自己的帮助程序,并接受您无法使用RTL帮助程序的功能.>通过助手以外的方式实现您的功能. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |