Sign in Join
Wiki copytemporary

Reintroduce: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Reintroduce

OldNewLine
1+The [[modifier]] `reintroduce` belongs to [[object-oriented programming]]. The modifier `reintroduce` allows a method of the parent [[Class|class]] to be concealed by a new [[Method|method]] with the same name. That is, a new method exists in the class derived from the parent class and in all other classes derived from it. The method in the parent class is preserved and can still be used by it.
2+
3+The method of the parent class does not exist anymore in the new class, it has been replaced by the new method with the same name. The method continues to exist in its original form in the parent class and can be used through the parent class. This is as opposed to [[modifier]] override which only works for virtual methods. The [[modifier]] reintroduce merely suppresses a warning that a similar method already exists and that the programmer is aware of that.
4+
5+Example:
6+
7+``` pascal
8+interface
9+
10+type
11+ TParentClass = class
12+ procedure SetTest(intNum: Integer); // Some method
13+ end;
14+
15+ TDerivedClass = class(TParentClass)
16+ procedure SetTest(strName: String); reintroduce; // This replaces the method of the parent class in the derived class. And supresses warnings that a method with an identical signature already exists.
17+ end;
18+
19+implementation
20+
21+procedure TDerivedClass.SetTest(strName: String);
22+begin
23+ inherited SetTest(1); // Call method with same name from parent class, if needed
24+end;
25+```
26+
27+---
28+*From the Free Pascal wiki, page "Reintroduce", as it stood on 2019-11-10 after a change by Thaddy, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history