[fpc-pascal] private type and type compatibility
Martin
lazarus at mfriebe.de
Wed Oct 30 14:40:10 CET 2013
On 30/10/2013 13:30, Xiangrong Fang wrote:
> 2013/10/30 Jonas Maebe <jonas.maebe at elis.ugent.be
> <mailto:jonas.maebe at elis.ugent.be>>
>
> The tdynarray type is not visible in the program because u1 is not
> in its uses clause (it's not in scope whatsoever), and
> nevertheless there is no problem to use it. It's of course not
> exactly the same (tdynarray isn't declared as private to u1), but
> at the scope visibility level it is the same situation as far as I
> am concerned.
>
>
> I don't think they are the same. tdynarray
> is not usable in main program because you did not uses u1, NOT
> because the type is defined as PRIVATE!
>
> As a matter of fact, if you define tdynarray as private (not in
> interface section), there is no way you can use it as a return type of
> an exported (public) function. This is a very consistent scoping rule!
>
> In my example, if the code is like this:
>
> generic TVector<T> = class
> private type
> TDataType = array of T;
> private
> function proc: TDataType;
> end;
>
> Then I think it is ok, because this PRIVATE type is used by PRIVATE
> function.
>
> What do you think?
I think there is no problem with:
var
a: array of Integer
begin
A:= obj.proc;
You are NOT using the type. You are using the value.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20131030/ace23480/attachment.html>
More information about the fpc-pascal
mailing list