Quantcast
Channel: Embarcadero Community - Embarcadero Community
Viewing all articles
Browse latest Browse all 3212

A question about constructors in Delphi

$
0
0

I would like to ask if calling a constructor within another constructor of the same class is always safe? In Java language special word this() is used in such cases.   For example:  

type
	A = class
		a,b: integer;
		constructor Init; overload;
		constructor Init(x:integer); overload;

		procedure print;
	end;

	constructor A.Init;
	begin
		a:=-1;
		b:=-1;
		writeln('Init');
	end;

	constructor A.Init(x:integer);
	begin
		Init;
		// is it always safe?
		a:=x;
		writeln('InitX');
	end;

	procedure A.print;
	begin
		writeln('a=',a,' b=',b);
	end;

	var
		o : A;

	begin
		o:=A.Init(10);
		o.print;
		readln;
	end




Viewing all articles
Browse latest Browse all 3212

Trending Articles