CREATETEMPFILE length issue

jimmyfjimmyf Member Posts: 104
Hi
I am trying to create a temporary file using the following code

HTMLfile.CREATETEMPFILE;
HTMLfile.WRITE(HTMLcode);
HTMLfile.CLOSE

HTMLcode is a text variable.
However when I run it I get the following error.

WRITE is not supported for Text without a maximum length

The HTMLcode can be quite large and will exceed 1024

Is there any other way to do this?

Thanks

Answers

  • JuhlJuhl Member Posts: 724
    Follow me on my blog juhl.blog
  • rsaritzkyrsaritzky Member Posts: 469
    We have similar issues. We have code that creates an HTML email body based on a template. Our code that creates the HTML stream keeps track of the character count and divides it up into blocks of approx 500 characters. Here's some sample code that reads the body from the Instream and outputs it in blocks:
    
    Body := '';
    LookForVariable := FALSE;
    WHILE InStreamTemplate.EOS() = FALSE DO BEGIN
      InStreamTemplate.READTEXT(InSReadChar,1);
      IF InSReadChar = '{' THEN BEGIN
        SMTP.AppendBody(Body);
        Body := InSReadChar;                            // Body is now '{'
        IF InStreamTemplate.READTEXT(InSReadChar,1) <> 0 THEN;
        IF InSReadChar = '{' THEN                       // {{ ~ Variable
          LookForVariable := TRUE;
      END;
    
      Body := Body + InSReadChar;
    
      IF LookForVariable THEN BEGIN
        IF ReplaceVariable(Body,EmailTemplateSetup."Location Code",RecRef) THEN BEGIN
          SMTP.AppendBody(Body);
          Body := '';
          InSReadChar := '';
          LookForVariable := FALSE;
        END;
      END ELSE BEGIN
        IF STRLEN(Body) >= 500 THEN BEGIN
          SMTP.AppendBody(Body);
          Body := '';
        END;
      END;
    END;
    
    SMTP.AppendBody(Body);
    

    Hope this gives you some ideas.

    Ron
    Ron
Sign In or Register to comment.