VC的接口问题(55分)

G

grace

Unregistered / Unconfirmed
GUEST, unregistred user!
1,(30)
已经存储了一些real类型数据在文件里
var r1: real;
F: file;
blockwrite(F, r1, sizeof(r1));
用VC怎么读取这些数据
因为VC里没有类似borland的6字节浮点的数据类型
2,(25)
VC中怎么读取paradox数据库
可以用ODBC,可是有许多机器里并没有pdx的ODBC驱动
那么发布的时候怎么办?
 
1, try open the file as binary.
 
没问题,我是按2进制打开的,您的意思是按borland的浮点数标准另行计算出来?
 
其实Delphi的real也是8字节的,real是double的别名
在Delphi1.0中好象是6字节,在新版本中6字节的浮点数的类型名是real48
 
我现在用的是delphi3,确实是6字节的,没有疑问
 
升级,就成8字节了 :)
 
我现在的任务是兼容以前的应用,升级是不能解决问题的
 
看来我的问题真的很难哦!
 
真的没有人回答?
 
我似乎找到了6字节real到double的转换方法,可我马上要上课来不及写
等回来再说
Please Wait ......
 
阿康哥你要快呀,不然小弟就要被炒鱿鱼了
注意我现在必须用VC
 
我用Delphi写一段程序,自己把它翻译成VC吧
假设将一6字节的real读到r[1],r[2],...,r[6]中 (r:array[1..6] of byte);
function real48todouble:double;
var p,i,j:integer;
b:array[1..40] of byte;
begin
if a[1]=0 then
Result:=0
else
begin
p:=a[1]-128;
for i:=6do
wnto 2do
for j:=7do
wnto 1do
if a and power(2,j)=0 then
b[8*(7-i)-j]:=0
else
b[8*(7-i)-j]:=1;
Result:=power(2,p);
for i:=2 to 40do
if b=1 then
Result:=Result+power(2,p+1-i);

if a[1]=1 then
Result:=-Result;
end;
end;

用vc应该更简单,因为可以用位运算.只是我对vc的语法有些生疏了,只好用Pascal写
仓促写成,还没调试,有错就多包涵吧 :)
 
sorry
应该是 p:=a[1]-129, 不是128
 
又有错误 for j:=7do
wnto 0 不是downto 1
 
kang 啊,看来真的把你累得够呛
你是根据(-1)s*(1.f)*exp(p)
这个公式计算的吧,我现在也是这么处理的,只是觉得有些讨厌
速度也受影响吧,iie给我发的程序用了and/or操作,那就是你说的位操作吧
 
研究下double的结构,看看有没有简单方法
 
用Delphi转成Double型存储到文件,再用VC吧
Prcedure Real48ToDouble;
var fs,fd:file of byte;
r:array[1..6] of byte;
d:array[1..8]of byte;
p,i:byte;

begin
assignfile(fs,sourcefilename);
reset(fs);
assignfile(fd,desfilename);
rewrite(fd);
//or reset(fd) if it is exist.
try
while not eof(fs)do

begin
for i:=1 to 6do
read(fs,r);
if a[1]=0 then
for i:=1 to 8do
d:=0
else
begin
p:=a[1]-130;
//p =power-1;
d[8]:=p div 16+64;
if a[6] and 128>0 the Inc(d[8],128);
d[7]:=16*(p mod 16)+(a[6] and 120 shr 3);
for i:=6do
wnto 3do
d:=(a and 7 shl 5)+(a[i-1] and $f8 shr 3);
d[2]:=a[2] and 7 shl 5;
end;
for i:=1do
8do
write(fd,d);
end;
finally
closefile(fd);
closefile(fs);
end;
end;
 
对不起,还得改一句:
d[2]:=..... h后加一句 d[1]:=0;
 
要是这样的话倒不如
var areal: real;
adouble: real;
begin
adouble := areal;
blockwrite(f, adouble, sizeof(adouble);
end;

你说呢?
关键是我不能改delphi源程序了,我这里只有接口(已存的文件)
 
我的已经把6字节的real文件转成8字节的double文件,你的恐怕不行吧(都是6字节)
你把它翻译成VC不就行了,我好长时间不用c,语法不太熟了
 

Similar threads

顶部