Solved

StringGrids' Col and Row properties are not accurate

Posted on 2002-03-27
10
335 Views
Last Modified: 2010-04-04
Hi everyone,

I am using a StringGrid component (a bit modified to display icons in) in my app. When clicked on a certain cell[Col,Row], a particular Popup menu should open giving choices of actions on the contents of the current cell. In other words, if the cell displays a username in it, open a form with user info, and if the cell displays a folder that that user owns, then open that folder. Trouble is, when I use StringGrid.Row and StringGrid.Col, these two properties seem to report the current row and column very inaccurately. They often miss by one and the next row in error. Does anyone know a fix for that?

Thanks
Vlad
0
Comment
Question by:vladh
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6901370
Hi Vlad,

If you can give me your email address, I'll send you an example application  (compiled + source) which will should you what you want to know.

If you could include in that email a screen shot of what your application looks like running (the grid), that would help me no end.

Cheers,

Stu
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6901379
Vlad,

Email me at gtho1971@hotmail.com instead of posting your address here.  I'll reply to you within the next day (we've about to start a long weekend here).

Stu
0
 
LVL 3

Author Comment

by:vladh
ID: 6901436
Stuart,

I appreciate your offer, but this is a public forum and I would like the answer to my question to be publicly readable. I often scan answers to other peoples questions looking for hints to help with my questions. I would like others to be able to read this thread later and hopefully find the answer to their questions - this is what "Exchange" is all about.

Thanks
Vladimir
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6901748
I agree with you, Vlad :o)

Regards,
Nick
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6901826
Hi vladh,

>> these two properties seem to report the current
>> row and column very inaccurately.

??? never noticed. Seems the problem in another place. Can you show simplified part of code you using to open popup menu?

------
Igor.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6904878
As I always do, if you accept the answer, the code will be pasted into the forum anyway.

No problems tho.

Stu
0
 
LVL 3

Author Comment

by:vladh
ID: 6908475
Stuart,

The answer to my question is likely no longer than a couple of lines of code. If your app contains it, I would appreciate it if you could paste the relevant parts here.

Basically my StringGrid is a modified component (StringGrid descendant). The changes I made to it allow images to be painted in the cells; it also allows images to be drawn from different imagelists. I suspect there must be some mechanism that keeps track of the current row/column which breaks when I paint the cell contents in the overriden DrawCell method.

Could someone explain the general use of the Notify method and whether or not it would be relevant in my case?
Thanks
Vlad
0
 
LVL 3

Accepted Solution

by:
SteveWaite earned 50 total points
ID: 6911162
maybe this helps you:

  TMyKeyGrid = class(TStringGrid)
  private
    FCol, FRow: Integer;
  // ..
  protected
    function SelectCell(ACol, ARow: Longint): Boolean; override;
  // ..

implementation

function TMyKeyGrid.SelectCell(ACol, ARow: Longint): Boolean;
begin
  FCol := ACol;
  FRow := ARow;
  Result := True;
end;

procedure TMyKeyGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
var
  B: TMouseButton;
begin
  if ((Button = mbRight) and (Pos((IntToStr(FCol) + ':' + IntToStr(FRow)), FOffCells) > 0))
    then B := mbLeft
    else B := Button;
  inherited MouseDown(B, Shift, X, Y);
end;

procedure TMyKeyGrid.DblClick;
begin
  if (Pos((IntToStr(FCol) + ':' + IntToStr(FRow)), FOffCells) = 0)
    then inherited DblClick;
end;

procedure TMyKeyGrid.KeyDown(var Key: Word; Shift: TShiftState);
begin
  if (Key in [vk_Escape, vk_Up, vk_Down, vk_Left, vk_Right]) and (Pos((IntToStr(FCol) + ':' + IntToStr(FRow)), FOffCells) <> 0)
    then inherited KeyDown(Key, Shift)
    else
      if (Pos((IntToStr(FCol) + ':' + IntToStr(FRow)), FOffCells) = 0)
        then inherited KeyDown(Key, Shift);
end;

Regards,
Steve
0
 
LVL 3

Author Comment

by:vladh
ID: 6911291
Thanks to everyone who responded. The problem was in my own buggy code ;( and is now fixed. Steve deserves the points for an actual attempt to get the problem fixed and for some code I could use for a different purpose ;)

Thanks again
Vlad
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6911400
glad to help Vlad :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need Delphi function to get Youtube video title 5 225
Process Javascript errors with Delphi TWebBrowser 1 113
select query - oracle 16 94
tidtcpserver connection lost handle 2 70
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now