Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Transparent form not transparent when compiled with Berlin


This question is not answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 9 - Last Post: Sep 8, 2016 10:31 AM Last Post By: Remy Lebeau (Te...
John Smith

Posts: 13
Registered: 6/12/09
Transparent form not transparent when compiled with Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 2, 2016 9:10 AM
I have created my own trackbar adding transparent capability by overriding create params. It works fine when compiled with XE7 and also if I start a new project, add the trackbar, and compile with a trial version of Berlin. However if I compile an existing project with Berlin it displays with a solid color (clBtnFace). Also tried deleting the component from a form in the existing project and then adding it back from the tool palette but still shows up as a solid color.

Any ideas where to look for something in the existing project that may prevent this working ?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Transparent form not transparent when compiled with Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 2, 2016 10:43 AM   in response to: John Smith in response to: John Smith
John wrote:

Any ideas where to look for something in the existing project that
may prevent this working ?

Not without knowing what your project actually does. If things work correctly
in a new project, but not in an existing project, then clearly the existing
project is doing something extra that the new project is not. We can't see
your system, so you will have to track down that difference yourself.

--
Remy Lebeau (TeamB)
John Smith

Posts: 13
Registered: 6/12/09
Re: Transparent form not transparent when compiled with Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 3, 2016 6:49 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
John wrote:

Any ideas where to look for something in the existing project that
may prevent this working ?

Not without knowing what your project actually does. If things work correctly
in a new project, but not in an existing project, then clearly the existing
project is doing something extra that the new project is not. We can't see
your system, so you will have to track down that difference yourself.

--
Remy Lebeau (TeamB)

What I do not understand is why the existing project compiles OK in XE7 but not Berlin. I am look through my project but with no idea what to look for it is not easy. I was hoping some expert such as you could guess the type of things I should be looking for.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Transparent form not transparent when compiled with Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 3, 2016 2:51 PM   in response to: John Smith in response to: John Smith
John wrote:

What I do not understand is why the existing project compiles OK
in XE7 but not Berlin.

What is not compiling? What does the code look like? What is the error
message?

--
Remy Lebeau (TeamB)
John Smith

Posts: 13
Registered: 6/12/09
Re: Transparent form not transparent when compiled with Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 4, 2016 7:17 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
John wrote:

What I do not understand is why the existing project compiles OK
in XE7 but not Berlin.

What is not compiling? What does the code look like? What is the error
message?

--
Remy Lebeau (TeamB)

The component code is below. If I compile with XE7 the component is transparent when FTransparent is set to True. If I compile with Berlin the component has a solid clBtnFace color. It shows up transparent in the Berlin IDE and in new projects but not for this existing project when compiled with Berlin. There are no error messages and I can't see anything in project options or the code that would cause a problem.

TMyTrackBar = Class (TTrackBar)
private
FThinBar: Boolean;
FTransparent: Boolean;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
constructor Create(AOwner: TComponent); override;
procedure SetThinBar(Value: Boolean);
procedure SetTransparent(Value: Boolean);
published
property ThinBar: Boolean read FThinBar write SetThinBar;
property Transparent: Boolean read FTransparent write SetTransparent;
property OnMouseDown;
end;

constructor TMyTrackBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FThinBar := False;
FTransparent := False;
end;

procedure TMyTrackBar.SetThinBar(Value: Boolean);
begin
FThinBar := Value;
invalidate;
end;

procedure TMyTrackBar.SetTransparent(Value: Boolean);
begin
FTransparent := Value;
Invalidate;
end;

procedure TMyTrackBar.CreateParams(var Params: TCreateParams);
begin
inherited;
if FThinBar then with Params do Style := Style and not TBS_ENABLESELRANGE;
if FTransparent then with Params do ExStyle := ExStyle or WS_EX_TRANSPARENT;
end;

Gabriel Corneanu

Posts: 17
Registered: 11/9/99
Re: Transparent form not transparent when compiled with Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 5, 2016 2:27 AM   in response to: John Smith in response to: John Smith
John Smith wrote:
Remy Lebeau (TeamB) wrote:
John wrote:

constructor TMyTrackBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FThinBar := False;
FTransparent := False;
end;

procedure TMyTrackBar.SetThinBar(Value: Boolean);
begin
FThinBar := Value;
invalidate;
end;

procedure TMyTrackBar.SetTransparent(Value: Boolean);
begin
FTransparent := Value;
Invalidate;
end;

procedure TMyTrackBar.CreateParams(var Params: TCreateParams);
begin
inherited;
if FThinBar then with Params do Style := Style and not TBS_ENABLESELRANGE;
if FTransparent then with Params do ExStyle := ExStyle or WS_EX_TRANSPARENT;
end;

Without trying, I think you should call RecreateWnd instead or Invalidate.
Invalidate is just triggering a redraw, CreateParams is only called when the handle is created.

Regards,
Gabriel
John Smith

Posts: 13
Registered: 6/12/09
Re: Transparent form not transparent when compiled with Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 5, 2016 4:30 AM   in response to: Gabriel Corneanu in response to: Gabriel Corneanu
Gabriel Corneanu wrote:

Without trying, I think you should call RecreateWnd instead or Invalidate.
Invalidate is just triggering a redraw, CreateParams is only called when the handle is created.

Regards,
Gabriel

Thanks for the idea but it made no difference. Does anybody know any difference in the way Berlin draws components or deals with transparency compared with XE7 - it seems to me that something must have changed and something I do in the existing project is causing that change to have an effect?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Transparent form not transparent when compiled with Berlin
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 5, 2016 4:23 PM   in response to: John Smith in response to: John Smith
John wrote:

FThinBar := Value;
invalidate;
...
FTransparent := Value;
Invalidate;

Your property setters are attempting to modify window styles, but Invalidate()
simply triggers a repaint, it does not trigger CreateParams() to apply the
new style values. You need to use TWinControl.RecreateWnd() for that purpose
instead, eg:

procedure TMyTrackBar.SetThinBar(Value: Boolean);
begin
  if FThinBar <> Value then
  begin
    FThinBar := Value;
    RecreateWnd;
  end;
end;
 
procedure TMyTrackBar.SetTransparent(Value: Boolean);
begin
  if FTransparent <> Value then
  begin
    FTransparent := Value;
    RecreateWnd;
  end;
end;


In the case of ThinBar, you are actually duplicating functionality that TTrackBar
already has. TTrackBar has a published ShowSelRange property that controls
the TBS_ENABLESELRANGE style, so you don't need your ThinBar property at
all. If you want to keep it for wording purposes, I suggest implementing
it in terms of the existing ShowSelRange property:

type
  TMyTrackBar = Class (TTrackBar)
  private
    FTransparent: Boolean;
    function GetThinBar: Boolean;
    procedure SetThinBar(Value: Boolean);
    procedure SetTransparent(Value: Boolean);
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property ThinBar: Boolean read GetThinBar write SetThinBar;
    property Transparent: Boolean read FTransparent write SetTransparent;
    property OnMouseDown;
  end;
 
constructor TMyTrackBar.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FTransparent := False;
end;
 
function TMyTrackBar.GetThinBar: Boolean;
begin
  Result := not ShowSelRange;
end;
 
procedure TMyTrackBar.SetThinBar(Value: Boolean);
begin
  ShowSelRange := not Value;
end;
 
procedure TMyTrackBar.SetTransparent(Value: Boolean);
begin
  if FTransparent <> Value then
  begin
    FTransparent := Value;
    RecreateWnd;
  end;
end;
 
procedure TMyTrackBar.CreateParams(var Params: TCreateParams);
begin
  inherited;
  if FTransparent then
    Params.ExStyle := Params.ExStyle or WS_EX_TRANSPARENT;
end;


--
Remy Lebeau (TeamB)
John Smith

Posts: 13
Registered: 6/12/09
Re: Transparent form not transparent when compiled with Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 8, 2016 6:48 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Your property setters are attempting to modify window styles, but Invalidate()
simply triggers a repaint, it does not trigger CreateParams() to apply the
new style values. You need to use TWinControl.RecreateWnd() for that purpose
instead, eg:

In the case of ThinBar, you are actually duplicating functionality that TTrackBar
already has. TTrackBar has a published ShowSelRange property that controls
the TBS_ENABLESELRANGE style, so you don't need your ThinBar property at
all. If you want to keep it for wording purposes, I suggest implementing
it in terms of the existing ShowSelRange property:

--
Remy Lebeau (TeamB)


Thanks for the suggestions. I have rewritten the components as you suggest and they work fine in a new project. It is the first rewrite since I was using Delphi 3 in the distant past so I guess I wrote the thinbar routine because that option was not available in those days.

I still have the original problem however in that the component paints itself with a solid clBtnFace background in my existing project. Even if I start a new project, create a window that displays a transparent track bar, then save it and add the new form to the existing project the new form opens with solid background in the existing project. I have looked through my project options and what I am doing on the forms that use this component and I can't see anything that looks like it would cause the problem.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Transparent form not transparent when compiled with Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 8, 2016 10:31 AM   in response to: John Smith in response to: John Smith
John wrote:

I still have the original problem however in that the component paints
itself with a solid clBtnFace background in my existing project. Even
if I start a new project, create a window that displays a transparent
track bar, then save it and add the new form to the existing project
the new form opens with solid background in the existing project. I
have looked through my project options and what I am doing on the
forms that use this component and I can't see anything that looks like
it would cause the problem.

Then the problem is more likely related to the project itself instead of
the particular Form. What is different between the two project setups?
For instance, does one enable visual themes/styles and the other does not?

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02