Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How do I disable File | Print menu item when no default

Posted on 1998-10-09
6
159 Views
Last Modified: 2010-04-06
How do I disable File | Print, The print menuitem and printer setup menuitem when no default printer is installed.
0
Comment
Question by:TCSCode
  • 3
  • 3
6 Comments
 
LVL 1

Accepted Solution

by:
ow earned 60 total points
ID: 1342398
Hi TCSCode,

look at the Registry and disable the MenuItem:

  var
    Registry :tRegistry;
    Print1 :tMenuItem;
    Key :string;
    EnablePrint :boolean;
.
  Registry := tRegistry.Create;
  Registry.RootKey := HKEY_CURRENT_CONFIG;
  Key := '\System\CurrentControlSet\Control\Print\Printers';
  EnablePrint := FALSE;
  if Registry.OpenKey(Key, FALSE) then
    EnablePrint := (Length(Registry.ReadString('Default')) = 0);
  Print1.Enabled := EnablePrint;
  Registry.Free;
.

regards
  ow
0
 

Author Comment

by:TCSCode
ID: 1342399
Hello Ow.
      For some reason I cannot get this code to work for 1 basic reason, I am not good with TRegistry, I tryied the code many different ways and all I come up with is Access violation Errors.
Could you make me a demo showing me where i should put this code.
                                                 Thanks TcsCode.
0
 
LVL 1

Expert Comment

by:ow
ID: 1342400
Hi TCSCode,

when you insert a menu in a form, the form will contain some fields of type "tMenuItem", one of them should be for printing, normaly "Print1 :tMenuItem".
Check for a default printer in tForm.Create:


unit Unit1;

INTERFACE

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Registry, Menus;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Print1: TMenuItem;
    PrinterSetup1: TMenuItem;
    Quit1: TMenuItem;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    end;

var
  Form1: TForm1;

IMPLEMENTATION

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
  var
    Registry :tRegistry;
    Key :string;
    EnablePrint :boolean;
  begin
  Registry := tRegistry.Create;
  Registry.RootKey := HKEY_CURRENT_CONFIG;
  Key := '\System\CurrentControlSet\Control\Print\Printers';
  EnablePrint := FALSE;
  if Registry.OpenKey(Key, FALSE) then
    begin
    TRY
      EnablePrint := (Length(Registry.ReadString('Default')) > 0);
    EXCEPT
      EnablePrint := FALSE;
      end;
    end;
  Print1.Enabled := EnablePrint;
  end;

initialization
end.


regards
  ow
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:TCSCode
ID: 1342401
I just have one last question. What is the initialization for in unit1? and Thanxs Ow..
0
 
LVL 1

Expert Comment

by:ow
ID: 1342402
Hi TCSCode,

well, in fact I write "initialization" in a unit even if there is no init code, cause I like it complete and I don't like single ends. But it's not absolutly necessary.

regards
  ow

0
 

Author Comment

by:TCSCode
ID: 1342403
Hi Ow.
 
Complete end, What good does adding "initialization"??? Thanks TCSCode.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 147
Reconfigure Delphi Install? 2 60
Performance of SQL statement 37 127
Delphi Seattle StructureView color 1 14
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question