Solved

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

Posted on 1998-10-09
6
156 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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

Expert Comment

by:ow
Comment Utility
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
Comment Utility
Hi Ow.
 
Complete end, What good does adding "initialization"??? Thanks TCSCode.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now