Home  |  Delphi .net Home  |  System.Console  |  SetError Method
  
SetError  
Method  
Assigns a new Error Output Stream writer
Console Class
System NameSpace
CF1.  Procedure SetError ( NewWriter : TextWriter ) ; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Assigns the Error property to NewWriter, allowing a different target for error data from a Console application.
 
As in the example, this can be used to write to a text file instead.
Notes
Static methods are not methods of an object - they are simply class functions or procedures available at any time.
Microsoft MSDN Links
System
System.Console
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  fileName  : String;

  reader    : TextReader;
  writer    : TextWriter;
  errWriter : Stream;

begin
  // Create a test text file
  fileName := 'C:DelphiBasics.txt';
  if not System.IO.File.Exists(fileName)
  then System.IO.File.CreateText(fileName);

  // Open the file
  writer := StreamWriter.Create(fileName);

  // Assign the Console Error stream to this file
  Console.SetError(writer);

  // Get the standard error stream writer
  // (There are no methods for directly writing to the error stream,
  //  unlike WriteLine to the output stream)
  errWriter := Console.OpenStandardError;

  // Write to the standard error stream
  errWriter.Write([Ord('H'), Ord('e'), Ord('l'),
                  Ord('l'), Ord('o')], 0, 5);

  // Close the file
  writer.Close;

  // Read from the file
  reader := StreamReader.Create(fileName);

  Console.WriteLine(reader.ReadLine);

  Console.ReadLine;
end.
   Hello
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author