runtime

16/03/2003

0

Por favor se algúm puder me ajudar ficarei aternamente grato.

Questao:
Em meu aplicativo criei em tempo de execucao um pagecontrol com N paginas, dentro de cada pagina criei, tambem em tempo de execucao, um stringgrid.

Pergunta: como fazer com que ao clicar em uma celula de qualquer um dos stringgrid a procedure que eu chamo me diga em que stringgrid, e em que celula estou clicando.

Codigo:

.
.
.

with pc1 do
for e := 1 to StrToInt(edtEST.Text)-1 do
with TTabSheet.Create(ts0) do
begin
PageControl := pc1;
Name := ´ts´ + IntToStr(e);
Caption := ´ Estante ´ + IntToStr(e+1);
end;

nc := 1;

pc1.ActivePage:=pc1.Pages[0];

with dg0 do
begin
ColCount := StrToInt(edtCAI.Text)+1;
RowCount := StrToInt(edtPRA.Text);
FixedCols := 1;
FixedRows := 0;
GridLineWidth := lw;
DefaultColWidth := ((Width-tfc) div (StrToInt(edtCAI.Text)+1));
DefaultRowHeight := ((Height-tfl) div (StrToInt(edtPRA.Text)));
Font.Style := [fsBold];
dg0.OnDblClick := teste;
for i:=0 to StrToInt(edtPRA.Text)-1 do
begin
dg0.Cells[0,i] := chr(65+i);
for j:=1 to StrToInt(edtCAI.Text) do
begin
dg0.Cells[j, i] := IntToStr(nc);
nc := nc + 1;
end;
end;
end;


for e := 1 to StrToInt(edtEST.Text)-1 do
begin
pc1.ActivePage:=pc1.Pages[e];
dg:=TStringGrid.Create(dg0);
dg.Name:=´dg´+IntToStr(e);
pc1.ActivePage.InsertControl(dg);
with dg do
begin
ColCount := StrToInt(edtCAI.Text)+1;
RowCount := StrToInt(edtPRA.Text);
FixedCols := 1;
FixedRows := 0;
Align := alClient;
Color := clCream;
GridLineWidth := lw;
DefaultColWidth := ((Width-tfc) div (StrToInt(edtCAI.Text)+1));
DefaultRowHeight := ((Height-tfl) div (StrToInt(edtPRA.Text)));
ScrollBars := ssNone;
Font.Style := [fsBold];
OnDblClick := teste;
for i:=0 to StrToInt(edtPRA.Text)-1 do
begin
dg.Cells[0,i] := chr(65+i);
for j:=1 to StrToInt(edtCAI.Text) do
begin
dg.Cells[j, i] := IntToStr(nc);
nc := nc + 1;
end;
end;

end;
end;

.
.
.

procedure TForm1.teste(Sender: TObject);
begin
ShowMessage(Sender.ClassName);
end;


Anonymous

Anonymous

Responder

Posts

16/03/2003

Carnette

Inclua na seção uses: Windows

// Procedure para saber qual stringgrid e posição que vc está na celula
procedure MouseCell(Grid: TStringGrid;
var Coluna, Linha: integer);
var
Pt: TPoint;
begin
GetCursorPos(Pt);
Pt := Grid.ScreenToClient(Pt);
if PtInRect(Grid.ClientRect, Pt) then
Grid.MouseToCell(Pt.X, Pt.Y, Coluna, Linha)
else begin
Coluna := -1;
Linha := -1;
end;
end;


//Voce digita este procedure..e em empo de execução direciona o evento onClick dos grids para ela
procedure TForm1.StringGrid1Click(Sender: TObject);
var
Coluna, Linha: integer;
begin
MouseCell(TStringGrid(sender), Coluna, Linha);
if (Coluna >= 0) and (Linha >= 0) then
Caption := TStringGrid(sender).Name+´Coluna: ´ + IntToStr(Coluna) + ´ - ´ + ´Linha: ´ + IntToStr(Linha)
else
Caption := ´O mouse não está no StringGrid´;
end;


Responder

16/03/2003

Anonymous

Muito obrigado pela sua resposta. Value mesmo.


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar