Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
What does "class" before a object method declaration mean? Posted by earth_walker on 17 Jul 2003 at 8:07 AM
Hi! When I check the declaration of TObject in "System" unit, I found these code:
  TObject = class
    constructor Create;
    procedure Free;
    class function InitInstance(Instance: Pointer): TObject;


There is a keyword "class" before the declaration of function "InitInstance", can you tell me what does it mean or which part of help file shall I read?

Thank you!
Report
Re: What does "class" before a object method declaration mean? Posted by earth_walker on 17 Jul 2003 at 8:20 AM
Hi! I find the documentation of Class methods. It tells that "class" before the declaration means the method is a Class Method. The way to find this documentation is to type in "class method" from index of help.

Documentation tells:
"A class method can be called through a class reference or an object reference. When it is called through and object reference, the class of the object becomes the value of Self."

However, I still don't know what is the difference between a Class Method and other methods.

Also, "the class of the object becomes the value of Self" => "class becomes value of Self", here "Self" is a variable. I don't understand why class can become a variable.

Thank you!
Report
Re: What does "class" before a object method declaration mean? Posted by injektilo on 17 Jul 2003 at 9:37 AM
This message was edited by injektilo at 2003-7-17 9:44:22

this is the core of delphi, the class method is build in into the compiler itselve, not available for us.

when calling it, it runs some code to register the class for windows wheter it is an object class or other, delphi knows what to do with it.

so TObject is the first class object created with the classmethod and you should start from there, or if you are programming a compiler then you should start to learn ASM :)) (wich you probebly allready have)


Report
Re: What does "class" before a object method declaration mean? Posted by earth_walker on 17 Jul 2003 at 9:58 AM
Thank you! You told me something in the kernal of Delphi, which is very useful to understand a programming language.

However, the thing currently I'm concerning is:
what is the difference between "InitInstance" and other method defined without "class" in front of it.
TObject = class
    constructor Create;
    procedure Free;
    class function InitInstance(Instance: Pointer): TObject;


Thank you!

Report
Re: What does "class" before a object method declaration mean? Posted by zibadian on 17 Jul 2003 at 10:26 AM
: This message was edited by injektilo at 2003-7-17 9:44:22

: this is the core of delphi, the class method is build in into the compiler itselve, not available for us.
:
: when calling it, it runs some code to register the class for windows wheter it is an object class or other, delphi knows what to do with it.
:
: so TObject is the first class object created with the classmethod and you should start from there, or if you are programming a compiler then you should start to learn ASM :)) (wich you probebly allready have)
:
:
:
A class method is not something for the core of Delphi, but a method, which can also be applied to the class definition itself. Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Button1.Caption := TButton.ClassName; // a class function
end;

This code will show the name of the class itself, not an instance of the object. Since ClassName() is a class method (see help file), this is a valid code, while the following code will generate an error:
procedure TForm1.Button1Click(Sender: TObject);
begin
  TButton.Click; // not a class method
end;

The Click() method cannot be called from the class definition of a TButton, but only from an TButton instance.
Report
Re: What does "class" before a object method declaration mean? Posted by earth_walker on 17 Jul 2003 at 2:34 PM
Thank you! I understand now.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.