Здравствуйте!
у меня программа - сом сервер и клиент клиент проверяется значение переменной в бесконечном цикле и отображает её. цикл в отдельном потоке . выходит ошибка: приложение обратилось к интерфейсу относящемуся к другому потоку
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj;
type
TForm1 = class(TForm)
Button1: TButton;
ColorDialog1: TColorDialog;
Label1: TLabel;
Label2: TLabel;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
//Server:Variant;
public
{ Public declarations }
end;
var
Form1: TForm1;
status:boolean;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var co:check;
begin
//Server:=CreateOLEObject('MyServer.AutoServer');
end;
procedure TForm1.FormDestroy(Sender: TObject);
var co:check;
begin
//Server:=NULL;
co.Terminate;
end;
procedure TForm1.Button1Click(Sender: TObject);
var co:check;
begin
status:=false;
co:=check.Create(true) ;
co.Resume;
co.Priority:=tpLower;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
status:=true;
end;
end.
в основном потоке цикл работает
вот 2-й поток:
Код:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj, unit1, myserver_tlb, activex;
type
check = class(TThread)
private
{ Private declarations}
Server:Variant;
protected
procedure Execute; override;
procedure UpdateCaption;
//function check.CoInitializeEx (pvReserved : pointer; coInit : longint) : HResult; stdcall;
end;
implementation
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure check.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ check }
procedure check.Execute;
begin
CoInitializeEx (NIL, COINIT_APARTMENTTHREADED);
{ Place thread code here }
Server:=CreateOLEObject('MyServer.AutoServer');
while true do
begin
Synchronize(UpdateCaption);
sleep(300);
if status=true then //CoUninitialize(nil) and
exit;
end;
end;
procedure check.UpdateCaption;
begin
if Server.Color=0 then
form1.label2.caption:=('выкл') ;
if Server.Color=1 then
form1.label2.caption:=('вкл') ;
if Server.Color=2 then
form1.label2.caption:=('на половину взведён') ;
if terminated then exit;
end;
end.
Вроде бы надо сделать маршлинг. Помогите пожалуйста организовать маршлингв моём коде.