OK, I got it working now. Just in case somebody else is googling for something like this:
first I define a class TDebugStream that will later replace the standard output: Type TDebugStream = class(TStream) function Write(const Buffer; Count : Longint) : Longint; override; end; implementation function TDebugStream.Write(const Buffer; Count : Longint) : Longint; var msg : ansistring; begin result := count; SetLength(msg, count); move(buffer, PChar(msg)[0], count); OutputDebugString(PChar(TrimRight(msg))); end; then in my application i have two global variables: var f : TextFile; s: TDebugStream; and a procedure to redirect the output: procedure redirect; begin s := TDebugStream.Create(); AssignStream(f, s); Rewrite(f); output := f; end; and then I can use it like this: procedure TForm1.FormCreate(Sender : TObject); begin redirect; writeln('form created'); end; procedure TForm1.Button1Click(Sender : TObject); begin writeln('button clicked'); end; This might seem trivial but my Pascal times have been 20 years ago with TurboPascal and I have to re-learn many things that I have forgotten. http://imagebin.org/105806 with GDB enabled http://imagebin.org/105807 without debugger, output sent to DebugView Now I think I have spent ten times more time with trying to figure out how to redirect writeln to OutputDebugString() than I could ever save by using it ;-) _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal