J
JUMP1972
Unregistered / Unconfirmed
GUEST, unregistred user!
在DLL中有一个函数:将传入的文本文件的内容读入内存
library FaxForIVR;
uses
windows,
SysUtils,
forms,
activex,
Classes,
printers,
inifiles,
adodb,db;
{$R *.RES}
function ReadTxt(const FileName:string;RetTxtChar):integer;
var
f:TFileStream;
s:String;
begin
Result:=0;
if not FileExists(FileName) then Exit;
f:=TFileStream.Create(FileName,fmOpenRead or fmShareDenyNone);
try
SetLength(s,f.Size);
f.Read(s[1],f.Size);
RetTxt:=StrPCopy(RetTxt,S); //这一句出错:格式%s无效或与自变量不相容:为什么[]
Result:=1;
finally
f.Free;
end;
end;
exports
ReadTxt,
GetCustPowerFee;
begin
end.
测试代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var
schar;
f:TFileStream;
begin
if OpenDialog1.Execute then
begin
try
f:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
// GetMem(s, f.Size+1000);
GetMem(s, f.Size);
f.free;
if ReadTxt(OpenDialog1.FileName,s)=1 then
// if GetCustPowerFee(ExtractFilePath(Application.Exename),'10','200306',s)=1 then
Label3.Caption:=s
else
showmessage('fail');
finally
FreeMem(s);
end;
end;
end;
library FaxForIVR;
uses
windows,
SysUtils,
forms,
activex,
Classes,
printers,
inifiles,
adodb,db;
{$R *.RES}
function ReadTxt(const FileName:string;RetTxtChar):integer;
var
f:TFileStream;
s:String;
begin
Result:=0;
if not FileExists(FileName) then Exit;
f:=TFileStream.Create(FileName,fmOpenRead or fmShareDenyNone);
try
SetLength(s,f.Size);
f.Read(s[1],f.Size);
RetTxt:=StrPCopy(RetTxt,S); //这一句出错:格式%s无效或与自变量不相容:为什么[]
Result:=1;
finally
f.Free;
end;
end;
exports
ReadTxt,
GetCustPowerFee;
begin
end.
测试代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var
schar;
f:TFileStream;
begin
if OpenDialog1.Execute then
begin
try
f:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
// GetMem(s, f.Size+1000);
GetMem(s, f.Size);
f.free;
if ReadTxt(OpenDialog1.FileName,s)=1 then
// if GetCustPowerFee(ExtractFilePath(Application.Exename),'10','200306',s)=1 then
Label3.Caption:=s
else
showmessage('fail');
finally
FreeMem(s);
end;
end;
end;