<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Nice. Now I know where all those bug reports come from :P<br></blockquote><div><br></div><div style> :D It's my pleasure. Aren't you happy?</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Are those available in Delphi as well? If not I see no use in them. </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Consider this code:<br>
<br>
=== code begin ===<br>
<br>
procedure SomeProc(aValue: Int32);<br>
var<br>
p: Pointer;<br>
begin<br>
p := GetReferenceToValue(aValue);<br>
end;<br>
<br>
=== code end ===<br>
<br>
The value stored in "p" will be of no significant use for you to be stored in the longterm, because aValue will be located on the stack and thus the pointer will no longer be valid once the function exits. This will also be the case for strings, arrays, records, etc. No compiler magic will change this.</blockquote>
<div><br></div><div>Yes, I know that. I need this only for shortterm. In that case for safety maybe we should remove System.Addr? ;) In Delphi they do that by special interfaces created for each type (lost of time and memory). First, I can't implement this by Delphi way because we have still a lot of generics bugs. Secondly, I think that we can do much more better implementation of Generics. This is not C#, in Pascal we have better access to pointers. Now I'm using (I hope temporarily):</div>
<div><br></div><div>=== code begin ===<br></div><div><br></div>
<div><div> TValueAnsiStringHelper = record helper for AnsiString</div><div> function GetValueSize: Integer; inline;</div><div> function GetReferenceToValue: Pointer; inline;</div><div> end;</div><div><br></div>
<div><div>function TValueAnsiStringHelper.GetValueSize: Integer;</div><div>begin</div><div> Result := Length(Self) * SizeOf(AnsiChar);</div><div>end;</div><div><br></div><div>function TValueAnsiStringHelper.GetReferenceToValue: Pointer;</div>
<div>begin</div><div> if Length(Self) <> 0 then</div><div> Result := @Self[1]</div><div> else</div><div> Result := nil;</div><div>end;</div></div><div><br></div></div><div> === code end ===</div><div style>
Etc. for other basic types.</div><div style><br></div>
<div>I, really need this for custom comparers and equality comparers, for example:</div><div><br></div><div>=== code begin ===<br></div><div>while AComparer.Compare(AValues[I].GetReferenceToValue, P.GetReferenceToValue, AValues[I].GetValueSize, P.GetValueSize) < 0 do<br>
</div><div>// ...<br></div><div>if FEqualityComparer.Equals(AKey.GetReferenceToValue, LItem.Pair.Key.GetReferenceToValue, AKey.GetValueSize, LItem.Pair.Key.GetValueSize) then<br></div><div> === code end ===<br>
</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
measured by human/programmer<br>
function GetValueSize(Value: T): Integer; // for string types return Length(s), for Int32 returs 4 etc.<br>
</blockquote></div>
You should not store the string's content, but only the reference to the string. If you use assignment operators the RTL will take care of the rest.</blockquote><div><br></div><div>But with generics code for some types i don't have predefined operators (for example: records), and here is the problem with Generics Dictionary.</div>
<div>GetValueSize and GetReferenceToValue is in the same level as System.SizeOf and System.Addr. </div><div><br></div><div>I think it's a natural evolution System.SizeOf and System.Addr for Generics (to operate on values). There is no other language as FreePascal and it would be wrong to introduce something stupid to such an important system functions. If my thinking is wrong, please, any hint of an alternative. Without it, I'm completely stuck.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<a href="http://bugs.freepascal.org/view.php?id=24283" target="_blank">http://bugs.freepascal.org/<u></u>view.php?id=24283</a> (CRITICAL! Very Important!)<br>
</blockquote></div>
I don't consider nested specializations as critical. It's likely that I will fix this after I've fixed other generic problems...<br></blockquote><div><br></div><div>As critical error I mean - hardcore incompatibility with Delphi version of Generics.Collections. With critical error you can't compile Delphi code "as is" with this library. </div>
</div><div><br></div>-- <br><span style="font-family:arial,sans-serif;font-size:13px">Regards,</span><br style="font-family:arial,sans-serif;font-size:13px"><font face="arial, sans-serif">HNB</font></div></div>