Extended or New TurboVision Objects


Q 408 How can I add printing capabilities to the editor object?
You need to take the following steps:
  1. Add method Print to the TFileEditor object.
  2. Add uses Printer to the implementation uses clause.
  3. Change TFileEditor.HandleEvent to call the Print method when for example the command cmPrint is received (in this case you need to add the cmPrint command somewhere in the interface also).
  4. Code the Print method as follows:
      function TFileEditor.Print : Boolean;
      var
        i : word;
      begin
        if CurPtr <> 0 then  begin
          i := 0;
          while i <= CurPtr do  begin
            write(lst, Buffer^[i]);
            Inc(i);
          end;
        end;
        i := CurPtr+GapLen;
        while i < GapLen+BufLen do  begin
          write(lst, Buffer^[i]);
          Inc(i);
        end;
        if IOResult <> 0 then EditorDialog(edPrintError, @FileName) else
        Print := TRUE;
      end;
    
  5. This Print method is a bit more advanced than described above, because when an error occurs the EditorDialog is called with the edPrintError constant which is not yet defined. You can add
      const
        edPrintError = 11;
    
    or something similar to the interface.
Next question
B de Boer Last modified: Tuesday 18 April 1995 - 10:20