Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

stringgrid: hidden focus/select to all cells.

2,861 views
Skip to first unread message

Cooper

unread,
Apr 6, 2010, 2:09:40 PM4/6/10
to
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?

alang...@aol.com

unread,
Apr 6, 2010, 2:43:58 PM4/6/10
to

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

unread,
Apr 6, 2010, 3:24:09 PM4/6/10
to

<alang...@aol.com> ha scritto nel messaggio
news:b39de041-25af-4495...@u22g2000yqf.googlegroups.com...
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.

alang...@aol.com

unread,
Apr 6, 2010, 3:45:10 PM4/6/10
to
On 6 Apr, 20:24, "Cooper" <coo...@blueware.it> wrote:
> 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?

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

unread,
Apr 6, 2010, 4:55:27 PM4/6/10
to
<alang...@aol.com> ha scritto nel messaggio
news:be74090c-bc53-4dd7...@g11g2000yqe.googlegroups.com...

> Possibilities . . .
>
> 1) Your version of Delphi does not allow selection outside the grid.
>
I use delphi 2010... is a problem this version?

> 2) Your version of Delphi has a different (or no) Rect() function.
>

Rect is defined as TRect.

> 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.

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

Same error that before :(

> Works for me in D3.
>

Understood.

Thanks again.
Cooper.

Jamie

unread,
Apr 7, 2010, 5:39:07 AM4/7/10
to
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...

alang...@aol.com

unread,
Apr 7, 2010, 1:39:41 AM4/7/10
to
On 6 Apr, 21:55, "Cooper" <coo...@blueware.it> wrote:
> <alangll...@aol.com> ha scritto nel messaggionews:be74090c-bc53-4dd7...@g11g2000yqe.googlegroups.com...> Possibilities . . .

>
> > 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 ?

> > 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

unread,
Apr 7, 2010, 2:50:33 AM4/7/10
to

<alang...@aol.com> ha scritto nel messaggio
news:5cbffea4-83e3-4b4a...@o30g2000yqb.googlegroups.com...

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.

alang...@aol.com

unread,
Apr 7, 2010, 3:43:50 AM4/7/10
to
On 7 Apr, 07:50, "Cooper" <coo...@blueware.it> wrote:
<snip>

> 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:

That's your problem . . .

I said . . .

> 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

unread,
Apr 8, 2010, 7:26:16 AM4/8/10
to
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

unread,
Apr 8, 2010, 3:48:37 AM4/8/10
to
"Jamie" <jamie_ka1lpa_not_v...@charter.net> wrote in message
news:1w8vn.55883$ao7....@newsfe21.iad...
[...]

> 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


alang...@aol.com

unread,
Apr 8, 2010, 12:13:01 PM4/8/10
to
On 8 Apr, 12:26, Jamie
<jamie_ka1lpa_not_valid_after_ka1l...@charter.net> wrote:

> 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

unread,
Apr 9, 2010, 6:52:43 AM4/9/10
to
Maarten Wiltink wrote:
> "Jamie" <jamie_ka1lpa_not_v...@charter.net> wrote in message
> news:1w8vn.55883$ao7....@newsfe21.iad...
> [...]
>
>>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?

Jamie

unread,
Apr 9, 2010, 6:55:02 AM4/9/10
to
alang...@aol.com wrote:

> On 8 Apr, 12:26, Jamie
> <jamie_ka1lpa_not_valid_after_ka1l...@charter.net> wrote:
>
>
>>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

unread,
Apr 8, 2010, 8:07:32 PM4/8/10
to
"Jamie" <jamie_ka1lpa_not_v...@charter.net> wrote in message
news:L8tvn.98294$sx5....@newsfe16.iad...
> alang...@aol.com wrote:

> 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.

>
> 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.

alang...@aol.com

unread,
Apr 9, 2010, 2:48:28 AM4/9/10
to
On 9 Apr, 01:07, "BRoberts" <berdontem...@caneris.ca> wrote:

> > alangll...@aol.com wrote:
> > 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

unread,
Apr 9, 2010, 3:38:46 AM4/9/10
to
"BRoberts" <berdon...@caneris.ca> wrote in message
news:8duvn.36472$u62....@newsfe10.iad...

> "Jamie" <jamie_ka1lpa_not_v...@charter.net> wrote in
message
> news:L8tvn.98294$sx5....@newsfe16.iad...

>> 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.


[...]


>> If you insist, one could always use the TAG property as a condition
>> flag..

...Once.


> 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


0 new messages