2

嗨,我正在尝试将所有这些内容放在一个字符串变量中,然后我用它来创建一个文本文件

问题是当您使用此代码时它总是失败:

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>

';

我必须做些什么才能使它工作?

4

1 回答 1

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;
于 2013-09-21T20:51:21.027 回答