Board index » delphi » SelStart in a TStringGrid's Cell

SelStart in a TStringGrid's Cell

In a cell of a TStringGrid, how can I determine SelStart, SelLength
and SelText of the text in the cell?

Many thanks!

 

Re:SelStart in a TStringGrid's Cell


In article <3d95fcd3.9583...@news.earthlink.net>, s...@ieee.NOSPAM.org (Shel)
writes:

Quote
>In a cell of a TStringGrid, how can I determine SelStart, SelLength
>and SelText of the text in the cell?

These are properties of the InPlaceEditor, a protected property of a
TCustomGrid which is not exposed by TStringGrid. So you have to declare a
descendant of TStringGrid and typecast your stringgrid to that.

  type
    TIPEGrid = class(TStringGrid);  // to expose InPlaceEditor

... then at some appropriate place in your code ...

  var
    IPESelStart, IPESelLength : integer;
  begin
    IPESelStart := TIPEGrid(StringGrid1).InPlaceEditor.SelStart;
    IPESellength := TIPEGrid(StringGrid1).InPlaceEditor.SelLength;

TInPlaceEditor is a descendant of TCustomMaskEdit.

Alan Lloyd
alangll...@aol.com

Re:SelStart in a TStringGrid's Cell


Many thanks, Alan. I never would have discovered this myself.

On 28 Sep 2002 20:32:36 GMT, alangll...@aol.com (AlanGLLoyd) wrote:

Quote
>In article <3d95fcd3.9583...@news.earthlink.net>, s...@ieee.NOSPAM.org (Shel)
>writes:

>>In a cell of a TStringGrid, how can I determine SelStart, SelLength
>>and SelText of the text in the cell?

>These are properties of the InPlaceEditor, a protected property of a
>TCustomGrid which is not exposed by TStringGrid. So you have to declare a
>descendant of TStringGrid and typecast your stringgrid to that.

>  type
>    TIPEGrid = class(TStringGrid);  // to expose InPlaceEditor

>... then at some appropriate place in your code ...

>  var
>    IPESelStart, IPESelLength : integer;
>  begin
>    IPESelStart := TIPEGrid(StringGrid1).InPlaceEditor.SelStart;
>    IPESellength := TIPEGrid(StringGrid1).InPlaceEditor.SelLength;

>TInPlaceEditor is a descendant of TCustomMaskEdit.

>Alan Lloyd
>alangll...@aol.com

Re:SelStart in a TStringGrid's Cell


In article <3d96282f.20685...@news.earthlink.net>, s...@ieee.NOSPAM.org (Shel)
writes:

Quote
>Many thanks, Alan. I never would have discovered this myself.

But the techniques of finding such information are not hard to learn <g>.

I had a vague recollection about it but the main sources of knowledge are
Delphi help, and Delphi source code.

Choosing "Find" in Delphi help and entering "grid", shows a topic having
"TInPlaceEdit" in the name. Entering that in "Index" in help, showed it had a
property of SelStart and SelLength (and SelText) from TCustomEdit. As this is
one of the ancestors of TStringGrid I was on the right trail.

I searched in Grids,pas (the unit referenced in the help file for TInPlaceEdit)
for TInPlaceEdit and found that an InPlaceEditor _was_ a protected property of
TCustomGrid.

Looking at TStringGrid in help showed that its heirarchy was TDrawGrid to
TCustomGrid. A check in grids.pas revealed that neither TDrawGrid nor
TStringGrid exposed the InPlaceEdit.

Exposing protected properties by type-casting to a descendant is a known
technique, so I had to do that to get at the InPlaceEditor's properties of
SelStart and SelLength.

The above is not "Rocket Science" but techniques you should learn and be
familiar with to get answers to queries you may have. I (and others) are glad
to help with our experience and knowledge, but unless those who ask questions
don't learn "knowledge source techniques" we will answer questions for ever
<g>.

This is _not_ a rant against you and other questioners, but an exhortation to
learn the techniques of obtaining "knowledge from facts", so that that
knowledge plus the "knowledge from experience" enhances your skills in Delphi.

Add to the above techniques an MS Word file of interesting snippets (with an
appropriate heading which I can search in Outline view, and now 1.7Mb) which
have been posted, and which I reckon I would not have found out by myself.

Alan Lloyd
alangll...@aol.com

Other Threads