Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7561829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:15:33+00:00 2026-05-30T13:15:33+00:00

The project below fails to run with access violation error. I use Delphi XE2

  • 0

The project below fails to run with “access violation” error. I use Delphi XE2 Update 3.

program Project1;

{$APPTYPE CONSOLE}

type
  TTestClass = class
  public
    class procedure Test;
  end;

var
  TestClass: TTestClass;

class procedure TTestClass.Test;
begin
end;

begin
  TestClass.Test;
end.

If i mark class procedure Test as “static”, there is no problem. Is this ‘as designed’?

P.S.: It was my mistake, shame on me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:15:34+00:00Added an answer on May 30, 2026 at 1:15 pm

    Yes, what you’ve witnessed is correct.

    Non-static class methods, just like instance methods, have a hidden Self parameter. For class methods, that refers to the class reference. It’s like the compiler transforms your method into this:

    type
      TTestClassClass = class of TTestClass;
    
    procedure TTestClass_Test(Self: TTestClassClass);
    

    When you call a class method on a non-class receiver (i.e., an object reference), the compiler inserts a call to ClassType to fill in that parameter with the run-time type of the object, like this:

    TTestClass_Test(TestClass.ClassType);
    

    The ClassType method fetches the address of the object’s VMT, but your variable doesn’t refer to any VMT. Your variable is either a null pointer or uninitialized, so attempting to dereference it to read the VMT address results in an access violation, if you’re lucky. (If you’re unlucky, it dereferences the address and the address happens to be somewhere else in your program’s address space, and the result is interpreted as a VMT pointer even though it’s not.)

    Call class methods on class references or valid object references only.

    TTestClass.Test;
    

    When you call it on a class-reference “literal” as above, the compiler already knows the value of the first parameter and transforms the call like this:

    TTestClass_Test(TTestClass);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run a Test Project on Visual Studio I use the code below
Update: XE2 Update 2 fixes the bug described below. The program below, cutdown from
i'm getting the below error, When compiling the Asp.Net web deploy project Could not
i have been developed my last project like below as by last architecture View
How do you define your UserControls as being in a namespace below the project
In my project i used this below function public function createIconMenu():NativeMenu{ var iconMenu:NativeMenu =
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
I am getting below EAccessViolation Exception in C++ Builder 2010 project. StackTrace is not
I'm doing a homework project that requires this: Below you will find the code
I'm using a thumbnail loader in my project the one mentioned below. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.