Problem with BorderStyle

I have two own VCL ( VCL1 and VCL2 ) where I declare:

TBorderStyle ... (bsNone, bsSingleFlat .. )

Bouth vcls have a BorderStyle property.

When create VCL2 I wish to create a VCL1 inside VCL2.

Create VCL2
begin
  VCL1:=TVCL1,Create(Self);
  VCL.Border := bsNone; // Here I have a problem

The compiler told me that VCL1.BorderStyle isn't compatible with VCL2.BorderStyle ?!?!?

What to do ? The declarations for BorderStyle are the same .
LVL 9
ginsonicAsked:
Who is Participating?
 
Russell LibbyConnect With a Mentor Software Engineer, Advisory Commented:
As I have already stated, use the namespace qualifier. For example (using what you have provided so far):

unit vcl1;

interface

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

type
  TBorderStyle      =  (bsNone, bs3D, bsFlatSingle, bsFlatDouble);

type
  TVCL1             =  class(TCustomControl)
  private
     // Private declarations
     FBorder:       TBorderStyle;
  protected
     // Protected declarations
     procedure      SetBorder(Value: TBorderStyle);
  public
     constructor    Create(AOwner: TComponent); override;
     destructor     Destroy; override;
  published
     property       Border: TBorderStyle read FBorder write SetBorder default bs3D;
  end;

implementation

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

destructor TVCL1.Destroy;
begin
  inherited Destroy;
end;

procedure TVCL1.SetBorder(Value: TBorderStyle);
begin
  FBorder:=Value;
end;

end.

---------------

unit vcl2;

interface

uses
  Windows, SysUtils, Classes, Controls, Forms, Dialogs, vcl1;

type
  TBorderStyle      =  (bsNone, bs3D, bsFlatSingle, bsFlatDouble);

type
  TVCL2             =  class(TCustomControl)
  private
     // Private declarations
     FVCL1:         TVCL1;
     FBorder:       TBorderStyle;
  protected
     // Protected declarations
     procedure      SetBorder(Value: TBorderStyle);
  public
     constructor    Create(AOwner: TComponent); override;
     destructor     Destroy; override;
  published
     property       Border: TBorderStyle read FBorder write SetBorder default bs3D;
  end;

implementation

constructor TVCL2.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FVCL1:=TVCL1.Create(Self);
  FVCL1.Parent:=Self;
  FVCL1.Border:=vcl1.bsNone; // <<--- THIS WORKS FINE
end;

destructor TVCL2.Destroy;
begin
  FreeAndNil(FVCL1);
  inherited Destroy;
end;

procedure TVCL2.SetBorder(Value: TBorderStyle);
begin
  FBorder:=Value;
end;

end.

----

If you are running into other problems, such as "control has no parent", then that is a different (not to mention unrelated) problem, but one we would need more code to help you with.

Russell

0
 
Russell LibbySoftware Engineer, Advisory Commented:

Have you tried using the namespace qualifier?

eg:

Create VCL2
begin
  VCL1:=TVCL1,Create(Self);
  VCL1.Border := VCL1.bsNone; <-- qualifier


Regards,
Russell


0
 
Russell LibbySoftware Engineer, Advisory Commented:

In truth, if they are the **same**, then it would be better to just declare it once; inside a common unit or whatever, and then put that common unit in the uses clause of the units that will use the declaration. Otherwise, you will need to qualify the identifier with the unit that it comes from. (as I mentioned above)

Russell

0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
BlackTigerXCommented:
you should have the base types (BorderStyle, etc) in a third unit, and then use that unit (those types) from both VCL1 and VCL2, then you can use the same "BaseTypes" unit in this one, where you are trying to assign the values and you won't have any problems

is a bad practice to duplicate types in various units
0
 
ginsonicAuthor Commented:
I try to use a single one but is same with standard, as name, TBorderStyle.

I changed to a single TginBorderStyle but when I create VCL1 and try to assign Border:=ginNone ( instead of bsNone ) I get an error as my VCL1 have no parent. But I use VCL1.Parent:=VCL2.
0
 
Russell LibbySoftware Engineer, Advisory Commented:

Not sure what the "no parent" error has to do with the border style, or how it even relates to the original question.

Russell
0
 
ginsonicAuthor Commented:
To be more clear:

unit VCL1

uses ....

type
  TBorderStyle = ( bsNone, bs3D, bsFlatSingle, bsFlatDouble );

type
  TVCL1 = class(TCustomControl)
  FBorder        : TBorderStyle;
  procedure SetBorder(Value:TBorderStyle);
  ................
  property Border         : TBorderStyle  read FBorder       write SetBorder     default bs3D;


unit VCL2

uses ....

type
  TBorderStyle = ( bsNone, bs3D, bsFlatSingle, bsFlatDouble );

type
  TVCL2 = class(TCustomControl)
  FBorder        : TBorderStyle;
  FVCL1          : TVCL1;
  procedure SetBorder(Value:TBorderStyle);
  ................
  property Border         : TBorderStyle  read FBorder       write SetBorder     default bs3D;
  ..............

constructor TVCL.Create(AOwner: TComponent);
begin
  FVCL1 := TVCL1.Create(Self);
  FVCL1.Parent := Self;
  FVCL.Border := bsNone;  //////////  My problem
0
 
BlackTigerXCommented:
if is already declared in a Borland unit, then  you DON'T need to redeclare the types, just reuse the same ones from the Borland Unit
0
 
Russell LibbySoftware Engineer, Advisory Commented:
BlackTigerX,

The declaration is NOT the same as that from the forms unit

<forms.pas>

type

  TFormBorderStyle = (bsNone, bsSingle, bsSizeable, bsDialog, bsToolWindow, bsSizeToolWin);

  TBorderStyle = bsNone..bsSingle;

vs.

type
  TBorderStyle      =  (bsNone, bs3D, bsFlatSingle, bsFlatDouble);


I would agree though that a new identifier name should be used, and should be placed in a common unit instead of declaring it twice. (curently in vcl1 and vcl2)

Russell
0
 
ginsonicAuthor Commented:
Thanks to all for help!

I use same identifier becouse I wish to keep "bs" from border style. if I redeclare to TgnBorderStyle I can't use bsNone for example.

But anyway my vcl work perfect now. Thanks again!
0
All Courses

From novice to tech pro — start learning today.