Solved

[Fatal Error] Unit1.pas(7): File not found: 'DesignConst.dcu'

Posted on 2003-10-22
8
4,613 Views
Last Modified: 2007-12-19
Hi, when I try to compile any program using my component (Component that I've created and it has a property editor), it shows me that error: [Fatal Error] Unit1.pas(7): File not found: 'DesignConst.dcu' . I'm using Delphi 7, and at the uses clausule, I've already put DesignConst,  DesignIntf,  DesignEditors . And at the package on the REQUIRES option, the designide.dcp is present. But, when I click two times at the designide.dcp, it shows me activated the install button, so, I perceived that designide.dcp isn't installed , and when I try to compile and install, it shows error on all contains items. How can I fix this problem?

Thanks, sorry for my english.
0
Comment
Question by:emu10k1
  • 5
  • 3
8 Comments
 
LVL 5

Expert Comment

by:snehanshu
Comment Utility
Have you included the path to the directory that contains 'DesignConst.dcu' file?
(i.e. in library path or search path of project options)
...S
0
 

Author Comment

by:emu10k1
Comment Utility
yes
0
 
LVL 5

Expert Comment

by:snehanshu
Comment Utility
Shouldn't it be DesignConsts? (With an s)
0
 
LVL 5

Expert Comment

by:snehanshu
Comment Utility
OK, Managed to check it on my office PC (Which has Delphi 7).
The path
C:\Program Files\Borland\Delphi7\Source\ToolsAPI
was not present in Tools -> Environment Options -> Library -> Library path.
Once I added it there, the compile error was gone.
Are you sure you have this in your library path and still are not able to compile?

...Snehanshu
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:emu10k1
Comment Utility
Ok, I put the Source\ToolsApi at library path. But, now it shows me another error: "[Fatal Error] DesignEditors.pas(530): File not found: 'Proxies.dcu'" . And I try to compile the designide.dcp and it shows me: "The package must be saved to a new name to be compiled. Do You want to save it now?" . When I put a new name and Try to compile, it shows an error at all files at "contains" options.  First at "PipeUtil", when I delete PipeUtil, it shows the error on the next file, ProcessUtil, and next and next....
0
 
LVL 5

Accepted Solution

by:
snehanshu earned 500 total points
Comment Utility
Great!
Now we have some known eror at our hands.
Well, you can try to read this link and figure out for yourself what changes you need in the code or paste your code so that we can try to figure it out.
...S
Link:
http://community.borland.com/article/0,1410,27717,00.html

Here's the article:
What ever happened to Proxies.pas?

Abstract: This article illustrates a scheme for properly segregating runtime code from design-time code in Delphi. By Jeff Overcash.

One frequent question since Delphi 6 shipped has concerned the disappearance of Proxies.pas from the source.

This change is part of a larger trend.

Borland chose not to ship DsgnIntf.dcu with Delphi 5, apparently to force compliance with the Delphi and C++Builder license agreements. The design-time code had been inadvertently used at runtime by many components. In some ways Borland encouraged this behavior: If you use the new component wizard you will see that this wizard creates only one unit, putting both the component skeleton code (runtime) and the Register procedure (design-time) in the same unit.

With Delphi 6, Borland has taken the next step. Not only was DsgnIntf replaced with DesignIntf, but the property editors were also pulled out into DesignEditors, DesignMenus, DesignWindows and other design-time files. DesignEditors in particular uses another IDE file named Proxies. (The Proxies code resides in DesignIDE.bpl.) Needless to say, these changes can result in errors at compile time.

If your code is already segregated in terms of runtime versus design-time then the fix is very simple. Open up your design-time package, select the requires folder and hit the Add button. Type designide.dcp and hit OK. Recompile your package and the error should go away.

But how can this problem be fixed when design-time and runtime code has been mixed together? DesignIDE.bpl is not a redistributable package in Delphi. So even in situations where the "design-time only" package has the component's runtime code and only the component dcu is used, there can still be a problem.

In 99.99% of the cases this is actually very easy to fix. Your runtime code isn't actually using the design-time code; things just are not properly segregated. The segregation lines are fairly simple, however.

The design-time package should include:

All registration statements.
All property editors.
All Component editors.
Should require DesignIDE and each runtime package that holds the components themselves.
The runtime package should include:

The components themselves only.
Optionally, any forms the editors may use IF the component can call the form itself at runtime
The only place where there is a little confusion is if the property/component editor uses a form. If that form is available at runtime to the component, it belongs in the runtime package. If it is only available at design-time, it goes in the design-time package. A very common misperception is that the form itself is the editor, but it is not. It is the component editor that calls the form that is the design-time editor.

You should get in the habit of always separating your components into two packages even if you only statically link your application, because mixing design-time and runtime code leads to code bloat. Your design-time code can't be executed in the runtime, but the linker doesn't know that so it links it in anyway. (This is why DsgnIntf is trying to get linked in.)

Let's walk though a very simple component to see how to break the design-time code from the runtime:

{ TMixedComponent }
TMixedComponent = class(TComponent)
  private
    FFileName: String;
  published
    property  FileName : String read FFileName write FFileName;
    { Published declarations }
  end;
  { TMixedFileNameProperty }
  TMixedFileNameProperty = class(TPropertyEditor)
    function    AllEqual: boolean; override;
    procedure   Edit; override;
    function    GetAttributes: TPropertyAttributes; override;
    function    GetValue: string; override;
    procedure   SetValue (const  Value: string); override;
  end;
procedure  Register;

implementation

procedure  Register;
begin
  RegisterPropertyEditor(TypeInfo(string), TMixedComponent, 'FileName', TMixedFileNameProperty);
  RegisterComponents('Samples', [TMixedComponent]);
end;

function  TMixedFileNameProperty.AllEqual: boolean;
var
  FirstVal: string;
  i: Integer;
begin
  FirstVal := GetStrValue;
  Result := True;
  i := 1;
  while  Result and  (i < PropCount) do
  begin
    Result := Result and  (GetStrValueAt(i) = FirstVal);
    Inc(i);
  end;
end;

procedure  TMixedFileNameProperty.Edit;
var
  Dlg: TOpenDialog;
begin
  Dlg := TOpenDialog.Create(Application);
  try
    with  Dlg do
    begin
      Title := 'File for ' + TComponent(GetComponent(0)).Name;
      FileName:= Value;
      if  Execute then  Value := FileName;
    end;
  finally
    FreeAndNil(Dlg);
  end
end;

function  TMixedFileNameProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog]
end;

function  TMixedFileNameProperty.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure  TMixedFileNameProperty.SetValue(const  Value: string);
begin
  SetStrValue(Value);
end;

end.
The easiest way to segregate the design-time code from runtime code is to take all the code that requires DesignIntf and DesignEditors and put it in its own unit. That unit will need to use the component's unit. The component itself does not have need to know about the IDE editors that will work with it. So for a start, remove the design-time units DesignIntf and DesignEditors from the uses clause component unit and let the compiler/linker tell you which classes need to be moved into their own unit:

[Error] MixedComponent.pas(23): Undeclared identifier: 'TPropertyEditor'
[Error] MixedComponent.pas(23): Class type required
[Error] MixedComponent.pas(24): Method 'AllEqual' not found in base class
[Error] MixedComponent.pas(25): Method 'Edit' not found in base class
[Error] MixedComponent.pas(26): Undeclared identifier: 'TPropertyAttributes'
[Error] MixedComponent.pas(27): Method 'GetValue' not found in base class
[Error] MixedComponent.pas(28): Method 'SetValue' not found in base class
[Error] MixedComponent.pas(35): Undeclared identifier: 'RegisterPropertyEditor'
[Error] MixedComponent.pas(35): Undeclared identifier: 'TMixedFile'
[Error] MixedComponent.pas(46): Undeclared identifier: 'GetStrValue'
[Error] MixedComponent.pas(49): Undeclared identifier: 'PropCount'
[Error] MixedComponent.pas(51): Undeclared identifier: 'GetStrValueAt'
[Error] MixedComponent.pas(51): Operator not applicable to this operand type
[Error] MixedComponent.pas(64): Undeclared identifier: 'GetComponent'
[Error] MixedComponent.pas(65): Undeclared identifier: 'Value'
[Error] MixedComponent.pas(75): Undeclared identifier: 'paDialog'
[Error] MixedComponent.pas(80): Undeclared identifier: 'GetStrValue'
[Error] MixedComponent.pas(85): Undeclared identifier: 'SetStrValue'
[Fatal Error] JOComponents.dpk(33): Could not compile used unit 'MixedComponent.pas'
The next step is to create a new unit to hold the design-time code. Name it something like MixedComponentReg. Move the Register procedure over to that unit. Now start going through the error messages and start evaluating them. The first error, [Error] MixedComponent.pas(23): Undeclared identifier: 'TPropertyEditor', indicates that the whole class inherits from something in one of the design-time units we removed. This is a clear indication that this is only design-time code and the whole class needs to be moved over to the newly created unit.

