Jump to content
alogrep

Determine if a stringgrid has ssboth or sshorizontal scrollbars defined

Recommended Posts

HI.

I have this line of code 

   if ( g.scrollbars =ssBoth) or (g.scrollbars=ssHorizontal)   then

     ....

(g is a tstringgrid);

I get the error 

   Incompatible styles: Tscrollstyles and Enumeration.

If I have only 

     if ( g.scrollbars =ssBoth) then

        ..

 (and with only g.scrollbars=ssHorizontal I still get the error)

I get no error message.

How can I determine if the scrollbars at design time is defined as ssBoth or ssHorizontal?

Any help?

Share this post


Link to post

Did you copy/paste the error message as-is?  There is no TScrollStyles type in the VCL, only TScrollStyle.

 

Do you, by chance, have a custom/3rd-party unit in your code that defines its own TScrollStyles type?  Perhaps also defines its own ssHorizontal constant of that type?

 

Have you tried qualifying the enum values with the enum type?  This is particularly important for ssHorizontal, which is defined by both of the System.UITypes.TScrollStyle and System.Classes.TShiftState types.

if ( g.ScrollBars = TScrollStyle.ssBoth) or (g.ScrollBars = TScrollStyle.ssHorizontal) then
if ( g.ScrollBars = TScrollStyle.ssBoth) then
if ( g.ScrollBars = TScrollStyle.ssHorizontal) then

 

Share this post


Link to post

@alogrep

 

maybe this way help you better no?

  • // TScrollStyle = System.UITypes.TScrollStyle deprecated 'Use System.UITypes.TScrollStyle';
implementation

{$R *.dfm}

uses
  System.TypInfo;

type
  TMyScrollStylesSetOfValues = set of TScrollStyle;  // if does not exists, we can create it!

  TMyHelperScrollStyle = record helper for TScrollStyle
    function ScrollBarStyleName: string;
  end;

  { TMyHelperScrollStyle }

function TMyHelperScrollStyle.ScrollBarStyleName: string;
begin
  result := GetEnumName(typeinfo(TScrollStyle), ord(Self));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  LStringGridScrollBarsIsUsingThisValues: TMyScrollStylesSetOfValues;
begin
  StringGrid1.ScrollBars := TScrollStyle.ssBoth; // testing...
  //
  LStringGridScrollBarsIsUsingThisValues := [ssBoth, ssHorizontal];
  //
    if (StringGrid1.ScrollBars in LStringGridScrollBarsIsUsingThisValues {or  ... [ssBoth, ssHorizontal] } ) then
    Memo1.Lines.Add('1: ' + StringGrid1.ScrollBars.ScrollBarStyleName)
  else
    Memo1.Lines.Add('2: ' + StringGrid1.ScrollBars.ScrollBarStyleName);
end;

 

 

         image.thumb.png.1f5c71defc66f7d1a5dc19df05dcfd9a.png

Edited by programmerdelphi2k

Share this post


Link to post

Thanks Remy.

Your solution worked.

I cannot find anywhere a componet that defines TScrollStyles. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×