Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seperate Units

Status
Not open for further replies.

siu01jam

Programmer
Oct 2, 2003
12
GB
I have an object inheriting from TPanel declared in a seperate unit:

type
TPreviewPanel = class(TPanel)
private
procedure ImagePreviewClick(Sender: TObject);
protected
{ Protected Declarations }
public
constructor Create(Owner: TComponent); override;
destructor Destroy; override;

published
{ Published Declarations }
end;


Then in the main unit I try to create it:

procedure TForm1.Insert1Click(Sender: TObject);
var temp: TPreviewPanel;
begin
temp:= TPreviewPanel.Create(self);
temp.Parent:= self; //<--- error here
end;

But I get a compilation error saying that TWidgetControl and TForm1 are incompatible types. If I transfer the class definition to the main unit it works correctly. Please can anyone tell me how I keep these in seperate units, without the error? I have included the seperate unit in my uses.
 
I have copied and pasted your code into a new project (with two units) using Delphi 5 but do not get a compilation error. It even runs correctly.

What version of Delphi are you using?
 
I am using Delphi 6 Enterprise . . . Could this make a difference?
 
try changing the problem line with

temp.Parent:= self as TControl;
 
Sorry, make that

temp.Parent:= self as TWinControl;
 
Doh - This is not an attempt to get my post count up, I assure you :)

I should have looked further before posting. You're using TPanel from the CLX library, not the VCL. TPanel in CLX is inherited from TWidgetControl, not TWinControl. However, you must be using TForm from the VCL library, and the two are incompatible as their first common ancestor is TControl.

Change either your TPanel or your TForm so that they're called from the same library, and it should be ok.
 
How do I change my TPanel so it is called from the VCL library? Thanks for the help!
 
Here is code I wrote to make an image panel, it may help. note the consuctor, this could be what you are missing.

interface

uses
SysUtils, Classes, Controls, ExtCtrls;

type
TImagePanel = class(TPanel)
private
{ Private declarations }
constructor Create (AOwner : TComponent); override;
procedure CreateWnd ; override;
protected
{ Protected declarations }

public
{ Public declarations }
published
{ Published declarations }
end;

procedure Register;

implementation
var
PictureImage : TImage;
procedure Register;
begin
RegisterComponents('Samples', [TImagePanel]);
end;


constructor TImagePanel.Create (AOwner : TComponent);
begin
inherited Create (AOwner);
end;

procedure TImagePanel.CreateWnd;
begin
inherited CreateWnd;
Caption := '';
with PictureImage do
begin
PictureImage := Timage.Create(self);
Parent := self;
Align := alClient
end;
end;
end.
 
You want to make sure your reference to QControl in your 'uses' clause is specified AFTER the reference to Control.

ie.

uses
Windows, SysUtils, Controls, QControls;

Or, alternatively, try removing the reference to QControls altogether and see if your project compiles.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top