At this point the runtime package now compiles cleanly (if not, keep pulling design-time code out until it compiles cleanly without errors). Now there is no need for Proxies.pas or any other design-time units for the component to work in your application at runtime. The runtime component unit is much simplified. It looks like this:

unit MixedComponent;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  { TMixedComponent }
  TMixedComponent = class(TComponent)
  private
    FFileName: String;
  published
    property FileName : String read FFileName write FFileName;
    { Published declarations }
  end;

implementation

end.
The final step is to get the component and its property editors compiled into a design-time package and installed into the IDE.

Create a new package by doing File | New | Other and select package. Bring up the packages options and select design-time only. Give a descriptive name in the Description field. Select the Requires folder and hit the Add button. In the Requires Package edit box type Designide.dcp and hit OK. Also add the dcp for the runtime package that the component resides in. In this case it was put it in JOComponents.dpk, so JOComponents.dcp is added to the requires section. The requires section has three items: JOComponents, designide and rtl. Finally, select the Contains folder and add MixedComponentReg.pas to the package.

We're almost done!

Open up MixedComponentReg.pas to add a couple of units in the uses section. Which section depends on whether your component or property editor uses the component in its declaration (more complicated editors sometimes need knowledge of the component). If it does, then add it to the Interface uses clause. If not, put it in the implementation uses. In our example we don't need the information so MixedComponent goes in the implementation uses clause. DesignIntf and DesignEditors belong in the Interface uses. SysUtils, Forms, Dialogs, and Classes are all used internally in different ways in the property editor, so they belong in the implementation section. The final MixedComponentReg looks like this:

unit MixedComponentReg;

interface

uses DesignIntf, DesignEditors;

type
  { TMixedFileNameProperty }
  TMixedFileNameProperty = class(TPropertyEditor)
    function  AllEqual: boolean; override;
    procedure Edit; override;
    function  GetAttributes: TPropertyAttributes; override;
    function  GetValue: string; override;
    procedure SetValue (const Value: string); override;
  end;

procedure Register;

implementation

uses MixedComponent, SysUtils, Forms, Dialogs, Classes;

procedure Register;
begin
  RegisterPropertyEditor(TypeInfo(string), TMixedComponent, 'FileName', TMixedFileNameProperty);
  RegisterComponents('Samples', [TMixedComponent]);
end;

function TMixedFileNameProperty.AllEqual: boolean;
var
  FirstVal: string;
  i: Integer;
begin
  FirstVal := GetStrValue;
  Result := True;
  i := 1;
  while Result and (i < PropCount) do
  begin
    Result := Result and (GetStrValueAt(i) = FirstVal);
    Inc(i);
  end;
end;

procedure TMixedFileNameProperty.Edit;
var
  Dlg: TOpenDialog;
begin
  Dlg := TOpenDialog.Create(Application);
  try
    with Dlg do
    begin
      Title := 'File for ' + TComponent(GetComponent(0)).Name;
      FileName:= Value;
      if Execute then Value := FileName;
    end;
  finally
    FreeAndNil(Dlg);
  end
end;

function TMixedFileNameProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog]
end;

function TMixedFileNameProperty.GetValue: string;
begin
  Result := GetStrValue;
end;

procedure TMixedFileNameProperty.SetValue(const Value: string);
begin
  SetStrValue(Value);
end;

end.
All that is left is to compile and install the design-time package.

The runtime code is now completely segregated from the design-time code.

While this is a fairly simple example, the only time it gets a little more complicated is when the property editor uses a form to retrieve the data, and that form is also available at runtime. In those cases the form stays in the runtime package, and the design-time property editor will call that form from the runtime package.

If you get in the habit of always having a runtime package for the components and a design-time package for the registration and editors, you won't have any more problems, even if you only intend to statically link in the DCUs.

By Jeff Overcash (TeamB).
0
 

Author Comment

by:emu10k1
Comment Utility
Thanks snehanshu, You really save me.

Thanks, emu10k1.
0
 
LVL 5

Expert Comment

by:snehanshu
Comment Utility
I am so glad I could help!
Thanks,
...Snehanshu
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

10 Experts available now in Live!

Get 1:1 Help Now