delphi我很弱,希望高手耐心指点,谢谢各位先!!函数原型:
//__int16 __stdcall Z8_GetTime(HANDLE icdev,unsigned char addr,unsigned char *time);
功能:返回time,格式为16进制 如06-9-6 20:23:12:0x06 0x09 0x06 0x20 0x23 0x12 DLEPHI 定义:
Function Z8_GetTime(icdev:integer;addr:integer;time:pchar):integer; stdcall;
far;external 'Z8rf32.dll' name 'Z8_GetTime';问题:现在返回的值为乱码 ,是delphi里定义函数不应该用TIME:PCHAR和unsigned char *time对应,还是pchar的值需要通过其他方法处理才能得到正确的时间。功能代码片断:
procedure TForm1.Button7Click(Sender: TObject);
var
i:integer;
p1:pchar;
mtime:string;
begin
try
GetMem(p1,100);
i:=Z8_GetTime(m_iHandle,m_iAddr,p1) ;
//m_iHandle,m_iAddr与出现问题无关,调试时发现P1的值为乱码
mtime:=string(p1);//调试mtime值为:#6#9#6#等
if i<>0 then
begin
ListBox1.Items.Add('error!');
exit;
end;
ListBox1.Items.Add('the time is:'+mtime);
FreeMem(p1);
except
on e:Exception do showmessage(E.Message);
end;
end;
//__int16 __stdcall Z8_GetTime(HANDLE icdev,unsigned char addr,unsigned char *time);
功能:返回time,格式为16进制 如06-9-6 20:23:12:0x06 0x09 0x06 0x20 0x23 0x12 DLEPHI 定义:
Function Z8_GetTime(icdev:integer;addr:integer;time:pchar):integer; stdcall;
far;external 'Z8rf32.dll' name 'Z8_GetTime';问题:现在返回的值为乱码 ,是delphi里定义函数不应该用TIME:PCHAR和unsigned char *time对应,还是pchar的值需要通过其他方法处理才能得到正确的时间。功能代码片断:
procedure TForm1.Button7Click(Sender: TObject);
var
i:integer;
p1:pchar;
mtime:string;
begin
try
GetMem(p1,100);
i:=Z8_GetTime(m_iHandle,m_iAddr,p1) ;
//m_iHandle,m_iAddr与出现问题无关,调试时发现P1的值为乱码
mtime:=string(p1);//调试mtime值为:#6#9#6#等
if i<>0 then
begin
ListBox1.Items.Add('error!');
exit;
end;
ListBox1.Items.Add('the time is:'+mtime);
FreeMem(p1);
except
on e:Exception do showmessage(E.Message);
end;
end;
mtime:=string(p1);//调试mtime值为:#6#9#6#等,
前面的值看上去有规律 但后面就是乱码了
日期为06-9-6 20:23:12 时
mtime:=string(p1);//调试mtime值为:#6#9#6#时间是乱码
日期为二位数如:11-10-12 20:23:12 时
mtime:=string(p1);//调试mtime值为:#$11#$10#$12#时间仍然是乱码
高手快出来帮帮忙啊 。
ZeroMemory(p1,100);试试,这样应该不会有乱码了吧