Доброго дня, есть Frame там создаются потоки с CS. Создаю CS я при открытии формы вот так:
procedure TForm1.FormCreate(Sender: TObject);
begin
Frame21.CS := TCriticalSection.Create;
end;
Вот код Frame:
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
Vcl.Samples.Spin, SyncObjs;
type
TFrame2 = class(TFrame)
Button1: TButton;
Memo1: TMemo;
private
{ Private declarations }
public
CS: TCriticalSection;
{ Public declarations }
end;
Parser = class(TThread)
private
protected
procedure Execute; override;
public
constructor Create(CreateSuspended: Boolean);
end;
var
Frame: TFrame2;
CountAcc: integer;
Work: boolean;
implementation
{$R *.dfm}
constructor Parser.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
end;
procedure Parser.Execute;
begin
while Work do
begin
try
CS.Enter;
Inc(CountAcc);
//Прочий код
CS.Leave;
// Прочий код
except On E:Exception do begin
showmessage(e.Message);
sleep(1000);
end;
end;
end;
end;
end.
В итоге я получаю ошибку: