Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Load MIME from a StringBuilder
See more MIME Examples
Demonstrates the Chilkat Mime.LoadMimeSb method, which parses complete MIME text from a StringBuilder and replaces the current MIME. The only argument is the StringBuilder.
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: When the MIME text already lives in a
StringBuilder — assembled in memory, or read and lightly edited — this loads it directly without an intermediate string copy. Its parsing behavior matches LoadMime; the difference is purely the source. For content that might include arbitrary binary bytes, use the BinData loader instead.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.Mime,
Chilkat.StringBuilder;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
sb: TStringBuilder;
mime: TMime;
begin
success := False;
// Demonstrates the Mime.LoadMimeSb method, which parses complete MIME text from a StringBuilder
// and replaces the current MIME. The only argument is the StringBuilder.
// Put the MIME text into a StringBuilder (here loaded from a file, but it could come from
// anywhere).
sb := TStringBuilder.Create;
success := sb.LoadFile('qa_data/message.eml','utf-8');
if (success = False) then
begin
WriteLn(sb.LastErrorText);
Exit;
end;
mime := TMime.Create;
success := mime.LoadMimeSb(sb);
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
WriteLn('Content-Type: ' + mime.ContentType);
sb.Free;
mime.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.