Server code:
```
program NamedPipeServer;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;

const
  PIPE_NAME = '\\.\pipe\MyNamedPipe';

var
  hPipe: THandle;
  lpvMessage: PChar;
  cbBytesRead, cbReplyBytes: DWORD;
begin
  WriteLn('Named Pipe Server started.');

  hPipe := CreateNamedPipe(PIPE_NAME, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE or PIPE_READMODE_MESSAGE or PIPE_WAIT,
    PIPE_UNLIMITED_INSTANCES, 1024, 1024, NMPWAIT_USE_DEFAULT_WAIT, nil);

  if hPipe = INVALID_HANDLE_VALUE then
  begin
    WriteLn('Error creating named pipe: ' + IntToStr(GetLastError));
    Exit;
  end;

  if ConnectNamedPipe(hPipe, nil) then
  begin
    lpvMessage := AllocMem(1024);

    if ReadFile(hPipe, lpvMessage^, 1024, cbBytesRead, nil) then
    begin
      WriteLn('Received message: ' + lpvMessage);

      cbReplyBytes := StrLen(lpvMessage) + 1;
      WriteFile(hPipe, lpvMessage^, cbReplyBytes, cbBytesRead, nil);
    end;

    DisconnectNamedPipe(hPipe);
    FreeMem(lpvMessage);
  end;

  CloseHandle(hPipe);

  WriteLn('Named Pipe Server stopped.');
end.


Client code:
program NamedPipeClient;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;

const
  PIPE_NAME = '\\.\pipe\MyNamedPipe';

var
  hPipe: THandle;
  lpvMessage: PChar;
  cbBytesRead, cbWritten: DWORD;
begin
  WriteLn('Named Pipe Client started.');

  hPipe := CreateFile(PIPE_NAME, GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, nil);

  if hPipe = INVALID_HANDLE_VALUE then
  begin
    WriteLn('Error connecting to named pipe: ' + IntToStr(GetLastError));
    Exit;
  end;

  lpvMessage := AllocMem(1024);
  StrCopy(lpvMessage, 'Hello, world!');

  if WriteFile(hPipe, lpvMessage^, StrLen(lpvMessage) + 1, cbWritten, nil) then
  begin
    if ReadFile(hPipe, lpvMessage^, 1024, cbBytesRead, nil) then
      WriteLn('Received message: ' + lpvMessage);
  end;

  FreeMem(lpvMessage);
  CloseHandle(hPipe);

  WriteLn('Named Pipe Client stopped.');
end.
```
Server code:


program NamedPipeServer;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;

const
  PIPE_NAME = '\\.\pipe\MyNamedPipe';

var
  hPipe: THandle;
  lpvMessage: PChar;
  cbBytesRead, cbReplyBytes: DWORD;
begin
  WriteLn('Named Pipe Server started.');

  hPipe := CreateNamedPipe(PIPE_NAME, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE or PIPE_READMODE_MESSAGE or PIPE_WAIT,
    PIPE_UNLIMITED_INSTANCES, 1024, 1024, NMPWAIT_USE_DEFAULT_WAIT, nil);

  if hPipe = INVALID_HANDLE_VALUE then
  begin
    WriteLn('Error creating named pipe: ' + IntToStr(GetLastError));
    Exit;
  end;

  if ConnectNamedPipe(hPipe, nil) then
  begin
    lpvMessage := AllocMem(1024);

    if ReadFile(hPipe, lpvMessage^, 1024, cbBytesRead, nil) then
    begin
      WriteLn('Received message: ' + lpvMessage);

      cbReplyBytes := StrLen(lpvMessage) + 1;
      WriteFile(hPipe, lpvMessage^, cbReplyBytes, cbBytesRead, nil);
    end;

    DisconnectNamedPipe(hPipe);
    FreeMem(lpvMessage);
  end;

  CloseHandle(hPipe);

  WriteLn('Named Pipe Server stopped.');
end.


Client code:
program NamedPipeClient;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;

const
  PIPE_NAME = '\\.\pipe\MyNamedPipe';

var
  hPipe: THandle;
  lpvMessage: PChar;
  cbBytesRead, cbWritten: DWORD;
begin
  WriteLn('Named Pipe Client started.');

  hPipe := CreateFile(PIPE_NAME, GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, nil);

  if hPipe = INVALID_HANDLE_VALUE then
  begin
    WriteLn('Error connecting to named pipe: ' + IntToStr(GetLastError));
    Exit;
  end;

  lpvMessage := AllocMem(1024);
  StrCopy(lpvMessage, 'Hello, world!');

  if WriteFile(hPipe, lpvMessage^, StrLen(lpvMessage) + 1, cbWritten, nil) then
  begin
    if ReadFile(hPipe, lpvMessage^, 1024, cbBytesRead, nil) then
      WriteLn('Received message: ' + lpvMessage);
  end;

  FreeMem(lpvMessage);
  CloseHandle(hPipe);

  WriteLn('Named Pipe Client stopped.');
end.