很长时间没有用D7,但是小应用原生代码还是要转回到D7.这两天在看同花顺和通达信,下载后的盘后数据下载想直接导入EXCEL。参考网上的同花顺数据格式介绍,下面的代码用于在TMEMO控件中显示文件头和文件内容。长时间不用D7,生殊处请见谅。
procedure TForm1.btOpenClick(Sender: TObject);
var
TM:TMemoryStream;
FHard:TDayRec;
PColDef:PByte;
s,i:integer;
tmp:Dword;
begin
if OpenDialog1.Execute then begin
FName:=OpenDialog1.FileName;
tm:=TMemorystream.Create;
try
tm.LoadFromFile(FName);
tm.Read(FHard,sizeof(TDayRec));
Memo1.Lines.Add(format('数据记录总数:%x / %d ',[fhard.rows,fhard.rows]));
memo1.Lines.add(format('数据记录内容开始地址:%x / %d ',[Fhard.StartAdd,Fhard.StartAdd]));
memo1.lines.add(format('每条记录的长度:%x / %d ',[FHard.RecordLenght,FHard.RecordLenght]));
memo1.lines.add(format('每个记录的列数:%x / %d ',[Fhard.ColNum,Fhard.ColNum]));
fhard.StartAdd:=sizeof(TDayRec)+fHard.ColNum*4;
memo1.Lines.add(format('数据记录内容真实开始地址:%x / %d ',[Fhard.StartAdd,Fhard.StartAdd]));
s:=FHard.ColNum*sizeof(TRecordDefine);
GetMem(PColDef,s);;
try
tm.Read(PColDef^,s);
for i:=0 to Fhard.ColNum-1 do begin
tmp:=PDWordArray(PcolDef)[i];
//tmp:=PDword(integer(pcoldef)+i*4)^;
memo1.Lines.add(format('列 %d: %x , 列长度:%x',[i,tmp,TColdef(tmp).ColLength]));
end;
finally
freemem(PColDef);
end;
finally
tm.Free;
end;
end;
end;
1