<div dir="ltr"><div>Hi!</div><div><br></div><div>I am writing my own string type and I want to overload standard string functions.</div><div>I don't want to hide them, just overload.<br></div><div><br></div><div>Consider the following example (I use 3.0.4 [2017/10/06] for i386):</div><div><br></div><div>=======================================</div><div>{$MODE FPC}<br><br>type<br>TMyString = record<br>end;<br><br>function Pos(const Sub, S: TMyString): LongInt;<br>begin<br> Pos := 0;<br>end;<br><br>function Length(const MyString: TMyString): SizeUInt;<br>begin<br> Length := 0;<br>end;<br><br>function Copy(const MyString: TMyString; A, B: LongInt): TMyString;<br>begin<br> Copy := MyString;<br>end;<br><br>begin<br> // Works just fine<br> Writeln(Pos('a', 'abcdef'));<br> // Error: Incompatible type for arg no. 1: Got "Constant String", expected "TMyString"<br> Writeln(Copy('abcdef', 1, 4));</div><div>
// Error: Incompatible type for arg no. 1: Got "Constant String", expected "TMyString
</div><div> Writeln(Length('abcdef'));<br>end.<br></div><div>=======================================<br></div><div><br></div><div>Pos behaves differently than Length and Copy.</div><div>Seems inconsistent -- should it be considered as a bug?<br></div><div><br></div><div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Victor Matuzenko (Виктор Матузенко)<br></div></div></div></div></div>