主线程中的实时数据是这样采集来的,代码如下:
procedure TMainInterface.Timer1Timer(Sender: TObject); var
lXPosi: LongWord;
lYPosi: LongWord;
begin ErrCode := P1240MotRdMutiReg(
gCurrentBoard,
XYZU_Axis,
Lcnt,
lXPosi,
lYPosi,
lZPosi,
lUPosi);
TextXPositionLogic.Caption := Floattostr(Longint(lXPosi)/1000);
TextYPositionLogic.Caption := Floattostr(Longint(lYPosi)/1000);
在另外一个线程中我写的代码如下:unit Unit4;interfaceuses
Classes;type
CreateThread = class(TThread)
private { Private declarations }
protected
procedure Execute; override;
end;implementationuses P1240, Unit1, Unit2, Unit3;{ 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 CreateThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }{ CreateThread }procedure CreateThread.Execute; var
dX:Double;
dY:Double;
dWid:Double;
dHei:Double;
dRotAng:Double;Init:function:Longint;cdecl;
SetParameter:procedure (dVel:double;dOffVel:double;dLaserOn:double;dPoly:double;
dLaserOff:double;dPos:double;dDis:double;lFreq:longint;dPower:double);cdecl;
MarkEllipse:procedure (dX:double;dY:double;dWid:double;dHei:double;dRot:double);cdecl;
DllModule:THandle;begin
dX:=10.0; //我在这里怎么样把这些数据改为主线程传过来的变量
dY:=10.0;
dWid:=2.0;
dHei:=8.0;
dRotAng:=45;begin
DllModule:=LoadLibrary('LsrEllipse.dll');
if DllModule<>0 then @Init:=GetProcAddress(DllModule,'Init');
@SetParameter:=GetProcAddress(DllModule,'SetParameter');
@MarkEllipse:=GetProcAddress(DllModule,'MarkEllipse'); if (@Init<>nil)then
if (@SetParameter<>nil)then
if (@MarkEllipse<>nil)then
begin
Init();
SetParameter(100,2000,0.0002,0.2,0.6,1,0.2,1000,0.6);
MarkEllipse(dX,dY,dWid,dHei,dRotAng);
FreeLibrary(DllModule); end;end.即把TextXPositionLogic.Caption的值得赋给dX把TextYPositionLogic.Caption的值得赋给dY就可以了 请各位前辈帮帮忙 小弟 第一次接触到多线程.
procedure TMainInterface.Timer1Timer(Sender: TObject); var
lXPosi: LongWord;
lYPosi: LongWord;
begin ErrCode := P1240MotRdMutiReg(
gCurrentBoard,
XYZU_Axis,
Lcnt,
lXPosi,
lYPosi,
lZPosi,
lUPosi);
TextXPositionLogic.Caption := Floattostr(Longint(lXPosi)/1000);
TextYPositionLogic.Caption := Floattostr(Longint(lYPosi)/1000);
在另外一个线程中我写的代码如下:unit Unit4;interfaceuses
Classes;type
CreateThread = class(TThread)
private { Private declarations }
protected
procedure Execute; override;
end;implementationuses P1240, Unit1, Unit2, Unit3;{ 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 CreateThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }{ CreateThread }procedure CreateThread.Execute; var
dX:Double;
dY:Double;
dWid:Double;
dHei:Double;
dRotAng:Double;Init:function:Longint;cdecl;
SetParameter:procedure (dVel:double;dOffVel:double;dLaserOn:double;dPoly:double;
dLaserOff:double;dPos:double;dDis:double;lFreq:longint;dPower:double);cdecl;
MarkEllipse:procedure (dX:double;dY:double;dWid:double;dHei:double;dRot:double);cdecl;
DllModule:THandle;begin
dX:=10.0; //我在这里怎么样把这些数据改为主线程传过来的变量
dY:=10.0;
dWid:=2.0;
dHei:=8.0;
dRotAng:=45;begin
DllModule:=LoadLibrary('LsrEllipse.dll');
if DllModule<>0 then @Init:=GetProcAddress(DllModule,'Init');
@SetParameter:=GetProcAddress(DllModule,'SetParameter');
@MarkEllipse:=GetProcAddress(DllModule,'MarkEllipse'); if (@Init<>nil)then
if (@SetParameter<>nil)then
if (@MarkEllipse<>nil)then
begin
Init();
SetParameter(100,2000,0.0002,0.2,0.6,1,0.2,1000,0.6);
MarkEllipse(dX,dY,dWid,dHei,dRotAng);
FreeLibrary(DllModule); end;end.即把TextXPositionLogic.Caption的值得赋给dX把TextYPositionLogic.Caption的值得赋给dY就可以了 请各位前辈帮帮忙 小弟 第一次接触到多线程.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货