K
K
Kevin Mitnick2014-12-18 19:49:29
Delphi
Kevin Mitnick, 2014-12-18 19:49:29

Delphi XE5 why doesn't "suspend, resume, terminate" work in a thread?

Hello. I create a thread in delphi:
postThread.Create(true);
Everything works fine, but I need to stop and suspend the execution of this thread in the program, but for this I need the "Terminate, Suspend, Resume" methods, but, for some unknown reason, they do not work. Delphi refuses to compile the code, indicating an error in the code:
postThread.Terminate;
Here is the error itself:

[dcc32 Error] Unit4.pas(63): E2076 This form of method call only allowed for class methods or constructor

Methods "Resume, Suspend" get out with the same error.
I have a thread class in a separate file, I tried to access methods in the main application window and through a procedure in the thread class itself, in both cases the same error occurs. What could be the problem ? Why don't these methods work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2014-12-18
@volfing

Your PostThread is not a variable, but a type. Therefore the code

type
  PostThread = class (TThread)
  end;

PostThread.Create(true);

fires, but the result of the constructor PostThread.Creategoes nowhere. And challenges PostThread.Resumeand the like are impossible - they are not class-based. It should be something like this...
type
  TPostThread = class (TThread)
  end;

var
  PostThread : TPostThread;

…
PostThread := TPostThread.Create(true);
PostThread.Resume;  // Suspend, Terminate и так далее…
…
PostThread.Free;   // Ну и убить его, наконец!

Your mistake: ignorance of the life cycle of an object; perhaps training in Turbo Pascal, in which everything is slightly different.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question