Link to home
Start Free TrialLog in
Avatar of AngryC
AngryC

asked on

How can I store a large HTML string on a variable?

Hello,

I am wondering how can I store a complicated HTML code (multiline & with ' & " etc) on a string!

In PHP, for instance, I do the following:

$var = <<<html
What ever I want... ' "
code
code
etc...
html;

How can I do this in Delphi?

Your help would be greatly appreciated.
Avatar of Russell Libby
Russell Libby
Flag of United States of America image

What is the html code currently stored as (eg stream, string constant, pchar, etc)? The assignment to a string should not be a problem, but it would help to first know what the html code is currently stored as (or what component you are working with)

Regards,
Russell
Avatar of AngryC
AngryC

ASKER

It's not stored anywhere. I am writing it as the program is running.

Right click on this page and view the source... how can I store the source you see on a variable?

You are missed the point....
Are you working with a TWebBrowser control, an edit control, etc? As to right clicking the page and viewing the source, it would be as simple as:

(Notepad)
Edit | Select All
Edit | Copy

Then clicking the button on the following application:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Clipbrd, StdCtrls;

type
  TForm1         = class(TForm)
     Button1:    TButton;
     procedure   Button1Click(Sender: TObject);
  private
     // Private declarations
  public
     // Public declarations
  end;

var
  Form1:         TForm1;

implementation
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var  s:    String;
begin
  s:=ClipBoard.AsText;
  ShowMessage(s);
end;

end.

---

My point is that I am trying to determine WHERE the html text is originating from.

Russell
var s: string;
s := BigHtmlString;


e.g. with the Indy component (TIdHTTP fromteh Indy Clients tab) you would do

procedure TForm1.Button2Click(Sender: TObject);
    var
        s: string;
    begin
        IdHTTP1.HandleRedirects := True;
        S := IdHTTP1.Get('http://www.google.com');
        memo1.lines.text := s; // display it in a memo
    end;

you can do similar with TWebBrowse, which way did you want to do this?
Avatar of AngryC

ASKER

Let's assume I want to type the following by hand and place it into a string:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<title>Untitled Document</title>
</head>

'

Some contents

<body>
</body>
</html>

How can I do that? Notice the code is multi-line and it contains single and double quotes.
ASKER CERTIFIED SOLUTION
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AngryC

ASKER

TheRealLoki,

Your last solution is exactly what I am trying to do. But is the a way to not use the "+ #13#10 +" stuff?

Thanks.
Dont think so, not in the .pas file anyway
If you absolutely want to be able to write the html in a freefrom manner, but don't want an external file that users might change,
you could maybe put it in a resource file (which gets compiled in)
http://www.jansfreeware.com/articles/delphiresource.html