unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Registry,
{$IFDEF PHIEMBED}
  PhiMainUnit,
{$ELSE}
  Pythia,
{$ENDIF}
  Rubies;

type
  TFormConsole = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  end;

var
  FormConsole: TFormConsole;

implementation

{$R *.DFM}

procedure Stdout(S: string);
begin
  with FormConsole.Memo1 do
  begin
    with Lines do Text := Text + S;
    SelStart := Length(Text);
    SelLength := 0;
  end;
end;

procedure init;
begin
  PhiExport('Ole');
end;

procedure TFormConsole.FormCreate(Sender: TObject);
begin
  ruby_init;
  ruby_init_loadpath;
  PhiSetStdoutProc(Stdout);
  PhiSetInitProc(init);
end;

procedure TFormConsole.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  if PhiAlive then CanClose := False;
end;

end.
