2

Hi I am trying to get all this content in a string variable which I then used to create a text file

The problem is that it always fails when you use this code:

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>

';

What I have to do to make it work ?

2
  • 2
    You have to enclose each line in '' quotes and concatenate such enclosed strings together. For instance this way. Commented Sep 21, 2013 at 20:49
  • By the way, there are multiple issues with your HTML and CSS. Commented Sep 21, 2013 at 22:51

1 Answer 1

4

You have to properly concatenate the string, using the + string concatenation operator.

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

Or, simply use a 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;
Sign up to request clarification or add additional context in comments.

2 Comments

#13#10 for a windows linebreak but you should be using sLineBreak instead of these magic constants. If you use sLineBreak then your code works on all platforms.
@David: Yes, I agree. Edited accordingly (and to fix missing closing parens).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.