Como atribuir focus a componente criado em tempo de execuçao, conforme abaixo:
As stringAligGrid representarão volantes vazios da lotomania , que serão preenchidos depois.
então suponha que o usuario precise de 10 volantes,,,,ele clica 10 vezes e constroi os volantes vazios.
Após criar os volantes ele vai preenche-los um a um. Ao clicar em determinado numero (celula) a referida deverá ficar verde.
Não consigo colorir a celula da stringgrid (volante) clicada, O EVENTO ACONTECE ou seja a celula fica marcada mais ao invés disso acontecer na stringaliggrid clicada acontece na ultima stringAligngrid CRIADA, como se apos o ultimo volante SER criado ele ficara preso na memoria.. e nao consigo dar o setfocus ou acessar nenhum outro volante que foi criado em tempo de execuçao. ....Obrigado
unit grade_virtual;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, Aligrid, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure colorir(Sender :TObject);
procedure ENCHER;
procedure colorir_celula(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
grade:TStringAlignGrid;
ESQUERDA:Integer;
ALTura:Integer;
CONTADOR:Integer;
numeral:Integer;
col,lin:Integer;
cor:tcolor;
x1:string;
compcomponent:TStringAlignGrid;
{$R *.DFM}
procedure tform1.colorir(Sender :TObject);
begin
//grade.ColorCell[col,lin]:=clGreen;
end;
procedure tform1.colorir_celula(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
grade.SetFocus;
col:=acol;
lin:=arow;
grade.ColorCell[col,lin]:=clGreen;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
grade:=TStringAlignGrid.Create(form1);
grade.top:=ALTura;
grade.LEFT:=10 +esquerda;
grade.RowCount:=10;
grade.ColCount:=10;
grade.FixedRows:=0;
grade.FixedCols:=0;
grade.DefaultColWidth:=20;
grade.DefaultRowHeight:=20;
grade.Width:=215;
grade.Height:=215;
grade.Parent:=Self;
//grade.Name:='Grade_' + FormatFloat('00',numeral);
grade.OnSelectCell:=colorir_celula;
grade.OnClick:=colorir;
grade.hint:='grade.name';
grade.ShowHint:=True;
ENCHER;
Inc(CONTADOR);
Inc(numeral);
if (contador > 0) and (CONTADOR <6) then
begin
esquerda:= esquerda + 220;
end;
if CONTADOR > 5 then
begin
contador:=1;
esquerda:=10;
altura:= ALTura +230;
end;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
CONTADOR:=1;
ESQUERDA:=10;
altura:=70;
end;
procedure Tform1.ENCHER;
var
i,c,l:integer;
N:STRING;
begin
c:=0;
l:=0;
for i:=1 to 100 do
begin
N:=FORMATFLOAT('00',I);
if i=100 then
begin
grade.Cells[c,l]:='00';
exit;
end;
if i<>100 then
begin
GRADE.Cells[c,l]:=N;
end;
C:=C+1;
if c=10 then
begin
L:=L+1;
if i=100 then
begin
grade.Cells[10,10]:='00';
end;
c:=0;
end;
end;
end;