[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

Instance of object of ancestors

if i have one ancestor name Form1 and two descendants derived from Form1 name Form2 and Form3, when the application is running the Form2 and Form3 is created, does this two Forms use the same instance of object of ancestors(Form1) ? or it will create the new instance object of ancestors(Form1) for each of them(Form2 and Form3) ?
0
dumper
Asked:
dumper
1 Solution
 
rwilson032697Commented:
Form inheritance works in exactly the same way as class inheritance. When form2 and form3 are created they essentially call their inherited constructors (which correspond to Form1).

The end result is that there are no instances of form1, merely an instance of form2 and form3 (which are really just classes derived from form1).

Does this clear it up for you?

Cheers,

Raymond.
0
 
dumperAuthor Commented:
so if i access the variable value in Form1 from Form2, the value will be the same as access from Form3,right ? so Form2 and Form3 is sharing the same instance of Form1 ?
0
 
qdyoungCommented:
No. There is no instance of TForm1. If you access variable Form1 in Unit1.pas, then you will get assignment error. If TForm1 has a public property named P. The TForm2 instance Form2 in Unit2.pas can assign it to 'ValueA', the TForm3 instance Form3 in Unit3.pas can assign it to 'ValueB' without effect Form2.P
  TForm is also just a VCL class, an object. You can refer to some Object-Oriented tech information.

Regards, Young.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now