[Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

Werner Pamler
For fpspreadsheet I would like to implement the feature of Excel or
Libre/OpenOffice that multiple cell ranges can be selected. The grid
component in this package, TsSpreadsheetGrid, currently can select only
a single range (if goRangeSelect is in the grid's Options) due to its
inheritance from TCustomGrid.

My idea is to add a new "goMultiSelect" option to TCustomGrid directly
since this might be an interesting feature for other applications as
well, and then to write additional code to store multiple range
rectangles. It shouldn't be too difficult, but I am failing already at
the very first step: adding the new option to the type TGridOption. This
is the new declaration:

type
   TGridOption = (
     goFixedVertLine,      // Ya
     goFixedHorzLine,      // Ya
     goVertLine,           // Ya
     goHorzLine,           // Ya
     goRangeSelect,        // Ya
     goDrawFocusSelected,  // Ya
     goRowSizing,          // Ya
     goColSizing,          // Ya
     goRowMoving,          // Ya
     goColMoving,          // Ya
     goEditing,            // Ya
     goAutoAddRows,        // JuMa
     goTabs,               // Ya
     goRowSelect,          // Ya
     goAlwaysShowEditor,   // Ya
     goThumbTracking,      // ya
     // Additional Options
     goColSpanning,        // Enable cellextent calcs
     goRelaxedRowSelect,   // User can see focused cell on goRowSelect
     goDblClickAutoSize,   // dblclicking columns borders (on hdrs)
resize col.
     goSmoothScroll,       // Switch scrolling mode (pixel scroll is by
default)
     goFixedRowNumbering,  // Ya
     goScrollKeepVisible,  // keeps focused cell visible while scrolling
     goHeaderHotTracking,  // Header cells change look when mouse is
over them
     goHeaderPushedLook,   // Header cells looks pushed when clicked
     goSelectionActive,    // Setting grid.Selection moves also cell cursor
     goFixedColSizing,     // Allow to resize fixed columns
     goDontScrollPartCell, // clicking partially visible cells will not
scroll
     goCellHints,          // show individual cell hints
     goTruncCellHints,     // show cell hints if cell text is too long
     goCellEllipsis,       // show "..." if cell text is too long
     goAutoAddRowsSkipContentCheck,//BB Also add a row (if AutoAddRows
in Options) if last row is empty
     goRowHighlight,       // Highlight the current Row
     goMultiSelect         // Enable selection of multiple ranges <<<< NEW
   );
   TGridOptions = set of TGridOption;

Recompiling the package LCLBase fails with the error: "Property can't
have a default value". I think this message is misleading and confusing
because the true issue seems to me that the set of TGridOptions now
contains 33 elements. In my understanding, the elements of a set
correspond to the bits of an integer. In a 32-bit OS, therefore, a set
can only contain 32 elements - there is one too many now...

Is this interpretation correct?

OK, here I could circumvent this issue by introducing a new boolean
property "MultiSelect" which is evaluated when goRangeSelect is active.
Maybe this is even better than the goMultiSelect option because it
bypasses the conflict with goRangeSelect.

But what if I would not have this possibility? Is there a way to extend
the set to more than 32 elements? If not, split the Options into groups
of options like VirtualTreeView does? I fear the options of the grid
components will require a major redsign soon.

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

leledumbo
Administrator
> In my understanding, the elements of a set
> correspond to the bits of an integer. In a 32-bit OS, therefore, a set
> can only contain 32 elements - there is one too many now...
>
> Is this interpretation correct?

http://www.freepascal.org/docs-html/prog/progsu163.html#x207-2200008.2.8
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

Michael Van Canneyt
In reply to this post by Werner Pamler


On Wed, 5 Nov 2014, Werner Pamler wrote:

