[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

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.
0
AngryC
Asked:
AngryC
  • 3
  • 3
  • 2
1 Solution
 
Russell LibbySoftware Engineer, Advisory Commented:
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
0
 
AngryCAuthor Commented:
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?
0
 
Russell LibbySoftware Engineer, Advisory Commented:

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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
TheRealLokiSenior DeveloperCommented:
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?
0
 
AngryCAuthor Commented:
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.
0
 
TheRealLokiSenior DeveloperCommented:
so you actually wish to add the html code manually?
you could put a TMemo on the form, and freeform type your html into that
then (in a button push for instance), go
var s: string;
begin
    s := memo1.lines.text;  
end;

'S' will include all the multi line and single and double quotes.

If you wish to load the html text from a file you could do
var
    sl: tstringlist;
    s: string;
begin
    sl := tstringlist.create;
    try
        sl.loadfromfile('c:\htmlfile.txt');
        s := sl.text;
    finally
        sl.free;
    end;
    showmessage(s);
end;

if you wish to have the code in the unit, without having to load it or type it into a memo then you will need to change the CRLF (endof lines) and single quotes to delphi-ise...
e.g.

s := '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' + #13#10 +
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' + #13#10 +
'<html xmlns="http://www.w3.org/1999/xhtml">' + #13#10 +
'<head>' + #13#10 +
'<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />' + #13#10 +
'<title>Untitled Document</title>' + #13#10 +
'</head>' + #13#10 +
+ #13#10 +
'single quote would be '' (i.e. type it twice)' + #13#10 +
+ #13#10 +
'Some contents' + #13#10 +
+ #13#10 +
'<body>' + #13#10 +
'</body>' + #13#10 +
'</html>';

if it is too big, you could go
s := s + 'extra stuff';

Maybe i'm just not understanding your question though, let me know if I'm on the wrong track
0
 
AngryCAuthor Commented:
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.
0
 
TheRealLokiSenior DeveloperCommented:
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now