![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 6 of 6 total |
![]() |
Wed, Nov 8 2017 7:25 AM | Permanent Link |
Michael Dreher | I have made a mistake and accidental referenced a class instance variable from a class method.
It would be fine if the compiler will report an error in this case. Example: type TMyClass = class public i : integer; procedure foo; class procedure cFoo; property GetI : integer read i write i; end; implementation procedure TMyClass.foo; begin end; class procedure TMyClass.cFoo; begin // This all compiles but should be rejected i := 42; foo; GetI := i*2; end; Michael Dreher |
Wed, Nov 8 2017 10:52 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. ![]() | Michael,
<< I have made a mistake and accidental referenced a class instance variable from a class method. It would be fine if the compiler will report an error in this case. >> I think I may have done this on purpose, but I'm not sure and will have to confirm it. Tim Young Elevate Software www.elevatesoft.com |
Mon, Dec 11 2017 2:28 AM | Permanent Link |
Michael Dreher | I just updated to 2.06B11 and noticed, access of class instance members from a class method is not possible anymore. Fine. However, this now is also true when accessing instance members of a concrete instance. Example:
type TMyClass = class public // ... class procedure cBar; end; class procedure TMyClass.cBar; var c : TMyClass; iValue : integer; begin c := TMyClass.Create; c.Foo; // [Error] Cannot access the Foo() instance member from within a class method iValue := c.GetI; // [Error] Cannot access the GetI instance member from within a class method iValue := c.i; // [Error] Cannot access the i instance member from within a class method end; Is this intentionally or accidentally? Michael Dreher |
Mon, Dec 11 2017 3:41 AM | Permanent Link |
Matthew Jones | Michael Dreher wrote:
> Is this intentionally or accidentally? Your example is incomplete, not having mention of those methods etc. At first look, I think it should be intentional, as you do not have a "self" to provide the reference. But in your example, the class method is creating an instance, so it should work for the references off that. I suspect that the compiler is being clever but not clever enough. What happens if you move your code into an ordinary procedure and call that from your class procedure? That may be a viable work around to save the compiler getting too complex. -- Matthew Jones |
Mon, Dec 11 2017 4:44 AM | Permanent Link |
Michael Dreher | "Matthew Jones" wrote:
// Your example is incomplete, not having mention of those methods... Sorry, it's an extension to the class of my first post, the missing members are there. // What happens if you move your code into an ordinary procedure // and call that from your class procedure? That may be a viable work around.... This works and is a work around, thanks! M. Dreher |
Mon, Dec 11 2017 1:23 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. ![]() | Michael,
<< I just updated to 2.06B11 and noticed, access of class instance members from a class method is not possible anymore. Fine. However, this now is also true when accessing instance members of a concrete instance. >> Yeah, I think that the compiler checks are not being fine-grained enough and aren't looking at the qualifying references. I'll have a fix for this in the next build. Tim Young Elevate Software www.elevatesoft.com |
This web page was last updated on Monday, September 25, 2023 at 03:00 PM | Privacy Policy![]() © 2023 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |