关于返回TStrings类型的怪问题。急救!!!
寒星 2001-09-29 10:35:23 代码如下:
function TMainFrm.GetTables(sSection: String): TStrings;
var
SysIni: TIniFile;
SecValues: TStrings;
strFile,ErrMsg: String;
begin
SysIni := TIniFile.Create(‘c:\Tables.INI');
try
SecValues := TStringList.Create;
try
SysIni.ReadSectionValues(sSection,SecValues);
SecValues := RetIniValue(SecValues);
GetTables := SecValues;
finally
SecValues.Free;
end;
finally
SysIni.Free;
end;
end;
procedure TMainFrm.Button1Click(Sender: TObject);
begin
sTables := TStringList.Create;
try
sTables := GetTables(SrvName);
showmessage(inttostr(sTables.count));
//这里报“Access Violation at address 00000000,Read of Address 00000000”,也不知道是什么问题。
finally
sTables.Free;
end;
end;
//但调用这个返回值为TStrings的函数就是正常的。
function TMainFrm.RetIniValue(IniValues: TStrings): TStrings;
var
i: integer;
begin
for i:=0 to IniValues.count - 1 do
begin
IniValues.Strings[i] := RetIniValue(IniValues.Strings[i])
end;
Result := IniValues;
end;