请问c++ 和 Object Pascal的问题!(懂C++的请近)(100分)

  • 主题发起人 主题发起人 hug
  • 开始时间 开始时间
H

hug

Unregistered / Unconfirmed
GUEST, unregistred user!
struct MultiMoveData{
short Axis;
short TS;
long Pos;
long StrVel;
long MaxVel;
long Acc;
long Dec;
long Jerk;
};
int Move4( long x, long y, long z, long u,
long start, long speed, long accel, long decel)
{
static MultiMoveData data[4];
static double k;

long len = sqrt( x*x+y*y+z*z+u*u );
if( len < 1 ) return 0;

long pos[4]={ x, y, z, u };


for( int i(0)
i<4
i++)
{
data.Axis = i;
data.TS = 0

data.Pos = pos;
k = (double)pos/double(len);
data.StrVel = long(k*start);
data.MaxVel = long(k*speed);
data.Acc = long(k*accel);
data.Dec = long(k*decel);
data.Jerk = 1

}
d3000_start_multi_move( 4, data );
return 1;

}
的原行为:DWORD WINAPI d3000_start_multi_move(short TotalAxis,
struct MultiMoveData *DataArray);
请帮我改为pascal语句,谢谢,(c++里的struct 与pascal的record数据类型形同吗?)
 
type MultiMoveData=record
Axis :shortint;
TS :shortint;
Pos :longint;
StrVel :longint;
MaxVel :longint;
Acc :longint;
Dec :longint;
Jerk :longint;
end;
function Move4(x,y,z,u,start,speed,accel,decel:longint):Integer;
var data:Array[0..3] of MultiMoveData;
k:Double;
len:Longint;
pos:Array[0..3] of longint;
i:integer;
begin
Result:=0;
len:=Trunc(sqrt( x*x+y*y+z*z+u*u ));
if( len < 1 ) then Exit;

pos[0]:=x;pos[1]:=y;pos[2]:=z;pos[3]:=u;

for i:=0 To 4-1 do
begin
data.Axis := i;
data.TS := 0;
data.Pos := pos;
k := pos/len;
data.StrVel := trunc(k*start);
data.MaxVel := trunc(k*speed);
data.Acc := trunc(k*accel);
data.Dec := trunc(k*decel);
data.Jerk := 1;
end;
d3000_start_multi_move( 4, data );
Result:=1;
end;
 
谢谢您,我是这样改的,帮我看看可以吗?还有一个问题,即使
c++里的struct 与pascal的record数据类型形同吗?会不会由于数据
类型不同而报错),我的修改如下:
MultiMoveData = record
Axis: SmallInt;
TS: SmallInt;
Pos: LongInt;
StrVel: LongInt;
MaxVel: LongInt;
Acc: LongInt;
Dec: LongInt;
Jerk: LongInt;
end;
function MoveFour(x, y, z, u, start, speed: integer
accel, decel: double):
integer;
var
Len: double;
K: double;
pos: array[0..3] of LongInt;
AsxiIndex: integer;
Data: array of MultiMoveData;
begin
len := sqrt(x * x + y * y + z * z + u * u);
if (len < 1) then
result := 0;
//pos[0,1,2,3]:=[ x, y, z, u ];
pos[0] := x;
pos[1] := y;
pos[2] := z;
pos[3] := u;
//double k(0.0);
setlength(Data,4);
for AsxiIndex := 0 to 3 do
begin
Data[AsxiIndex].Axis:=AsxiIndex;
Data[AsxiIndex].TS:=0;
Data[AsxiIndex].Pos:=Pos[AsxiIndex];
k := 1.0 * pos[AsxiIndex] / len;
Data[AsxiIndex].StrVel:=round(k*Start);
Data[AsxiIndex].MaxVel:=Round(k*Speed);
Data[AsxiIndex].Acc:=round(k*accel);
Data[AsxiIndex].Dec:=round(k*decel);
Data[AsxiIndex].Jerk:=1;
end;
d3000_start_multi_move( 4, data);
result := 1;
end;
 
由于试调用dll,我将函数
DWORD WINAPI d3000_start_multi_move(short TotalAxis,
struct MultiMoveData *DataArray);
作如下修改:function d3000_start_multi_move
( Asis:SmallInt;DataArrAy:array of MultiMoveData):integer;stdcall;
问题在哪里?试我的不对还是他们的dll函数有问题?
 
function d3000_start_multi_move
( Asis:SmallInt;Var DataArrAy:MultiMoveData):integer;stdcall;
 
DataArrAy:array of MultiMoveData
这个参数不对
可以这样:
type
PMultiMoveDataArray = ^MultiMoveDataArray;
MultiMoveDataArray = array[0..0]of MultiMoveData;
function d3000_start_multi_move
( Asis:SmallInt;DataArrAy:PMultiMoveDataArray):integer;stdcall;
 
type
PMultiMoveData = ^TMultiMoveData;
TMultiMoveData = packed Record
Axis : short;
TS : short;
Pos : LongInt;
StrVel : LongInt;
MaxVel : LongInt;
Acc : LongInt;
Dec : LongInt;
Jerk : LongInt;
end;

function d3000_start_multi_move(TotalAxis : short;
DataArray : PMultiMoveData) : DWORD
stdcall;
external 'FileName.DLL';

function Move4(x, y, z, u, start, speed, accel, decel : LongInt) : Integer;
var
//static
data : array[0..3] of TMultiMoveData;
//static
k : double;
len : LongInt;
pos : array[0..3] of LongInt;
i : Integer;
begin
len := TRUNC(sqrt(x*x+y*y+z*z+u*u));
if len < 1 then
begin
Result := 0;
Exit;
end;
pos[0] := x
pos[1] := y
pos[2] := z
pos[3] := u;
for i := 0 to 3 do
begin
data.Axis := i;
data.TS := 0;
data.Pos := pos;
k := pos/len;
data.StrVel := TRUNC(k*start);
data.MaxVel := TRUNC(k*speed);
data.Acc := TRUNC(k*accel);
data.Dec := TRUNC(k*decel);
data.Jerk := 1;
end;
d3000_start_multi_move( 4, @data );
Result := 1;
end;
 
谢谢大家,我是试,大家的代码
 
谢谢大家,amli的正确,谢谢
 
多人接受答案了。
 
后退
顶部