having type declaration 2 sub-types deriving same internal type, how can have different record helper each sub-type?
example:
type singlea = single; singleb = single; _singlea = record helper singlea procedure dothingstoa; end; _singleb = record helper singleb procedure dothingstob; end;
if declare var of type singlea, helper type singleb, know normal behaviour if override same internal type, why happen different types?
any appreciated...
thanks in advance.
you not declaring sub-types here. code:
type singlea = single; singleb = single;
is merely declaring aliases, not types. such, singlea
, singleb
same type single
.
this explained here:
type compatibility , identity (delphi)
when 1 type identifier declared using type identifier, without qualification, denote same type. thus, given declarations:
type t1 = integer; t2 = t1; t3 = integer; t4 = t2;
t1
,t2
,t3
,t4
, ,integer
denote same type. create distinct types, repeat wordtype
in declaration. example:type tmyinteger = type integer;
creates new type called
tmyinteger
not identicalinteger
.
in effect, = type x
construct creates new type info type that
typeinfo(singlea) <> typeinfo(singleb)
.
in original code, declaring 2 aliases same type single
.
for given type (and aliases), can only have 1 type helper in scope, in original code record helper singleb
hides record helper singlea
.
by upgrading aliases own types, avoid issue:
type singlea = type single; singleb = type single; <<-- type keyword makes singleb distinct singlea
now have 2 distinct types, , record helpers work expected.
Comments
Post a Comment