[DUG] D2007 to XE2 conversion notes
Jolyon Smith
jsmith at deltics.co.nz
Tue Jan 17 11:32:48 NZDT 2012
Where is this clear "default is false" indication in the docs ?
RTTI generation has always been "off" by default (as a project wide
setting), unless a class extends a type for which RTTI was previously
enabled. But I can't find any reference to _extended_ RTTI being disabled
by default.
Note also that another (new) option that is OFF by default is WEAKLINKRTTI.
This controls whether methods that are discoverable by RTTI are linked
even if not directly used. With this ON, then code that would normally be
excluded by the linker, because it is not referenced, will still be linked
_just in case_ they may be discovered and invoked at runtime thru RTTI.
i.e. If you have not turned WEAKLINKRTTI *ON* then any method for which
RTTI is generated will be linked in, even if never called. I don't see any
obviously named project level setting for this, so this directive
presumably has to be included in every unit where you wish to suppress this
behaviour (and thus cannot be applied to VCL units without jumping through
hoops).
With all that in mind, now, try this...
in XE2... create a new VCL Forms application. You can even check that the
"Enable RTTI" project setting is indeed the default FALSE setting if you
wish. Now drop a TListBox on the default form (ListBox1). Then add this
code to the FormCreate event:
var
rtti: TRTTIContext;
lType: TRTTIType;
lMethods: TArray<TRTTIMethod>;
lMethod: TRTTIMethod;
begin
rtti := TRttiContext.Create;
try
lType := rtti.GetType(self.ClassType);
lMethods := lType.GetMethods;
for lMethod in lMethods do
ListBox1.Items.Add(lMethod.Name);
finally
rtti.Free;
end;
end;
This will list over 170 methods for TForm1 for which RTTI information
exists !
Do the equivalent thing in a version of Delphi prior to D2010 when this
extended RTTI was introduced, and you will get just 1: the FormCreate
event handler method itself.
Notice also that even if you add the following directive immediately prior
to the TForm1 declaration, you still get the same list of 178 methods, even
tho the directive appears to (and should, according to the documentation)
disable ALL RTTI for that class:
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS ([])}
TForm1 = class(TForm)
Whether this is some misunderstanding of how this directive is supposed to
work, or a bug in the compiler ignoring the directive (no RTTI declaration
of any form appears to make any difference at all), I don't know.
Yes, Unicode will have some impact too but I am pretty sure that the new
RTTI features that your code now enjoys (without having asked for it, and
presumably without even needing it) are the main source for the sudden
increase in EXE size.
On 17 January 2012 10:33, Peter Hyde <peter at webcentre.co.nz> wrote:
> re: RTTI
>
> > imho this sort of change should be opt-IN, not opt-OUT.
>
> XE2 help clearly says the defaut is false, and that's the case for the
> three projects I'm
> working on at present. So the bloat that John reports must come from other
> factors.
>
> I think it must be related to the Unicode (or similar) changes as, for my
> apps at least, the big
> increment - about 70% - came in the shift from D2007 to D2010.
>
> Even so, there was a noticeable (20%) jump between D2010 and XE2.
>
> cheers,
> peter
>
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at listserver.123.net.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at listserver.123.net.nz with
> Subject: unsubscribe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20120117/7c8b89c2/attachment.html
More information about the Delphi
mailing list