Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Asignar una función dinámicamente (https://www.clubdelphi.com/foros/showthread.php?t=92803)

strelok 07-02-2018 17:14:19

Asignar una función dinámicamente
 
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, el evento OnGetCellColor está declarado así:
Código Delphi [-]
 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:
Código Delphi [-]
...

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

Cita:

Empezado por ecfisa (Mensaje 524421)
Hola.

Nunca he usado los componentes TMS, pero de acuerdo a esta guía, TMS TAdvStringGrid DEVELOPERS GUIDE, el evento OnGetCellColor está declarado así:
Código Delphi [-]
 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:
Código Delphi [-]
...

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í?
Código:

if (TComboBox(pComponente).OnEnter=nil) then

Neftali [Germán.Estévez] 08-02-2018 16:19:39

Cita:

Empezado por strelok (Mensaje 524439)
Muchas gracias, ¿y para preguntar que no el método no se esté usando actualmente? ¿algo así?
Código:

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.


La franja horaria es GMT +2. Ahora son las 05:22:37.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi