Recent

Author Topic: TScrollingWinControl and scrolling  (Read 8938 times)

korba812

  • Sr. Member
  • ****
  • Posts: 464
TScrollingWinControl and scrolling
« on: May 15, 2010, 08:33:03 pm »
Hello!

I'm trying to port delphi component to lcl. I have got some trouble with TScrollingWinControl descendant. When I scroll this control, scroll bar "Position" property allways point scrolling width (or height) divided by 2.
Next question is about TControlScrollBar. How can I calculate "Page" propery? Should be ClientWidth/Height?

Martin V

  • Full Member
  • ***
  • Posts: 139
Re: TScrollingWinControl and scrolling
« Reply #1 on: May 23, 2010, 12:52:53 pm »
Hi,

I have also problems with ScrollingWinControl. It seems that the Lazarus behaviour is different from Delphi. If you create a sample project with a Form1 and then put a button into the form and then write:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  Height := 500;
  VertScrollbar.Range := 1000;
  VertScrollbar.Position := 250;
end;
The height of the moveable button should be 50% of the full height of the window and it should be centered, the partitions are 25% above the movable button, 50% moveable button and 25% below the moveable button. In Delphi the behaviour is OK, in Lazarus, the moveable button is only perhaps 10% of the window height instead of 50%.

Is it a bug or is the Lazarus behaviour different?

korba812

  • Sr. Member
  • ****
  • Posts: 464
Re: TScrollingWinControl and scrolling
« Reply #2 on: May 24, 2010, 04:53:19 pm »
LCL version of TScrollingWinControl is different than VCL and have many inconsistencies.
VCL version dosesn't have Canvas property. is introduced in TCustomControl.
In LCL, when scrollbar position is changed, canvas position is also scrolled. This make many problems eg. popup menu is shown in wrong place. Mouse events coordinates are different than GetCursorPos. etc...

Martin V

  • Full Member
  • ***
  • Posts: 139
Re: TScrollingWinControl and scrolling
« Reply #3 on: May 25, 2010, 12:17:45 pm »
Is there a documentation about LCL tControlScrollbar and tScrollingWinControl ? (besides the 'reference for package lcl')

Martin V

  • Full Member
  • ***
  • Posts: 139
Re: TScrollingWinControl and scrolling
« Reply #4 on: May 31, 2010, 10:02:58 am »
For porting an existing application, I have decided to write my own Form with Scrollbars based on tScrollbar and not tControlScrollbar. So it is much more close to VCL. I have only added the functionality I needed for my application. Feel free to extend the object. Because I come from WDsibyl and not from Delphi, perhaps there's the need of modifications.

Code: [Select]
type
tScrollForm=Class(tForm)
  private
    FScrollBars:TScrollStyle;
    FVertScrollbar, FHorzScrollbar : tScrollbar;
  protected
    procedure OnCreate; override;
    Procedure SetScrollBars(NewValue:TScrollStyle);
    Procedure Scroll(Sender:TObject;ScrollCode:TScrollCode;Var ScrollPos:Longint);virtual;
    property VertScrollbar : tScrollbar read FVertScrollbar; {overwrite the old tControlScrollbar property}
    property HorzScrollbar : tScrollbar read FHorzScrollbar; {overwrite the old tControlScrollbar property}
    Property ScrollBars:TScrollStyle Read FScrollbars Write SetScrollBars;
end;

const
    scColumnLeft = scLineUp;
    scColumnRight = scLineDown;
    scPageLeft = scPageUp;
    scPageRight = scPageDown;
    scHorzPosition = scPosition;
    scVertPosition = scPosition;
    scHorzTrack = scTrack;
    scVertTrack = scTrack;
    scHorzEndScroll = scEndScroll;
    scVertEndScroll = scEndScroll;

implementation

procedure tScrollForm.OnCreate;
  begin
    inherited OnCreate;
    FHorzScrollbar := tScrollbar.Create(self); FHorzScrollbar.Visible := false;
    FHorzScrollbar.Kind := sbHorizontal; FHorzScrollbar.Align := alBottom; FHorzScrollbar.OnScroll := @Scroll;
    InsertControl (FHorzScrollbar);
    FVertScrollbar := tScrollbar.Create(Self); FVertScrollbar.Visible := false;
    FVertScrollbar.Kind := sbVertical; FVertScrollbar.Align := alRight; FVertScrollbar.OnScroll := @Scroll;
    InsertControl (FVertScrollbar);
    fScrollbars := ssNone;
  end;

Procedure tScrollForm.SetScrollBars(NewValue:TScrollStyle);
  begin
    if NewValue = ssBoth then begin
      FVertScrollbar.Visible := true; FHorzScrollbar.Visible := true;
    end
    else if NewValue = ssHorizontal then begin
      FVertScrollbar.Visible := false; FHorzScrollbar.Visible := true;
    end
    else if NewValue = ssVertical then begin
      FVertScrollbar.Visible := true; FHorzScrollbar.Visible := false;
    end
    else begin
      FVertScrollbar.Visible := false; FHorzScrollbar.Visible := false;
    end;
    FScrollbars := NewValue;
  end;

Procedure tScrollForm.Scroll(Sender:TObject;ScrollCode:TScrollCode;Var ScrollPos:Longint);
  begin
  end;

 

TinyPortal © 2005-2018