Solved

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

Posted on 1998-10-09
6
158 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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