关于函数出错 ( 积分: 100 )

  • 主题发起人 主题发起人 kwmxw
  • 开始时间 开始时间
K

kwmxw

Unregistered / Unconfirmed
GUEST, unregistred user!
在 myfun中定义函数
function readinistr(ininame,secname,ident,mystr:pchar):pchar
var
myini:Tinifile;
begin
try
try
myini:=tinifile.create(ininame)
result:=myini.readstring(secname,ident,mystr);
except
on e:exception do
showmessage(e.messages);
end;
finally
myini.destroy;
end;
end;

然后在datamodule中调用
uses myfun;

readinistr('boot.ini','database','server','');
不能出现正常结果,调试出现stock overflow 请问该如何解决?
 
你分多 ^_^

function ReadIniStr(IniName,SecName,Ident:string):String
var
MyIni:TiniFile;
begin
try
try
MyIni:=TIniFile.create(ExtractPath(ParamStr(0))+IniName);
Result:=MyIni.ReadString(SecName,Ident,'');
except
on E:Exception do
ShowMessage(E.messages);
end;
finally
MyIni.free;
end;
end;
 
const
M_ININame = 'boot.ini'; // ini文件名

....

Procedure Create_INI(INIPath: String);
Var
INI_File: TextFile;
Begin
If Not FileExists(INIPath) Then
Begin
AssignFile(INI_File, INIPath);
Rewrite(INI_File);
CloseFile(INI_File);
End;
End;
procedure Put_INI_String(atype, aheader, aData: String);
var
INIPath: String;
MyIniFile: TIniFile;
begin
INIPath := Format('%s%s',[ExtractFilePath(ParamStr(0)), M_ININame]);
Create_INI(INIPath);
if FileExists(INIPath) then
Begin
MyIniFile := TIniFile.Create(INIPath);
try
MyIniFile.WriteString(Atype, aheader, aData); //写:
finally
MyIniFile.Free;
end;
End;
end;
 
明天回到班上发个给你.我写的函数.读写INI文件.
 
Function ReadIniStr(ininame, secname, ident, mystr: PChar): PChar;
Var
myini: Tinifile;
Begin
myini := TIniFile.Create(ininame);
Result := PChar(myini.ReadString(secname, ident, mystr));
myini.Free;
End;

procedure TForm1.Button5Click(Sender: TObject);
begin // 通过测试
ShowMessage(PChar(ReadIniStr('C:/MyDBGridEh1.ini','MyDBGridEh1','FieldName.List','')));
end;
 
后退
顶部