Discussion:
stringgrid: hidden focus/select to all cells.
(too old to reply)
Cooper
2010-04-06 18:09:40 UTC
Permalink
Hello,
i have read about help guide but not found as solve this problem; i have
done some try with canvas but nothing. In practise; i have a stringgrid.
I set from option:

1) goRangeSelect = False;
2) goDrawFocusSelected = False;

I want that in cells, when i click on a cell with mouse, not came displayed
the focus (and not came selected it); i tried to disable stringgrid and i
have partially solved it; but i continue to display cell selected.
Shortly i want that all cells are same, without rectangle (about
focus/select).
Thanks to who can help me.
Cooper.

PS: I don't want redraw cells; or if necessary redraw cell, i can redraw
ONLY cells NOT-FIXED?
a***@aol.com
2010-04-06 18:43:58 UTC
Permalink
Post by Cooper
Hello,
i have read about help guide but not found as solve this problem; i have
done some try with canvas but nothing. In practise; i have a stringgrid.
1) goRangeSelect = False;
2) goDrawFocusSelected = False;
I want that in cells, when i click on a cell with mouse, not came displayed
the focus (and not came selected it); i tried to disable stringgrid and i
have partially solved it; but i continue to display cell selected.
Shortly i want that all cells are same, without rectangle (about
focus/select).
Thanks to who can help me.
Cooper.
PS: �I don't want redraw cells; or if necessary redraw cell, i can redraw
ONLY cells NOT-FIXED?
You have two solutions . . .

1 Use your own code in onDrawCell event handler to _not_ draw
selection or focus. Also use DefaultDraw := false.

2 In the OnClick event handler change the selected cell to one off
the stringgrid display . . .

MyStringGrid.Selection := TGridRect(Rect(-1,-1,-1,-1));

Alan Lloyd
Cooper
2010-04-06 19:24:09 UTC
Permalink
Post by a***@aol.com
2 In the OnClick event handler change the selected cell to one off
the stringgrid display . . .
MyStringGrid.Selection := TGridRect(Rect(-1,-1,-1,-1));
Thanks very much, about this solution, i have this error:

[DCC Error] Test.pas(51): E2066 Missing operator or semicolon

at: (-1,-1,-1,-1).

I solved writing:

Xr.Top := -1;
Xr.Left := -1;
Xr.Right := -1;
Xr.Bottom := -1;

MyStringGrid.Selection := TGridRect(xr);

But not understood why not agree form:

MyStringGrid.Selection := TGridRect(Rect(-1,-1,-1,-1));

Some idea?
Just a thing, sometime came gived exception with message: Grid index out of
range, can i solve?
Thanks again for help.
a***@aol.com
2010-04-06 19:45:10 UTC
Permalink
�[DCC Error] Test.pas(51): E2066 Missing operator or semicolon
at: �(-1,-1,-1,-1).
� � � Xr.Top := -1;
� � � Xr.Left := -1;
� � � Xr.Right := -1;
� � � Xr.Bottom := -1;
� �MyStringGrid.Selection := TGridRect(xr);
� �MyStringGrid.Selection := TGridRect(Rect(-1,-1,-1,-1));
Some idea?
Possibilities . . .

1) Your version of Delphi does not allow selection outside the grid.

2) Your version of Delphi has a different (or no) Rect() function.
Look it up in Delphi Help. Its in Classes.pas, is this in your uses
clause.

Try using TGridRect(Rect (2,2,2,2)) and see if its 1) above.

Works for me in D3.

