program Umlaute;

{$ifdef fpc}
  {$mode objfpc}{$H+}
{$endif}

Uses
  {$ifdef fpc}
    {$ifdef Linux}
       CWString,
    {$endif}
    LCLType,
    Interfaces,
  {$else}
    WinTypes,
  {$endif}
  SysUtils,
  Forms;

{$ifndef fpc}
  type UTF8String  = String;
       AnsiString  = String;

  function AnsiToUTF8(s : AnsiString) : UTF8String;
    begin
      { Bei Delphi bleibt es ANSI }
      AnsiToUTF8 := s;
    end;
{$endif}

function MsgBox(Text, Caption : AnsiString; Flags : LongInt) : Integer;
  var    TextBuffer,
         CaptionBuffer : PChar;
         UTF8Text,
         UTF8Caption   : UTF8String;
  begin
    UTF8Text      := AnsiToUTF8(Text);
    UTF8Caption   := AnsiToUTF8(Caption);
    TextBuffer    := StrAlloc(Length(UTF8Text)    + 1);
    CaptionBuffer := StrAlloc(Length(UTF8Caption) + 1);
    StrPCopy(TextBuffer,    UTF8Text);
    StrPCopy(CaptionBuffer, UTF8Caption);
    MsgBox := Application.MessageBox(TextBuffer, CaptionBuffer, Flags);
    StrDispose(TextBuffer);
    StrDispose(CaptionBuffer);
  end;

begin
  {$ifdef fpc}
    Application.Initialize;
  {$endif}
  MsgBox('äöüßÄÖÜ', 'äöüßÄÖÜ', mb_OK);
end.

