您好我正在尝试将所有这些内容都放在一个字符串变量中,然后我用它创建一个文本文件
问题是当你使用这段代码时总是会失败:
html: = '
<title> test </ title>
<STYLE type=text/css>
body, a: link {
background-color: black;
color: red;
Courier New;
cursor: crosshair;
font-size: small;
}
input, table.outset, table.bord, table, textarea, select, fieldset, td, tr {
font: normal 10px Verdana, Arial, Helvetica,
sans-serif;
background-color: black;
color: red;
border: 1px solid # 00FF0red0;
border-color: red
}
a: link, a: visited, a: active {
color: red;
font: normal 10px Verdana, Arial, Helvetica,
sans-serif;
text-decoration: none;
}
</ style>
';
我需要做些什么才能让它发挥作用?
答案 0 :(得分:4)
您必须使用+
字符串连接运算符正确连接字符串。
html: = '<title> test </ title>' + sLineBreak +
'<STYLE type=text/css>' + sLineBreak + sLineBreak +
'body, a: link {' + sLineBreak +
'background-color: black;' + sLineBreak +
'color: red;' + sLineBreak +
'Courier New;' + sLineBreak +
'cursor: crosshair;' + sLineBreak +
'font-size: small;' + sLineBreak +
'}'; // Keep going with the rest of your text
或者,只需使用TStringList
:
var
html: TStringList;
begin
html := TStringList.Create;
try
html.Add('<title> test </ title>');
html.Add('');
html.Add('<STYLE type=text/css>');
html.Add('body, a: link {');
html.Add('background-color: black');
html.Add('color: red;');
html.Add('Courier New;');
html.Add('cursor: crosshair;');
html.Add('font-size: small;');
html.Add('}'; // Keep going with the rest of your text
html.SaveToFile('YourFileName.html');
finally
html.Free;
end;
end;