delphi写入文件的问题
代码如下:functionTFrm_Main.AddTnsnames():Boolean;constcTnsName_NewInstant='%s'+'='+#13#10...
代码如下:
function TFrm_Main.AddTnsnames(): Boolean;
const
cTnsName_NewInstant =
'%s' + ' =' + #13#10 +
' (DESCRIPTION =' + #13#10 +
' (ADDRESS_LIST =' + #13#10 +
' (ADDRESS = (PROTOCOL = TCP)(HOST = %s)(PORT = 1521))' + #13#10 +
' )' + #13#10 +
' (CONNECT_DATA =' + #13#10 +
' (SERVICE_NAME = %s)' + #13#10 +
' )' + #13#10 + ' )';
var
strmFile: TFileStream;
strData: string[255];
begin
if (Edit3.Text = '') or (Edit4.Text = '') or (Edit5.Text = '') then
begin
TMessageBox.ShowInfo('输入存在空值,请检查!');
Exit;
end
else
begin
strData := Format(cTnsName_NewInstant, [AYEdit3.Text, AYEdit5.Text, AYEdit4.Text]);
try
try
strmFile := TFileStream.Create('C:\Users\Admin\Desktop\config.ini', fmOpenWrite or fmShareExclusive);
strmFile.Seek(0, soFromEnd);
strmFile.WriteBuffer(strData, SizeOf(strData));
Result := True;
finally
strmFile.Free;
Result := False;
end;
except
TMessageBox.ShowInfo('写入文件失败!');
end;
end;
end;
测试时如果在三个edit分别输入:test,orcl,1.1.1.1时最终写入的是:
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 1.1.1.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)嚈遳茺 庶d? p驮 利 聂遳犝? 袡遳
蜷Z 茺 p驮 潲 寭E 旪
不知道是什么问题。求教。谢谢了!或者还有更好的方式写入那一段格式字符串吗。 展开
function TFrm_Main.AddTnsnames(): Boolean;
const
cTnsName_NewInstant =
'%s' + ' =' + #13#10 +
' (DESCRIPTION =' + #13#10 +
' (ADDRESS_LIST =' + #13#10 +
' (ADDRESS = (PROTOCOL = TCP)(HOST = %s)(PORT = 1521))' + #13#10 +
' )' + #13#10 +
' (CONNECT_DATA =' + #13#10 +
' (SERVICE_NAME = %s)' + #13#10 +
' )' + #13#10 + ' )';
var
strmFile: TFileStream;
strData: string[255];
begin
if (Edit3.Text = '') or (Edit4.Text = '') or (Edit5.Text = '') then
begin
TMessageBox.ShowInfo('输入存在空值,请检查!');
Exit;
end
else
begin
strData := Format(cTnsName_NewInstant, [AYEdit3.Text, AYEdit5.Text, AYEdit4.Text]);
try
try
strmFile := TFileStream.Create('C:\Users\Admin\Desktop\config.ini', fmOpenWrite or fmShareExclusive);
strmFile.Seek(0, soFromEnd);
strmFile.WriteBuffer(strData, SizeOf(strData));
Result := True;
finally
strmFile.Free;
Result := False;
end;
except
TMessageBox.ShowInfo('写入文件失败!');
end;
end;
end;
测试时如果在三个edit分别输入:test,orcl,1.1.1.1时最终写入的是:
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 1.1.1.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)嚈遳茺 庶d? p驮 利 聂遳犝? 袡遳
蜷Z 茺 p驮 潲 寭E 旪
不知道是什么问题。求教。谢谢了!或者还有更好的方式写入那一段格式字符串吗。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询