Show: Delphi C++
Display Preferences

WEAKLINKRTTI directive (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Delphi Compiler Directives (List) Index

Type

Switch

Syntax

{$WEAKLINKRTTI ON} or {$WEAKLINKRTTI OFF}

Default

{$WEAKLINKRTTI OFF}

Scope

Local


Remarks

Normally, all the methods that can be accessed and invoked using extended RTTI must be compiled into the binary. Let's take the following example:

var
  LContext: TRttiContext;
  LType: TRttiType;
begin
  { Create a new RTTI context }
  LContext := TRttiContext.Create();

  { Obtain the TRttiType for a given TSomeClass class }
  LType := LContext.GetType(TSomeClass);
 
  { Invoke the method called SomeMethod in the class }
  LType.GetMethod('SomeMethod').Invoke(['FirstParameter', 2]);
end;

In the previous example, a method SomeMethod is invoked dynamically. There is no link-time reference to SomeMethod, so the normal linking process would not include it into the binary, thus the RTTI-using code would fail to call the method that does not exist. In our example, TSomeClass has extended RTTI, so the linker includes all methods into the binary (even the ones not referenced directly).

In some cases though, it is not desirable to include all the methods into the binary. In most cases, there is no RTTI-aware code that finds and invokes the methods at run time. Use {$WEAKLINKRTTI ON} to suppress the default behavior of including all method into the binary. The $WEAKLINKRTTI directive only affects linking. It does not affect unit compilation. It is the only way to control how much RTTI is generated in the final executable without recompiling the original units with different settings for the $RTTI directive.


See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance