Understand class references this type

zhaozj2021-02-08  246

Question: Written in the book:

--------------------

Class reference is a type, it is not a reference to the object, nor is it a reference to a class,

It is a reference for the type of class. The reference type of the class defines the type of reference variable.

Suppose the user defines a class:

Type

CMYCLASS = Class

...

end

The following is defined below, the reference type of the category is related to the following class:

Type

MyclassRef = Calss of CMYCLASS

This declares two types of variables:

ACLASSREF: MyClassRef;

AOBJECT: CMYCLASS;

The first variable references an object, the second reference class:

Aclassref = CMYCLASS;

AOBJECT = CMYCLASS.CREATE;

--------------------

I can't understand this paragraph, please explain it. Thank you

From: PIPI., Time: 2002-2-8 23:13:00, ID: 916427 Also hold an example, such as I can write a function

TYPE TCONTROLCLASS = Class of tcontrol;

Procedure INSERT_CONTROL (CLS: TCONTROLCLASS);

Begin

Obj; = CLS.CREATE (Application);

Put Obj into FORM

END;

When you call, if you are INSERT_CONTROL (TEDIT), put it in FORM is an edit box.

If INSERT_CONTROL (TButton) is then put into FORM is a button

Thank you is

VAR CTL: TControlClass;

CTR: = TEDIT;

INSERT_CONTROL (CTL)

------------------------------

Note that we use TButton and Tedit that they have common ancestors TControl

We define a base class and then pass the different subclasses, then a function only writes a different effect.

From: Holyowl, Time: 2002-2-8 23:26:00, ID: 916440 The use of the reference is to create an object that cannot be determined in the compiler, lifting a list:

Type

Tcontrolcls = Class of tcontrol;

Function CreateComponent (Controlcls: tcontrolcls): tcontrol;

Begin

Result: = Controlcls.create (Form1);

...

END;

When calling:

CreateComponent (TMEMO); // Creating a TMEMO object

CreateComponent (TEDIT); // Create TEDIT object

From: Renrf, Time: 2002-2-9 0:07:00, ID: 916478 Thank you,

How is the example in my book understand?

From: PIPI., Time: 2002-2-9 0:29:00, ID: 916503 The example of your book is simpler, did not talk about the actual use at all

Just a place where ACLASSREF appears, you look into CMYCLASS.

From: TestNet, Time: 2002-2-16 1:17:00, ID: 923102 in advance, I haven't seen it yet

Type

Tcontrolcls = Class of tcontrol;

Function CreateComponent (Controlcls: TcontrolCls): tcontrol; begin

Result: = Controlcls.create (Form1);

...

END;

Function CreateComponent (Controlcls: tcontrol): tcontrol;

Begin

Result: = Controlcls.create (Form1);

...

END;

Is the result of these two stuff? What difference will there be? ? I only pay attention to the result

From: PIPI., Time: 2002-2-16 1:26:00, ID: 923112 is of course different

From: Beta, Time: 2002-2-16 2:34:00, ID: 923171to TestNet:

Change your two function names to CreateComponent1 and CreateComponent2

You are like this:

CreateComponent1 (TEDIT);

CreateComponent2 (TEDIT);

See the difference in the results?

From: Beta, Time: 2002-2-16 2:35:00, ID: 923172 The former requires the introduction of a class, while the latter requires access to an object (instance of class)

From: Beta, Time: 2002-2-16 2:43:00, ID: 923174 The previous function will create an instance of the class you incorporated, and the latter function, there is no meaning.

From: JHDANDCL, Time: 2002-2-16 10:53:00, ID: 923281 is more clear,

Type

MyclassRef = Calss of CMYCLASS / / indicates that myclassRef is a pointer to CMYCLASS or its parent class.

From: Leasun, Time: 2002-2-16 11:37:00, ID: 923316 The reference is like a pointer to the class.

From: TestNet, Time: 2002-2-16 12:41:00, ID: 923408 This feature is good

From: xiangya, Time: 2002-2-21 1:33:00, ID: 931109 | Editor did not say clear! [: D] See the explanation here:

Accurately, this is the original secondary identification of the compiler.

"I defined a lot of classes, of course, they are a system, then, I will become a certain type,

When you need an instance of a class or class (usually the latter), you will tell me the name of that class.

Then, I will give you the class, or the instance of the class. "In fact, this is not clear, behind,

"You are a pig, pig, he is a horse, horse, I am a head, human,"

Ok, "We are all called animal categories (there are animal categories in actual life [?] No!

It's all abstract concepts) So, the example of animal category we call a certain animal.

Now, the slaughterhouse should buy an animal, good! Is it a pig? Is it a horse? [?] No, it will not be a person.

In this way, we send a pig or horse (remember, this is type), no matter how, the slaughterhouse will get an animal.

Finally, some human instances have to eat [: D]

Think about it, then the following,

Type

Tcontrolcls = Class of tcontrol;

Function CreateComponent (Controlcls: tcontrolcls): tcontrol;

/ / Here is asking "Are you sending a horse or a pig? [?]"

/ / The result, the following code sent a window class [:)]

Begin

Result: = Controlcls.create (Form1);

...

END;

Function CreateComponent (Controlcls: tcontrol): tcontrol;

// Ask, you want the pig [?]

// A: I want the window of the window [^]

Begin

Result: = Controlcls.create (Form1);

...

END;

Ok, if you don't understand it, it is a pig. [:)] The last expression: What type of type you need, well, you tell me the type you want, I will build a such object.

[: (!] [:(!] Declare, don't misunderstand, I don't swear, I want to say this, your impression is very deep and better understood.

转载请注明原文地址:https://www.9cbs.com/read-1857.html

New Post(0)