<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Am 30.10.2013 08:47, schrieb Xiangrong
Fang:<br>
</div>
<blockquote
cite="mid:CAP93jB3_gqVXpmKHYokfKPsmdyLANgxKpu8iw14-wMqE7ZCQRw@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_default" style="font-family:courier
new,monospace">Hi All,<br>
<br>
I have the following class:<br>
<br>
type<br>
generic TVector<T> = class<br>
private type<br>
TDataType = array of T;<br>
private<br>
FData: TDataType;<br>
... ...<br>
public<br>
... ...<br>
function Slice(APos: Integer = -1; ACount: Integer = -1):
TDataType;<br>
end;<br>
<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace">
The Slice() method return a portion of the data as a dynamic
array.<br>
<br>
My question is, as I define TDataType as PRIVATE type, why it
is still usable outside of the class? In the main program I
did:<br>
<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace">
type<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace"> TIntVector = specialize
TVector<Integer>;<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace">var<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace"> iv: TIntVector;<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace"> ia: array of Integer;<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace">
begin<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace"> iv := TIntVector.Create;<br>
... ...<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace"> ia := iv.Slice;<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace">end.<br>
<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace">This will assign a TDataType (is it
TVector$TDataType or TIntVector$TDataType? I don't know) to an
"array of Integer". Why this assignment works? <br>
<br>
</div>
<div class="gmail_default" style="font-family:courier
new,monospace">i.e. how does the type system work?!<br>
</div>
</div>
</blockquote>
It's a bit annoying that the usage private/protected types in
public/published functions is allowed... (this is however Delphi
compatible) Maybe this should be adjusted for non-Delphi modes for
language consistency... (maybe at least as a warning which could be
elevated to an error if someone wants)<br>
<br>
Regards,<br>
Sven<br>
</body>
</html>