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 8049085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:41:04+00:00 2026-06-05T06:41:04+00:00

I have a unit something like this type TMyClass = Class(TObject) private AnInteger :

  • 0

I have a unit something like this

type
 TMyClass = Class(TObject)
private
 AnInteger      : Integer;
 MyThreadHandle : DWORD;
 procedure MyPrivateProcedure;
public
 procedure MyPublicProcedure;
end;

procedure TMyClass.MyPrivateProcedure;
 procedure MyThread; stdcall;
 begin
  if AnInteger <> 0 then MyPublicProcedure;
 end;
var
 DummyID: DWORD;
begin
  MyThreadHandle := CreateThread(NIL,0,@MyThread,NIL,0, DummyID);
end;

procedure TMyClass.MyPublicProcedure;
begin
 AnInteger := 0;
end;

My goal is to have a Thread (no TTthread please.) that can “access” the vars/functions/procedures just like it’s part of the class. This Example fails because it doesn’t have access to the vars nor to the procedure. This is just an example, I am aware that the Integer can’t change just like that. To me it’s just important to have a thread that is part of the class. I also tried to pass the integer as a pointer (which worked) to the thread but I still can’t access a procedure/function of the class. any ideas?

  • 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-06-05T06:41:06+00:00Added an answer on June 5, 2026 at 6:41 am

    A thread has its own stack pointer, so you can’t access local variables or parameters (like the hidden Self parameter) in you MyThread local procedure (which BTW is declared wrong). Furthermore you can’t use local procedures for threads if they access variables (including Self) from the outer function. And if you want to use the 64bit compiler in the future, you can’t use local procedures for any callback.

    In your case you just have to fix the declaration of your procedure and move it into the unit scope (make it a “stand alone” procedure. This allows you to use the thread-callback parameter for “Self”.

    function MyThread(MyObj: TMyClass): DWORD; stdcall;
    begin
      if MyObj.AnInteger <> 0 then
        MyObj.MyPublicProcedure;
      Result := 0;
    end;
    
    procedure TMyClass.MyPrivateProcedure;
    var
      DummyID: DWORD;
    begin
      MyThreadHandle := CreateThread(nil, 0, @MyThread, Self, 0, DummyID);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code like this: case class FunctionCommand[A](function: Function1[Array[A], Unit]) class MyClass(commands: List[FunctionCommand[_]])
I have some data from DB then I need to load. Something like this
So, I have a function that looks something like this: function getUnits(squad_id) { $.ajax({
Say you have some boiler plate using statements. Say something like this: #if !NUNIT
I am looking to implement a continuous unit test running system, something I have
I have a unit test that tests if an Exception is throw, but this
I have a Unit test project for my Application using DUnit framework. This project
In my application I have use some data ValueCell (something like 20) and I
I have a column defined like this: <DataGridTextColumn Binding={Binding Path=FileSizeBytes, Mode=OneWay} Header=Size IsReadOnly=True />
I have this situation object SuperHorribleLongName { trait X { private[SuperHorribleLongName] def internalGaga() :

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.