Alan Lloyd
Cooper
2010-04-06 20:55:27 UTC
Permalink
Post by a***@aol.com
Possibilities . . .
1) Your version of Delphi does not allow selection outside the grid.
I use delphi 2010... is a problem this version?
Post by a***@aol.com
2) Your version of Delphi has a different (or no) Rect() function.
Rect is defined as TRect.
Post by a***@aol.com
Look it up in Delphi Help. Its in Classes.pas, is this in your uses
clause.
Not understood well, but class uses is in uses clause.
Post by a***@aol.com
Try using TGridRect(Rect (2,2,2,2)) and see if its 1) above.
Same error that before :(
Post by a***@aol.com
Works for me in D3.
Understood.

Thanks again.
Cooper.
Jamie
2010-04-07 09:39:07 UTC
Permalink
Post by Cooper
Post by a***@aol.com
Possibilities . . .
1) Your version of Delphi does not allow selection outside the grid.
I use delphi 2010... is a problem this version?
Post by a***@aol.com
2) Your version of Delphi has a different (or no) Rect() function.
Rect is defined as TRect.
Post by a***@aol.com
Look it up in Delphi Help. Its in Classes.pas, is this in your uses
clause.
Not understood well, but class uses is in uses clause.
Post by a***@aol.com
Try using TGridRect(Rect (2,2,2,2)) and see if its 1) above.
Same error that before :(
Post by a***@aol.com
Works for me in D3.
Understood.
Thanks again.
Cooper.
Maybe what you need is to step back a little and build on your own grid..

Take a look at "TDrawGrid"

With that, you do most of the work, that includes supplying your own
stringlist etc...
a***@aol.com
2010-04-07 05:39:41 UTC
Permalink
Post by Cooper
Post by a***@aol.com
2) Your version of Delphi has a different (or no) Rect() function.
Rect is defined as TRect.
That's the result of the function. Are the parameters of the Rect()
function comma-separated integers ?
Post by Cooper
Post by a***@aol.com
Try using TGridRect(Rect (2,2,2,2)) and see if its 1) above.
Same error that before :(
Something is very strange, maybe in your program. Open a new project,
place a TStringGrid on the form, and in the form's OnCreate event
handler put the . . .

StringGrid1.Selection := TGridRect(Rect(2,2,2,2));

. . . code. If that works try changing the parameters to -1,-1,-1,-1 &
see if that works.

If both work you've got something strange in your original program
code.

If neither work you've got something _very_ strange, which I don't
know. Any gurus about <g>.

Alan Lloyd
Cooper
2010-04-07 06:50:33 UTC
Permalink
Post by a***@aol.com
Post by a***@aol.com
Possibilities . . .
Post by a***@aol.com
2) Your version of Delphi has a different (or no) Rect() function.
Rect is defined as TRect.
That's the result of the function. Are the parameters of the Rect()
function comma-separated integers ?
Post by a***@aol.com
Post by a***@aol.com
Try using TGridRect(Rect (2,2,2,2)) and see if its 1) above.
Same error that before :(
Something is very strange, maybe in your program. Open a new project,
place a TStringGrid on the form, and in the form's OnCreate event
handler put the . . .
StringGrid1.Selection := TGridRect(Rect(2,2,2,2));
. . . code. If that works try changing the parameters to -1,-1,-1,-1 &
see if that works.
If both work you've got something strange in your original program
code.
If neither work you've got something _very_ strange, which I don't
know. Any gurus about <g>.
Done as you told, when i put it in OnCreate event, it work in both case, no
problem; if i put it in onDrawCell then is problem with error: "[DCC Error]
Test.pas(32): E2066 Missing operator or semicolon"

Thanks again for help.
Cooper.
a***@aol.com
2010-04-07 07:43:50 UTC
Permalink
On 7 Apr, 07:50, "Cooper" <***@blueware.it> wrote:
<snip>
Post by Cooper
Done as you told, when i put it in OnCreate event, it work in both case, no
That's your problem . . .

I said . . .
Post by Cooper
2 In the OnClick event handler change the selected cell to one off
the stringgrid display . . .
MyStringGrid.Selection := TGridRect(Rect(-1,-1,-1,-1));
If you put it in the OnDrawCell then changing the selection causes a
redraw of the grid, which calls the OnDrawCell, which changes the
selection etc. ie a recursive state. This would cause some sort of
stack overflow.

You _can_ put it in the OnClick or in the OnMouseDown or OnMouseUp
event, but _not_ in the OnDrawCell (at least not without a real hack
which I would not expect you (or want you) to know.

Alan Lloyd
Jamie
2010-04-08 11:26:16 UTC
Permalink
Post by a***@aol.com
<snip>
Post by Cooper
Done as you told, when i put it in OnCreate event, it work in both case, no
That's your problem . . .
I said . . .
Post by Cooper
2 In the OnClick event handler change the selected cell to one off
the stringgrid display . . .
MyStringGrid.Selection := TGridRect(Rect(-1,-1,-1,-1));
If you put it in the OnDrawCell then changing the selection causes a
redraw of the grid, which calls the OnDrawCell, which changes the
selection etc. ie a recursive state. This would cause some sort of
stack overflow.
You _can_ put it in the OnClick or in the OnMouseDown or OnMouseUp
event, but _not_ in the OnDrawCell (at least not without a real hack
which I would not expect you (or want you) to know.
Alan Lloyd
And he can also put a BUSY const inside that DrawEvent to avoid reentry..

Constant
Busy:boolean = false;
Begin
If Busy then exit else busy := true;

// do your code now...

Busy := false;
End;
Maarten Wiltink
2010-04-08 07:48:37 UTC
Permalink
"Jamie" <***@charter.net> wrote in message news:1w8vn.55883$***@newsfe21.iad...
[...]
Post by Jamie
And he can also put a BUSY const inside that DrawEvent to avoid reentry..
Constant
Busy:boolean = false;
Begin
If Busy then exit else busy := true;
// do your code now...
Busy := false;
End;
If Busy is a constant, how can I change its value?

Yes, I know, there's a compiler switch that enables just that.
It stays OFF in my projects, thank you very much. They're _constants_.

There is the different concern that there is now a single flag
guarding possibly several object instances. That may be exactly what
you want, but it would come more naturally to me to put that Busy
flag in the classtype. No need to call it a constant then, either, and
you get a flag whose scope actually matches that of your event.

A try-finally would also be a good idea. This way, if the 'do your code
now...' bit ever throws an exception, the event will stay disabled
forever.

Groetjes,
Maarten Wiltink
Jamie
2010-04-09 10:52:43 UTC
Permalink
Post by Maarten Wiltink
[...]
Post by Jamie
And he can also put a BUSY const inside that DrawEvent to avoid reentry..
Constant
Busy:boolean = false;
Begin
If Busy then exit else busy := true;
// do your code now...
Busy := false;
End;
If Busy is a constant, how can I change its value?
Yes, I know, there's a compiler switch that enables just that.
It stays OFF in my projects, thank you very much. They're _constants_.
Never heard of Static types?
a***@aol.com
2010-04-08 16:13:01 UTC
Permalink
On 8 Apr, 12:26, Jamie
Post by Jamie
And he can also put a BUSY const inside that DrawEvent to avoid reentry..
Constant
� Busy:boolean = false;
Begin
� �If Busy then exit else busy := true;
� �// do your code now...
� �Busy := false;
End;
I would prefer ...

var
SavedOnDrawCell : TDrawCellEvent;
begin
SavedOnDrawCell := MyStringGrid.OnDrawCell;
MyStringGrid.OnDrawCell := nil;
try
// do stuff
finally
MyStringGrid.OnDrawCell := SavedOnDrawCell;
end;
end;

Its rather clearer what you are doing.

Alan Lloyd
Jamie
2010-04-09 10:55:02 UTC
Permalink
Post by a***@aol.com
On 8 Apr, 12:26, Jamie
Post by Jamie
And he can also put a BUSY const inside that DrawEvent to avoid reentry..
Constant
� Busy:boolean = false;
Begin
� �If Busy then exit else busy := true;
� �// do your code now...
� �Busy := false;
End;
I would prefer ...
var
SavedOnDrawCell : TDrawCellEvent;
begin
SavedOnDrawCell := MyStringGrid.OnDrawCell;
MyStringGrid.OnDrawCell := nil;
try
// do stuff
finally
MyStringGrid.OnDrawCell := SavedOnDrawCell;
end;
end;
Its rather clearer what you are doing.
Alan Lloy
I guess no one likes using Static types, I use them all the time.
Makes life so much easier..

If you insist, one could always use the TAG property as a condition
flag..
BRoberts
2010-04-09 00:07:32 UTC
Permalink
Post by Jamie
I guess no one likes using Static types, I use them all the time.
Makes life so much easier..
I too use static variables when they make sense, which is relatively rarely.
I suspect that part of the reason they don't tend to be used in Delphi is
because Pascal never had them and many people object to overloading the
keyword CONST.
Post by Jamie
If you insist, one could always use the TAG property as a condition
flag..
Tag, IMO, is really not a good option. There is no easy way to document it's
use in the code and the habit is prone to unintended double use.
a***@aol.com
2010-04-09 06:48:28 UTC
Permalink
Post by Jamie
I guess no one likes using Static types, I use them all the time.
Makes life so much easier..
You're quoting words I didn't use.

Alan Lloyd
Maarten Wiltink
2010-04-09 07:38:46 UTC
Permalink
Post by BRoberts
Post by Jamie
I guess no one likes using Static types, I use them all the time.
Makes life so much easier..
I think the words used in the help are 'explicitly typed constants'.
And I'll freely admit they behave much like C's static variables...
sometimes. And Pascal doesn't really have a good equivalent.

So I'll make do with one of the poor equivalents that does not depend on
compiler settings, and does not break the meaning of language keywords.

Do not underestimate the importance of 'meaning'. Compilers are in a
sense an easy audience. They are very literal-minded and never confused
by terminology, because they don't know or care what you _mean_ anyway;
they live by their own rules. It's people you have to worry about. If
someone else needs to read your code, or may need to in the unspecified
future, it's a good idea to be conservative in what you send, and to
only use 'const' to bloody well mean 'const'.

'Making life easier' is a relative concept. Since we all mostly work
in the scope of a class now, it could be argued that life is made
easiest by introducing our flags at that same scope, as protected
fields/properties. No problems with separate instances sharing the
same unit-scope flag. No problems having several event handlers react
to the same flag.


[...]
Post by BRoberts
Post by Jamie
If you insist, one could always use the TAG property as a condition
flag..
...Once.
Post by BRoberts
Tag, IMO, is really not a good option. There is no easy way to document
it's use in the code and the habit is prone to unintended double use.
When I started in my current job, I consciously took on a new habit.
If I use Tag in a unit, I describe exactly how it's used, in a comment
near the top.

Also, when I need a Boolean, I use only one bit at a time.

Groetjes,
Maarten Wiltink

Loading...