How to get and set the printer programatically

  • I can not see any reference to it in the manual, and following the source code needs several hours, so:

    1.) How can I get the actual WPRichText1 Printer, and how can I set it programatically to another one without calling the setup dialog.

    2.) How can I get printer parameters programatically like printer name, orientation, paper size after calling WPRichText1.PrinterSetup.

    • Offizieller Beitrag
    Zitat

    1.) How can I get the actual WPRichText1 Printer, and how can I set it programmatically to another one without calling the setup dialog.

    As usually with Delphi VCL, use Printer.PrinterIndex for this. The integer value is the index in the list Printer.Printers[].

    You can use this function:

    The part with "Reset" used to be required to make sure, the printer is not using properties of the previous printer.

    Zitat

    2.) How can I get printer parameters programmatically like printer name, orientation, paper size after calling WPRichText1.PrinterSetup.

    You need to use DeviceCapabilities. See this method in WPCtrMemo.pas

    TWPCustomRtfEdit.UpdatePrinterProperties

  • After looking at UpdatePrinterProperties, and in respect to:

    Zitat

    2.) How can I get printer parameters programmatically like printer name, orientation, paper size after calling WPRichText1.PrinterSetup.

    What I want to do is to update my form data with the printer name just selected.

    I tried to implement the events TWPDefAct.WPAPrinterSetup1AfterExecute and TWPDefAct.aView_PrinterSetupAfterExecute through the StdActions control in wpDefActions7, but none of both are called after WPRichText1.PrinterSetup terminates.

    So, is there a way to get the printer name once PrinterSetup dialog is terminated, and preferably without changing the control source code.