> For fpspreadsheet I would like to implement the feature of Excel or
> Libre/OpenOffice that multiple cell ranges can be selected. The grid
> component in this package, TsSpreadsheetGrid, currently can select only a
> single range (if goRangeSelect is in the grid's Options) due to its
> inheritance from TCustomGrid.

>>
> Recompiling the package LCLBase fails with the error: "Property can't have a
> default value". I think this message is misleading and confusing because the
> true issue seems to me that the set of TGridOptions now contains 33 elements.
> In my understanding, the elements of a set correspond to the bits of an
> integer. In a 32-bit OS, therefore, a set can only contain 32 elements -
> there is one too many now...
>
> Is this interpretation correct?

Yes.

>
> OK, here I could circumvent this issue by introducing a new boolean property
> "MultiSelect" which is evaluated when goRangeSelect is active. Maybe this is
> even better than the goMultiSelect option because it bypasses the conflict
> with goRangeSelect.
>
> But what if I would not have this possibility? Is there a way to extend the
> set to more than 32 elements? If not, split the Options into groups of
> options like VirtualTreeView does? I fear the options of the grid components
> will require a major redsign soon.

The 32-bit limit cannot be circumvented easily.
It would require a major redesign of streaming and rtti.
Your fastest path is splitting the options.

Michael.

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

Bart
In reply to this post by Werner Pamler
On 11/5/14, Werner Pamler <[hidden email]> wrote:

> Recompiling the package LCLBase fails with the error: "Property can't
> have a default value". I think this message is misleading and confusing
> because the true issue seems to me that the set of TGridOptions now
> contains 33 elements. In my understanding, the elements of a set
> correspond to the bits of an integer. In a 32-bit OS, therefore, a set
> can only contain 32 elements - there is one too many now...
>
> Is this interpretation correct?

I think it's not.

Default values must be of ordinal, pointer or small set type (Delphi)
(See: http://docwiki.embarcadero.com/RADStudio/XE7/en/E2146_Default_values_must_be_of_ordinal,_pointer_or_small_set_type_%28Delphi%29)

After you added the 33-rd option now SizeOf(TGridOptions) = 32 bytes.
Every option is stored as a bit, so you can have 256 (=32*8) options (I think).

Bart

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
rvk
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

rvk
In reply to this post by Werner Pamler
So it's not that the set can't hold more than 32 items...
It's just you can't use *default* for a property if the set's base has
more than 32 values.

This is from the Delphi manual (but I'm sure it also applies to FPC):
<quote>
The default and nodefault directives are supported only for ordinal
types and for set types, *provided the upper and lower bounds of the
set's base type have ordinal values between 0 and 31;*
</quote>
Source: http://docwiki.embarcadero.com/RADStudio/XE6/en/Properties

So the error message is not misleading at all ;)
<quote>
Error: Property can’t have a default value
   Set properties or indexed properties cannot have a default value.
</quote>

Maybe you can skip the default command for property and set the default
in Create. (Will that work correctly?)

Werner Pamler wrote:
> Recompiling the package LCLBase fails with the error: "Property can't
> have a default value". I think this message is misleading and confusing
> because the true issue seems to me that the set of TGridOptions now
> contains 33 elements. In my understanding, the elements of a set
> correspond to the bits of an integer. In a 32-bit OS, therefore, a set
> can only contain 32 elements - there is one too many now...
>
> Is this interpretation correct?

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

Frederic Da Vitoria
2014-11-05 18:35 GMT+01:00 Rik van Kekem <[hidden email]>:
So it's not that the set can't hold more than 32 items...
It's just you can't use *default* for a property if the set's base has more than 32 values.

This is from the Delphi manual (but I'm sure it also applies to FPC):
<quote>
The default and nodefault directives are supported only for ordinal types and for set types, *provided the upper and lower bounds of the set's base type have ordinal values between 0 and 31;*
</quote>
Source: http://docwiki.embarcadero.com/RADStudio/XE6/en/Properties

So the error message is not misleading at all ;)
<quote>
Error: Property can’t have a default value
  Set properties or indexed properties cannot have a default value.
</quote>

This may be me misunderstanding English, but I feel that it is misleading: To me, "Set properties cannot have a default value" means that even a set with 2 elements could not have a default value.

--
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » - http://www.april.org

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
rvk
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

rvk
On 05-11-2014 19:31, Frederic Da Vitoria wrote:
So the error message is not misleading at all ;)
<quote>
Error: Property can’t have a default value
  Set properties or indexed properties cannot have a default value.
</quote>

This may be me misunderstanding English, but I feel that it is misleading: To me, "Set properties cannot have a default value" means that even a set with 2 elements could not have a default value.
You are absolutely correct. But it does point in the right direction (unlike Werner expected) ;) However expanding the error-message to include the text that it only applies to sets with base types with more than 32 values would make it not fit on screen. But the help-page for the message could be expanded to include this text. (I got it from http://www.freepascal.org/docs-html/user/userse62.html)

So it should be something like this (with my limited English):
Error: Property can’t have a default value
    Set properties or indexed properties cannot have a default value if the upper and lower bounds of the set's base type have ordinal values between 0 and 31.

This message also comes when you right-click the error and choose help. So it could be clarified there too.


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

Howard Page-Clark
On 05/11/2014 18:58, Rik van Kekem wrote:
So it should be something like this (with my limited English):
Error: Property can’t have a default value
    Set properties or indexed properties cannot have a default value if the upper and lower bounds of the set's base type have ordinal values between 0 and 31.

I think you meant:
"... cannot have a default value if the upper or lower bounds of the set's (or array's) base type have ordinal values outside the range 0..31."

Howard

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
rvk
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

rvk
On 05-11-2014 20:11, Howard Page-Clark wrote:
I think you meant:
"... cannot have a default value if the upper or lower bounds of the set's (or array's) base type have ordinal values outside the range 0..31."
Yep.... That would be better ;) (That's what you get when you try to merge two opposite English sentences together.)
(From http://docwiki.embarcadero.com/RADStudio/XE6/en/Properties and http://www.freepascal.org/docs-html/user/userse62.html)


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

Flávio Etrusco
In reply to this post by Bart
On Wed, Nov 5, 2014 at 12:33 PM, Bart <[hidden email]> wrote:

> On 11/5/14, Werner Pamler <[hidden email]> wrote:
>
>> Recompiling the package LCLBase fails with the error: "Property can't
>> have a default value". I think this message is misleading and confusing
>> because the true issue seems to me that the set of TGridOptions now
>> contains 33 elements. In my understanding, the elements of a set
>> correspond to the bits of an integer. In a 32-bit OS, therefore, a set
>> can only contain 32 elements - there is one too many now...
>>
>> Is this interpretation correct?
>
> I think it's not.

AFAICS it is.

> Default values must be of ordinal, pointer or small set type (Delphi)
> (See: http://docwiki.embarcadero.com/RADStudio/XE7/en/E2146_Default_values_must_be_of_ordinal,_pointer_or_small_set_type_%28Delphi%29)
>
> After you added the 33-rd option now SizeOf(TGridOptions) = 32 bytes.
> Every option is stored as a bit, so you can have 256 (=32*8) options (I think).

No, SizeOf(TGridOptions) = 4 (bytes) = 32 bits = 32 options.

Best regards,
Flávio

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

leledumbo
Administrator
In reply to this post by rvk
Rik van Kekem wrote
On 05-11-2014 20:11, Howard Page-Clark wrote:
> I think you meant:
> "... cannot have a default value if the upper or lower bounds of the
> set's (or array's) base type have ordinal values *outside* the range
> 0..31."
Yep.... That would be better ;) (That's what you get when you try to
merge two opposite English sentences together.)
(From http://docwiki.embarcadero.com/RADStudio/XE6/en/Properties and
http://www.freepascal.org/docs-html/user/userse62.html)


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Anybody wants to file an error message enhancement to the bugtracker?
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

Sven Barth
In reply to this post by Flávio Etrusco
On 06.11.2014 04:43, Flávio Etrusco wrote:
>> Default values must be of ordinal, pointer or small set type (Delphi)
>> (See: http://docwiki.embarcadero.com/RADStudio/XE7/en/E2146_Default_values_must_be_of_ordinal,_pointer_or_small_set_type_%28Delphi%29)
>>
>> After you added the 33-rd option now SizeOf(TGridOptions) = 32 bytes.
>> Every option is stored as a bit, so you can have 256 (=32*8) options (I think).
>
> No, SizeOf(TGridOptions) = 4 (bytes) = 32 bits = 32 options.

If a 33rd option is added he's right:

=== code begin ===

program tsettest;

type
   TTest = (
     t1,
     t2,
     t3,
     t4,
     t5,
     t6,
     t7,
     t8,
     t9,
     t10,
     t11,
     t12,
     t13,
     t14,
     t15,
     t16,
     t17,
     t18,
     t19,
     t20,
     t21,
     t22,
     t23,
     t24,
     t25,
     t26,
     t27,
     t28,
     t29,
     t30,
     t31,
     t32,
     t33
   );

   TTests = set of TTest;

var
   t: TTests;
begin
   Writeln(SizeOf(t));
end.

=== code end ===

=== output begin ===

% ./tsettest
32

=== output end ===

Regards,
Sven

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Having more than 32 elements in a set (TGridOptions of TCustomGrid)

Flávio Etrusco
On Thu, Nov 6, 2014 at 3:41 AM, Sven Barth <[hidden email]> wrote:

> On 06.11.2014 04:43, Flávio Etrusco wrote:
>>>
>>> Default values must be of ordinal, pointer or small set type (Delphi)
>>> (See:
>>> http://docwiki.embarcadero.com/RADStudio/XE7/en/E2146_Default_values_must_be_of_ordinal,_pointer_or_small_set_type_%28Delphi%29)
>>>
>>> After you added the 33-rd option now SizeOf(TGridOptions) = 32 bytes.
>>> Every option is stored as a bit, so you can have 256 (=32*8) options (I
>>> think).
>>
>>
>> No, SizeOf(TGridOptions) = 4 (bytes) = 32 bits = 32 options.
>
>
> If a 33rd option is added he's right:
>
> === code begin ===
>
> program tsettest;
>
> type
>   TTest = (
>     t1,
>     t2,
>     t3,
>     t4,
>     t5,
>     t6,
>     t7,
>     t8,
>     t9,
>     t10,
>     t11,
>     t12,
>     t13,
>     t14,
>     t15,
>     t16,
>     t17,
>     t18,
>     t19,
>     t20,
>     t21,
>     t22,
>     t23,
>     t24,
>     t25,
>     t26,
>     t27,
>     t28,
>     t29,
>     t30,
>     t31,
>     t32,
>     t33
>   );
>
>   TTests = set of TTest;
>
> var
>   t: TTests;
> begin
>   Writeln(SizeOf(t));
> end.
>
> === code end ===
>
> === output begin ===
>
> % ./tsettest
> 32
>
> === output end ===
>
> Regards,
> Sven

Oh, OK, I misread the message. He was not implying the streaming would
allow that :-$
Sorry.

-Flávio

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus