Solved

Problem with BorderStyle

Posted on 2004-10-27
308 Views
Last Modified: 2010-04-05
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 .
0
Question by:ginsonic
    10 Comments
     
    LVL 26

    Expert Comment

    by:Russell Libby

    Have you tried using the namespace qualifier?

    eg:

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


    Regards,
    Russell


    0
     
    LVL 26

    Expert Comment

    by:Russell Libby

    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
     
    LVL 13

    Expert Comment

    by:BlackTigerX
    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
     
    LVL 9

    Author Comment

    by:ginsonic
    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
     
    LVL 26

    Expert Comment

    by:Russell Libby

    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
     
    LVL 9

    Author Comment

    by:ginsonic
    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
     
    LVL 26

    Accepted Solution

    by:
    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
     
    LVL 13

    Expert Comment

    by:BlackTigerX
    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
     
    LVL 26

    Expert Comment

    by:Russell Libby
    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
     
    LVL 9

    Author Comment

    by:ginsonic
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    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.

    A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

    913 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

    17 Experts available now in Live!

    Get 1:1 Help Now