Got it working.. still doesn't look nice.
How's this for wierd syntax?...

   TmyClass2(Tmyclass2).class1.doIt;

:)

Chris


> -----Original Message-----
> From: Myles Penlington [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, 2 October 2002 4:31 p.m.
> To: Multiple recipients of list delphi
> Subject: RE: RE: [DUG]: Class refs in classes
> 
> 
> No. You should be able to do this. It is in essence what 
> create does. Seems
> like the compiler is getting confused - perhaps try some 
> syntax variations
> to get it to work.
> 
> Myles.
> 
> 
> -----Original Message-----
> From: Chris Milham [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, 2 October 2002 4:29 p.m.
> To: Multiple recipients of list delphi
> Subject: RE: RE: [DUG]: Class refs in classes
> 
> 
> Thanks David,
> 
> The thing is, I don't want to have to instantiate anything.
> Yes, I agree the local variable thing is a problem. Does 
> Delphi have the
> equivalent of a class variable then? Variable is not the 
> right word.. what I
> really want is a static ref to a class that can be contained 
> in another
> class and accessed like a instance variable. Am I asking too 
> much? hmmm...
> 
> Thanks,
> 
> Chris
> 
> > -----Original Message-----
> > From: David Brennan [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, 2 October 2002 4:13 p.m.
> > To: Multiple recipients of list delphi
> > Subject: RE: [DUG]: Class refs in classes
> > 
> > 
> > Chris,
> > 
> > I'm guess that the problem isn't "accessing a class func 
> > through a ref to a
> > class". I think it is that you are trying to access a local 
> > variable of a
> > class without instantiating an instance of the class. The 
> > line with the
> > problem is:
> > 
> > Tmyclass2.class1.doIt;
> > 
> > The problem is actually the part "Tmyclass2.class1". The 
> > other part (ie
> > "class1.doIt") should be fine. The reason it doesn't work is 
> > that Tmyclass2
> > is a class reference and you can't access local variables of a class
> > reference (and class1 is a local variable).
> > 
> > For this to be working you need to instantiate an instance of 
> > Tmyclass2 as
> > follows...
> > 
> > var
> >   LMyClass2 : TMyClass2;
> > begin
> >   LMyClass2 := TMyClass2.Create;
> >   LMyClass2.Class1 := Tmyclass1; // Or any other Tmyclass1 
> > descendant class.
> >   LMyClass2.Class1.doIt;
> >   ...
> > end;
> > 
> > (with appropriate try finally's etc added of course).
> > 
> > Cheers,
> > David.
> > 
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED] 
> > [mailto:[EMAIL PROTECTED]]On
> > > Behalf Of Chris Milham
> > > Sent: Wednesday, 2 October 2002 3:45 p.m.
> > > To: Multiple recipients of list delphi
> > > Subject: [DUG]: Class refs in classes
> > >
> > >
> > > Hi,
> > >
> > > I have been trying to make a hierarchical library of routines
> > > using class procs/funcs. However Delphi 5 doesn't like me 
> > doing this.
> > > What I have tried to do is as follows (hope this makes sense..
> > > only important bits included):
> > >
> > > type
> > >   Tmyclass1 = class
> > >      class procedure DoIt;
> > >   end;
> > >   Tmyclass1class = class of Tmyclass1;
> > >   Tmyclass2 = class
> > >     class1:Tmyclass1class;
> > >   end;
> > >
> > > procedure TForm1.Button1Click(Sender: TObject);
> > > begin
> > >   Tmyclass1.doIt;   // <- no probs with using a class proc
> > >  // Tmyclass2.class1.doIt; // *** Delphi compiler doesn't like me
> > > doing this: accessing a class func through a ref to a class.
> > > end;
> > >
> > > class procedure Tmyclass1.DoIt;
> > > begin
> > >   ShowMessage('Hello');
> > > end;
> > >
> > >
> > > The error Delphi gives is: method identifier expected.
> > > I can understand this (yes, I've read the help on it) but why??
> > > I have tried numerous ways of getting this to work but had to
> > > resort one option....
> > > I can work around this by simply having a class proc in Tmyclass2
> > > that returns a Tmyclass1 class.
> > > eg.
> > >
> > > Tmyclass2 = class
> > >     class function class1:TmyClass1class;
> > > end;
> > >
> > > class function Tmyclass2.class1: TmyClass1class;
> > > begin
> > >   Result := tmyclass1;
> > > end;
> > >
> > > Then I can happily use this syntax: 'Tmyclass2.class1.doIt;'
> > > This seems a not-too-nice way of doing what I want.
> > > Any suggestions? Or am I trying to make Delphi be another 
> > language? ;)
> > >
> > > The other thing is: Is Delphi's optimiser smart enough to convert
> > > my 'class1'  function in Tmyclass2 into a static reference? ie.
> > > am I going to have a performance hit because of trying to do this
> > > hierarchical library thing?
> > >
> > > TIA,
> > >
> > > Chris
> > >
> > > ---
> > >
> > > Chris Milham
> > > Software Developer
> > > MedTech Software Ltd.
> > > Level M, 48 Market Place, Viaduct Basin, Auckland
> > > Ph. +649 3559666 Extn. 714, Fax +649 3774231
> > > E-mail: [EMAIL PROTECTED]
> > > Web: http://www.medtech-software.com
> > >
> > >
> > > This e-mail and any attachments are intended only for the person
> > > to whom it is addressed and may contain privileged, proprietary,
> > > or other data protected from disclosure under applicable law. If
> > > you are not the addressee or the person responsible for
> > > delivering this to the addressee you are hereby notified that
> > > reading, copying or distributing this transmission is prohibited.
> > > If you have received this e-mail in error, please telephone us
> > > immediately and remove all copies of it from your system. Thank
> > > you for your co-operation.
> > >
> > >  <<Chris Milham.vcf>>
> > >
> > 
> > --------------------------------------------------------------
> > -------------
> >     New Zealand Delphi Users group - Delphi List - 
> > [EMAIL PROTECTED]
> >                   Website: http://www.delphi.org.nz
> > To UnSub, send email to: [EMAIL PROTECTED] 
> > with body of "unsubscribe delphi"
> > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
> > 
> --------------------------------------------------------------
> -------------
>     New Zealand Delphi Users group - Delphi List - 
> [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED] 
> with body of "unsubscribe delphi"
> Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
> --------------------------------------------------------------
> -------------
>     New Zealand Delphi Users group - Delphi List - 
> [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED] 
> with body of "unsubscribe delphi"
> Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
> 
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to