RTTI, , protected , , .
Delphi : , protected , . , , . , , , .
, . , .
, DestroyWindowHandle VCL TWinControl - . , TWinControl, . , , - HWND , :
type
TWinControlEx = class(TWinControl);
procedure TMyForm.MyButtonClick(Sender: TObject);
begin
TWinControlEx(Sender).DestroyWindowHandle;
end;
, , , ?
, . , , , :
unit Unit2;
interface
type
TFoo = class
protected
constructor Create;
end;
implementation
constructor TFoo.Create;
begin
inherited Create;
// Foo specific, protected initialisation here....
end;
end.
- ...
unit Unit1;
..
implementation
uses
Unit2;
type
TFooEx = class(TFoo);
procedure TMyForm.FormCreate(Sender: TObject);
var
foo: TFoo;
begin
foo := TFooEx.Create;
end;
, foo TFooEx, TFoo. . , , , :
if foo is TFoo then
- , . , :
if foo.ClassType = TFoo then
( foo.ClassType = TFooEx, TFoo).
, , protected, , , , . , , , , () TFoo, , , :
// unit2
TFoo = class
protected
constructor Create; virtual;
end;
TBar = class(TFoo)
protected
constructor Create; override;
end;
...
TFooEx = class(TBar);
procedure ....;
var
foo: TFoo;
begin
foo := TFooEx.Create;
end;
< >
RTTI , , RTTI .
Another advantage is that if the signatures of the protected methods that you call in this way are changed, then the code simply does not compile, and not only does not work at run time. It also means that you get help from code completion and understanding when making a constructor call, reducing the likelihood of errors in the number or type of parameters.