Hi David, Thanks for these pointers. Yes, you're right, I'm trying to fight the compiler and loosing ;)
I had considered a singleton class but I'd prefer it as a last resort. Now, what I am trying to do is create a hierarchical library of functions. eg. LibraryRoot Func1 Func2 . . SubLibrary1 AnotherFunc1 AnotherFunc2 AnotherSubLibrary FuncX FuncY . . Sublibrary2 BlaaFunc1 BlaaFunc2 . . . . Does this make sense? I would like to be able to access library funcs to as many levels deep as the library goes. I'm simply trying to do this for logical organisation of functions in a big project. Having entries like "LibraryRoot.SubLibrary1.AnotherSubLibrary.FuncX" (although certanly not that many chars!) is much more helpful for me when I'm looking at the code than just seeing "FuncX" and wondering where it lives, and helps (me) with consistintly naming things. I know I could use various addins etc to help but I like to be able to understand as much as poss what is going on by looking at the code itself. Hmmm, maybe I should pick up Java too, eh Jeremy? Anyone like to offer an opinion on my previous question about "Is Delphi's optimiser smart enough to convert my 'class1' function in Tmyclass2 into a static reference?" Many thanks, Chris > -----Original Message----- > From: David Brennan [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, 2 October 2002 4:48 p.m. > To: Multiple recipients of list delphi > Subject: RE: RE: [DUG]: Class refs in classes > > > Chris, > > I think the compiler is correct according to standard delphi > syntax. The > "class1:Tmyclass1class;" line is definitely defining a local > variable within > the TMyClass2 definition. The fact that the variable is a > class reference > variable doesn't make any difference. Just like any other > pointer or object > reference the variable doesn't exist until you instantiate an > instance of > TMyClass2. > > From the sound of it you might be wanting a constant class > reference within > TMyClass2 though I can't see what the benefit of this could > possibly be. In > any rate I don't think classes (or objects for that matter) > can contain > constants, short of a function which returns the class > reference (which you > have already pointed out). > > Maybe you should give us an idea of what you are really > trying to do as > there may be another way. For example you could automatically create a > singleton instance of TMyClass2 which then maintains pointers > to other class > references? > > David. > > > -----Original Message----- > > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]]On > > Behalf Of Myles Penlington > > 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/ > --------------------------------------------------------------------------- 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/