1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| unit Panel1;
interface
uses
SysUtils, Classes, Controls, ExtCtrls, StdCtrls, Grids;
type
TPanelGrid = class(TPanel)
private
FGrid: TStringGrid;
FLabel: TLabel;
{ Déclarations privées }
protected
{ Déclarations protégées }
procedure OnSelectCellHandler(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
public
{ Déclarations publiques }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Déclarations publiées }
property MonLabel :TLabel read FLabel;
property MaGrille :TStringGrid read FGrid;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('TestsDvp', [TPanelGrid]);
end;
{ TPanelGrid }
constructor TPanelGrid.Create(AOwner: TComponent);
begin
inherited;
//creation des composants et parametrage des composants
FLabel := TLabel.Create(self);
FLabel.Parent := self;
FLabel.Align := alTop;
FGrid := TStringGrid.Create(self);
FGrid.Parent := self;
FGrid.Align := alClient;
FGrid.OnSelectCell := OnSelectCellHandler;
FGrid.Options := FGrid.Options + [goEditing, goAlwaysShowEditor];
end;
destructor TPanelGrid.Destroy;
begin
//detruire les composants crees
//facultatif car notre composant est leur owner...
FGrid.Free();
FLabel.Free();
inherited;
end;
procedure TPanelGrid.OnSelectCellHandler(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
//ecrire le texte de la cellule dans le label
FLabel.Caption := FGrid.Cells[ACol, ARow];
end;
end. |
Partager