doubt in object

ravisiva
ravisiva used Ask the Experts™
on
Dear all

 I think  the following two   class declarations   are same.

1.   TSample = Class

2   TSample =  Class(Tobject)

When i saw some delphi  coding in uint Dbtables( code  given below)


In one class the delare as   TBDECallback = class

and the other  class   delared as      TSessionList = class(TObject)


I think there is some specifice reason behind this

Can canbody explain this?

Thanx in   advance

Ravisiva


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


  TBDECallback = class
  private
    FHandle: hDBICur;
    FOwner: TObject;
    FCBType: CBType;
    FOldCBData: Longint;


    FOldCBBuf: Pointer;
    FOldCBBufLen: Word;
    FOldCBFunc: pfDBICallBack;
    FInstalled: Boolean;
    FCallbackEvent: TBDECallbackEvent;
  protected
    function Invoke(CallType: CBType; CBInfo: Pointer): CBRType;
  public
    constructor Create(AOwner: TObject; Handle: hDBICur; CBType: CBType;
      CBBuf: Pointer; CBBufSize: Integer; CallbackEvent: TBDECallbackEvent;
      Chain: Boolean);
    destructor Destroy; override;
  end;

{ TSessionList }

  TSessionList = class(TObject)
  private
    FSessions: TThreadList;

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You are right. "class" and class(TObject)" is exactly the same.

I use it this way:

// this is a forward declaration of the class
// i am not sure if (TObject) is allowed here
TMyClass = class;

TMyAnotherClass = class(TObject)
private
  // so it can be used here
  FMyObject: TMyClass;
end;

// to emphasize that this is not a forward declaration (TObject) is used here
TMyClass = class(TObject)
  ...
end;

So it is all a question of programming style and many Delphi programmers are sloppy with that.

Commented:
From the Delphi 7 help:
-----------
A class type declaration has the form

type className = class (ancestorClass)
      memberList
       end;

where className is any valid identifier, (ancestorClass) is optional, and memberList declares members--that is, fields, methods, and properties--of the class. If you omit (ancestorClass), then the new class inherits directly from the predefined TObject class.
---------
So it is NOT sloppy, it is purely optional.

Geoff M.
With sloppy i mean that the programmers often mix the use of "class" and "class(TObject)" in their sources.
That is definitely sloppy and bad style.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Commented:
Spurious, I agree. Still not convinced about the sloppy though - I worry more about other types of programming flaws such as lack of error handling/checking.

Geoff M.
This goes usually hand in hand. The cleaner the style the better the error handling.
A clean style indicates a programmer who cares about details. No wonder such a guy writes sources with less errors.
I have cleaned the style of the Jedi Code Library and the Jedi VCL. I know.

Commented:
I have some comments but I'll leave them out of this topic discussion. Suffice to say I agree in principle but not in this specific example.

Author

Commented:
Dear   gmayo

 It is True . But My  Question is somewhat different.
we agree   Mr. robert_marquardt  's Point also.

But my pt of view i thought   in    VCL files without any sigle reason they dddnt add  a  single line.
That is why i raise that question?

Thanks for your comments


Commented:
Sorry, you've lost me completely there. What are you asking?
Commented:
This form of declaration:

TSomeObject = Class;     (note ';' - ending of declaration)

is usually used as FORWARD declaration - you can use this identificator in declaration of other class before it's real definition to avoid circular referring


Example from stdctrls.pas

  TButtonControl = class;   /// forward declaration

  TButtonActionLink = class(TWinControlActionLink)
  protected
    FClient: TButtonControl;             //// we can use it!
...
  end;

 TButtonActionLinkClass = class of TButtonActionLink;

  TButtonControl = class(TWinControl)
 private
 protected
    function GetActionLinkClass: TControlActionLinkClass; override;
...

(real definition)

Commented:
Ah. Had the original example had a semicolon after the declaration I would have spotted it. As it didn't, I assumed it was a full declaration, just without the rest of the class. Amazing how a single character can change the whole picture...

Geoff M.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial