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/