If you'll upgrade to Delphi 2010, you'll quickly notice that old code you were using to create threads, such as
constructor TMyThread.Create;
begin
inherited Create({CreateSuspended}true);
// must create event handle first!
FEventHandle := CreateEvent(
{security} nil,
{bManualReset} true,
{bInitialState} false,
{name} nil);
Resume;
end;
now produces a warning:
[DCC Warning] xxx.pas(277): W1000 Symbol ‘Resume’ is deprecated
Of course, you can change Resume to Start and it will work, but that's not a proper way to create threads. The proper way would be:
constructor TMyThread.Create;
begin
// create event handle first!
FEventHandle := CreateEvent(
{security} nil,
{bManualReset} true,
{bInitialState} false,
{name} nil);
inherited Create({CreateSuspended}false);
end;
The trick is that Delphi does not require "inherited Create" to be the first statement in descendant constructor body.
Calling TObject.Create from descendant constructor does not create an object and does not write zeros to all of object fields. It is TObject.NewInstance method that does that.
The call "fMyThread := TMyThread.Create;" is actually compiled into two calls:
The same principle also applies to Destroy and FreeInstance methods: calling ancestor Destroy is not required to be the last statement of destructor's body.
Comments
Post new comment