Recent

Author Topic: TCriticalSection (Solved)  (Read 13508 times)

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
TCriticalSection (Solved)
« on: November 14, 2010, 10:11:48 am »
Why is it
Quote
Illegal qualifier


type
Tmyfunc = function(mem:tmemorystream; prec:pMyStreamRec; score:integer): integer of object;
TScanThread=class(TThread)
private
  FCS:TCriticalSection;
  FIndex:integer;
protected
    procedure execute; override;
public
    constructor Create(AIndex:integer);
    destructor Destroy; override;
end;

implementation

{ TScanThread }
constructor TScanThread.Create(AIndex:integer);
begin
  FCS:=TCriticalSection.Create; // ILLEGAL QUALIFIER, why?
  FIndex:=AIndex;
  inherited Create(true);
end;

destructor TScanThread.Destroy;
begin
  freeandnil(FCS);
  inherited;
end;


Thanks :D
« Last Edit: November 14, 2010, 10:09:33 pm by xenablaise »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TCriticalSection
« Reply #1 on: November 14, 2010, 10:18:42 am »
Code: [Select]
TCRITICALSECTION = TRTLCriticalSection;
and

Code: [Select]
TRTLCriticalSection = packed record
    DebugInfo : pointer;
    LockCount : longint;
    RecursionCount : longint;
    OwningThread : THandle;
    LockSemaphore : THandle;
    SpinCount : ULONG_PTR;
  end;       

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TCriticalSection
« Reply #2 on: November 14, 2010, 10:25:56 am »
Code: [Select]
TCriticalSection.Create;This calls TCriticalSection's constructor IF it's a class.
Code: [Select]
TCRITICALSECTION = TRTLCriticalSection;
TRTLCriticalSection = packed record
    DebugInfo : pointer;
    LockCount : longint;
    RecursionCount : longint;
    OwningThread : THandle;
    LockSemaphore : THandle;
    SpinCount : ULONG_PTR;
  end;
As you post here, it's a packed record, NOT a class.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12712
  • FPC developer.
Re: TCriticalSection
« Reply #3 on: November 14, 2010, 02:02:15 pm »
It is also a class, just in a different unit. (syncobjs)

Put "syncobjs" as last unit in the uses clause in your original code and it will work.

This is a common confusion for people that come from older Delphi's, with more recent Delphi's (D7+ iirc), this class moved to syncobjs too

See e.g.

http://docwiki.embarcadero.com/VCL/en/SyncObjs.TCriticalSection

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: TCriticalSection (Solved)
« Reply #4 on: November 14, 2010, 10:09:04 pm »
Thanks

"syncobjs" did solved the issue. :D

Eko Wahyudin

  • New Member
  • *
  • Posts: 21
  • Indonesia
Re: TCriticalSection (Solved)
« Reply #5 on: August 25, 2011, 11:09:20 am »
// ILLEGAL QUALIFIER, why?

because there is two or more same symbol name on different unit.

eg. you have a variable on unit1;
unit unit1;
interface
var x: Integer;

unit unit2;
interface
var x: string;

and you use unit1 and unit2;

uses unit1, unit2;

then x:= 'hallo world';

it's will be error;


you can use code like this for your code

varCriticalSection := syncobjs.TCritialSection.Create;



Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TCriticalSection (Solved)
« Reply #6 on: August 25, 2011, 06:15:55 pm »
Quote
and you use unit1 and unit2;

uses unit1, unit2;

then x:= 'hallo world';

it's will be error;
Nope, it will be compiled OK. Identifiers are searched backward from the uses clause list. In this case, x is the same as unit2.x, which is indeed a string.

 

TinyPortal © 2005-2018