Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get a Related Item as Text with CRLF Line Endings
See more Email Object Examples
Demonstrates the Chilkat Email.GetRelatedStringCrLf method, which returns the text of a related item with CRLF (\r\n) line-endings, interpreting the item's bytes using the supplied charset. It is intended for text-based related items such as style sheets. This example reads an embedded CSS style sheet with normalized CRLF line endings.
Background: Embedded text may arrive with any style of line ending — bare
LF, bare CR, or CRLF. This method normalizes them all to CRLF, which is what internet protocols and many Windows tools expect, avoiding mixed-newline problems when the text is written out or re-transmitted. It is the CRLF counterpart to GetRelatedString (which uses bare CR).Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Email;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
email: TEmail;
content: string;
begin
// Demonstrates the GetRelatedStringCrLf method, which returns the text of a related item
// with CRLF line-endings, interpreting the bytes using the specified charset. This is
// intended for text-based related items such as style sheets. The index is zero-based.
email := TEmail.Create;
email.Subject := 'GetRelatedStringCrLf example';
// The HTML references a related style sheet by name (Content-Location).
email.SetHtmlBody('<html><head><link rel="stylesheet" href="styles.css"/></head><body>Styled.</body></html>');
// Add the related style sheet (index 0).
email.AddRelatedString2('styles.css','body { color: navy; }' + #10 + 'h1 { color: teal; }','utf-8');
// Get the first related item (index 0) as text with CRLF line endings.
content := email.GetRelatedStringCrLf(0,'utf-8');
WriteLn('Related item 0 text (CRLF-normalized):');
WriteLn(content);
email.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.