[DUG] basic question

Chee Wee Chua CheeWee.Chua at codegear.com
Wed Jul 25 17:04:51 NZST 2007


Delphi does not have class methods? News to me.

I wonder what these do:

  TShowOff = class
  public
    class procedure Static1;
    class procedure Static2; static;
  end;

Best Regards, 

Chua, Chee Wee 
CCNA, MCSE, SCJP, SCSA,
CodeGear(tm), from Borland
Where developers matter
www.codegear.com
 

> -----Original Message-----
> From: delphi-bounces at delphi.org.nz 
> [mailto:delphi-bounces at delphi.org.nz] On Behalf Of Neven MacEwan
> Sent: 25 July 2007 12:57
> To: NZ Borland Developers Group - Delphi List
> Subject: Re: [DUG] basic question
> 
> Ani
> 
> What you are referring to is a "Class Method" and no Delphi 
> does not have them (though other OO languages do) it also 
> does not have class variables (hence there is not need for 
> Class Methods is the logic I presume)
> 
> The reason your code works is that the method you called 
> makes no reference to the instance of FormB only to the 
> method of class FormB (and ShowMessage is a non OO 
> procedure), in compiled code there always on instance of the 
> code base (and data for the Object instances) so i assume 
> that you called "Execute" in the class method table in the 
> context of a nil instance If you had done
> 
>    procedure TFormB.Execute;
>     begin
>       ShowMessage(self.Caption); // AV Here
>     end;
> 
> I'm sure this is all wrong and Max or Paul will correct me
> 
> Cheers
> Neven
> 
> > Hi,
> >
> > Is it possible to call a method of a class without creating 
> a object 
> > of it, even if the method is not a class function in Delphi 
> ? I wrote 
> > the below code just to test -
> >
> > 1. Created a simple form A and a button on it.
> > 2. Created another simple form B, written a procedure in it as -
> >     FormB.Execute;
> >     begin
> >       ShowMessage("xyz");
> >     end;
> > 3. Commented out auto creation of FormB in application.
> > 4. On Button Click in FormA I called the Execute of FormB and it 
> > worked perfectly okay.
> >
> > What could be the reason for this? I had the idea that 
> either I need 
> > to create an object before calling any method or I need to 
> declare a 
> > class function.
> >
> > In the above steps when I am trying to call Show in Execute 
> function 
> > of Form B I got Access violation which is perfectly fine 
> according to 
> > the above statement.
> >
> > May be I am missing something simple here, but any pointers will be 
> > great. This was done in D2005 and it's win32 app.
> >
> > Thanks
> > -Ani
> >
> > 
> ----------------------------------------------------------------------
> > --
> >
> > _______________________________________________
> > NZ Borland Developers Group - Delphi mailing list
> > Post: delphi at delphi.org.nz
> > Admin: http://delphi.org.nz/mailman/listinfo/delphi
> > Unsubscribe: send an email to delphi-request at delphi.org.nz with 
> > Subject: unsubscribe
> 
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz 
> with Subject: unsubscribe
> 



More information about the Delphi mailing list