[DUG]: Stringgrid methods?

John Bird johnkbird at paradise.net.nz
Mon Mar 20 17:06:21 NZST 2006


Incidentally you can access the grid properties, as long as you know it is a
grid calling the event, you can do code such as to call your procedure, if
it has a parameter Sender:TObject  :


	gridkeypress((Sender as TCustomGrid),key);

You can also do stuff like:
	
    if Comp.components[i] is TStringgrid then
    begin
      ltype:='Grid';
      top:=(Comp.Components[i] as TStringGrid).top;
      left:=(Comp.Components[i] as TStringGrid).left;
      width:=(Comp.Components[i] as TStringGrid).width;
      compfont:=(Comp.Components[i] as TStringgrid).font;
      lcolmax:=(comp.Components[i] as TStringGrid).ColCount-1;
      lrowmax:=(comp.Components[i] as TStringGrid).RowCount-1;
      for colptr := 0 to lcolmax do
        lcolwidths[colptr]:=(comp.Components[i] as
TStringGrid).Colwidths[colptr];
    end

In this case Comp is  Tcomponent and contains the name of the form, and you
can iterate through the form components as in this block, and this obtains
the properties of the individual component into local variables.

In case this helps...

John

-----Original Message-----
From: delphi-bounces at ns3.123.co.nz [mailto:delphi-bounces at ns3.123.co.nz] On
Behalf Of Chris Veale
Sent: Wednesday, 4 August 2004 12:56 p.m.
To: delphi at delphi.org.nz
Subject: [DUG]: Stringgrid methods?
Importance: High



** High Priority **

Hi.

I am creating a few stringgrids on my form at runtime and want to be able to
hook into the onkeypress event that I would have if I included the
functionality at designtime.

but I want to call a procedure that automatically moves the current cell
based on the key entered (effectively), so I want to pass a parameter of
type stringgrid and key to the procedure

I have a procedure

gridkeypress(grid:tstringgrid;key:char)
begin
   ...do stuff with the passed grid
end;

but how do I assign this method to the freshly created grid dynamically? so
that when a user clicks any grid, I call this procedure and action the
keypress accordingly?

I have tried assigning the onkeypress event of the created grid to
gridkeypress but the compiler complains about incompatible types (as tobject
seems to be expected) but I cant pass the grid as a tobject as then I cant
access the grid properties at all?

Can someone please tell me how I can overcome this?

Cheers

Chris

______________________________________________________

The contents of this e-mail are privileged and/or confidential to the named
recipient and are not to be used by any other person and/or organisation. If
you have received this e-mail in error, please notify 
the sender and delete all material pertaining to this e-mail.
______________________________________________________
_______________________________________________
Delphi mailing list
Delphi at ns3.123.co.nz http://ns3.123.co.nz/mailman/listinfo/delphi




More information about the Delphi mailing list