Ver la Versión Completa : Asignar una función dinámicamente
strelok
07-02-2018, 17:14:19
Hola,
me gustaría saber si es posible asignar una función al evento OnGetCellColor de los TAdvStringGrid y TDBAdvGrid, si y solo si, no hacen uso de ese evento actualmente ¿es posible?:D
ecfisa
07-02-2018, 21:00:41
Hola.
Nunca he usado los componentes TMS, pero de acuerdo a esta guía, TMS TAdvStringGrid DEVELOPERS GUIDE (http://www.tmssoftware.biz/download/manuals/TMS%20TAdvStringGrid%20Developers%20Guide.pdf), el evento OnGetCellColor está declarado así:
TGridColorEvent = procedure (Sender:TObject; ARow, ACol:Integer; AState:TGridDrawState;
ABrush:TBrush; AFont:TFont) of object;
Entonces creo que para asignarle tu propio procedimiento, bastaría con hacer algo similar a esto:
...
type
TForm1 = class(TForm)
AdvStringGrid1 : TAdvStringGrid;
procedure FormCreate(Sender: TObject);
...
private
procedure MyGetCell(Sender:TObject; ARow, ACol:Integer; AState:TGridDrawState; ABrush:TBrush; AFont:TFont);
...
public
...
end;
...
implementation
procedure TForm1.FormCreate(Sender: TObject);
begin
AdvStringGrid1.OnGetCellCol := MyGetCell;
end;
procedure TForm1.MyGetCell(Sender:TObject;ARow, ACol:Integer; AState:TGridDrawState; ABrush:TBrush; AFont:TFont);
var
sg: TAdvStringGrid;
begin
sg := AdvStringGrid1;
... // operaciones pertinentes
end;
...
Aunque, en base, sería lo mismo usar la declaración original...
Saludos :)
strelok
08-02-2018, 09:42:42
Hola.
Nunca he usado los componentes TMS, pero de acuerdo a esta guía, TMS TAdvStringGrid DEVELOPERS GUIDE (http://www.tmssoftware.biz/download/manuals/TMS%20TAdvStringGrid%20Developers%20Guide.pdf), el evento OnGetCellColor está declarado así:
TGridColorEvent = procedure (Sender:TObject; ARow, ACol:Integer; AState:TGridDrawState;
ABrush:TBrush; AFont:TFont) of object;
Entonces creo que para asignarle tu propio procedimiento, bastaría con hacer algo similar a esto:
...
type
TForm1 = class(TForm)
AdvStringGrid1 : TAdvStringGrid;
procedure FormCreate(Sender: TObject);
...
private
procedure MyGetCell(Sender:TObject; ARow, ACol:Integer; AState:TGridDrawState; ABrush:TBrush; AFont:TFont);
...
public
...
end;
...
implementation
procedure TForm1.FormCreate(Sender: TObject);
begin
AdvStringGrid1.OnGetCellCol := MyGetCell;
end;
procedure TForm1.MyGetCell(Sender:TObject;ARow, ACol:Integer; AState:TGridDrawState; ABrush:TBrush; AFont:TFont);
var
sg: TAdvStringGrid;
begin
sg := AdvStringGrid1;
... // operaciones pertinentes
end;
...
Aunque, en base, sería lo mismo usar la declaración original...
Saludos :)
Muchas gracias, ¿y para preguntar que no el método no se esté usando actualmente? ¿algo así? if (TComboBox(pComponente).OnEnter=nil) then
Neftali [Germán.Estévez]
08-02-2018, 16:19:39
Muchas gracias, ¿y para preguntar que no el método no se esté usando actualmente? ¿algo así? if (TComboBox(pComponente).OnEnter=nil) then
Aunque esté asiganado, siempre puedes "quedarte" con el puntero, asignar la tuya y luego desde la tuya llamar à la anterior que estaba asignada.
De esa forma podrías mantener amnbas.
vBulletin v3.6.8, Derechos ©2000-2024, Jelsoft Enterprises Ltd.