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
[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.
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
> 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.
Take a look at "TDrawGrid"
With that, you do most of the work, that includes supplying your own
stringlist etc...
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
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.
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
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
> 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
Never heard of Static types?
> 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..
> 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.
You're quoting words I didn't use.
Alan Lloyd
>> 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