begin process at 2010 03 22 10:59:00
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Composants

 > COMPOSANT GRILLE AVEC NOUVELLES PROPRIÉTÉS

COMPOSANT GRILLE AVEC NOUVELLES PROPRIÉTÉS


 Information sur la source

Note :
Aucune note
Catégorie :Composants Classé sous :Ajustement-Automatique, Format-Numérique, Couleur-CelluleLigneColonne, Image-CelluleLigneColonne Niveau :Débutant Date de création :31/12/2008 Date de mise à jour :07/01/2009 21:55:25 Vu / téléchargé :1 837 / 307

Auteur : Paounet

Ecrire un message privé
Commentaire sur cette source (10)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
- Propriété About = Auteur-Concepteur.
-       Propriété Aide = Aide descriptif sur les Propriétés.
- Propriété AlignText : Formatte un texte dans les Cellules
- Propriété Automatic :  Ajuste automatiquement la Largeur et Hauteur de la Grille.
- Propriété FormatNumeric : Formatage à droite des cellules contenant des nombres.
- Propriété CellColor: CellCor :  Couleur pour la Cellule choisie. (ou ligne ou Colonne).
- Fonction Publiée : ChangeCellColor(Acol,ARow:Integer) - Couleur de Cellule.
- Propriété Picture : Image BitMap sélectionnée pour la fonction CellBitMap.
- Utilisation de la Fonction Publiée : CellBitMap(ACol,ARow:Integer).

Source

  • unit TGrille; // Composant Visuel Grille Hérité TStringGrid @ Guy Bidi 2008
  • interface
  • uses Windows,SysUtils,Classes,Controls,Grids,Types,Graphics,Forms,StdCtrls,
  • Dialogs,ShellApi;
  • Const Mess=' Propriété About : Auteur : © Guy Bidi - paounet@free.fr'+Chr(13)+Chr(13)+
  • ' 1 - La Propriété Aide à True affiche l''Aide actuelle.'+Chr(13)+Chr(13)+
  • ' 2 - La Propriété AlignText :'+Chr(13)+Chr(13)+
  • ' Left : Aligne à Gauche le texte des Cellules.'+Chr(13)+
  • ' Center : Aligne au Centre le texte des Cellules.'+Chr(13)+
  • ' Right : Aligne à Droite le texte des Cellules.'+Chr(13)+Chr(13)+
  • ' 3 - La Propriété Automatic : Ajuste la Largeur et Hauteur de la Grille (True ).'+Chr(13)+Chr(13)+
  • ' 4 - La Propriété FormatNumeric : '+Chr(13)+Chr(13)+
  • ' En utilisant les symbôles de formatage tels que #, 0, . les cellules contenant des'+Chr(13)+
  • ' nombres seront formatés à droite comme la fonction FormatFloat (''0.##'',Valeur).'+Chr(13)+Chr(13)+
  • ' 5 - La Propriété CellColor: CellCor : Couleur pour la Cellule choisie.'+Chr(13)+Chr(13)+
  • ' IndexCol : Index de Colonne / IndexRow : Index de Ligne.'+Chr(13)+
  • ' Si IndexRow/IndexCol est vide alors toute la colonne/Ligne sera affichée '+Chr(13)+
  • ' avec la couleur issue de CellColor.'+Chr(13)+Chr(13)+
  • ' 6- Utilisation de la Fonction Publiée : ChangeCellColor(Acol,ARow:Integer)'+Chr(13)+Chr(13)+
  • ' - Couleur de Cellule : CellColor.Color '+Chr(13)+Chr(13)+
  • ' 7 - La Propriété Picture : Image BitMap sélectionnée pour la fonction CellBitMap'+Chr(13)+Chr(13)+
  • ' 8- Utilisation de la Fonction Publique : CellBitMap(ACol,ARow:Integer)'+Chr(13)+Chr(13)+
  • ' Grille1.CellBitMap(-1,-1) Toute la Grille est dessinée'+Chr(13)+
  • ' Grille1.CellBitMap(2,3); La Cellule(2,3) est dessinée'+Chr(13)+
  • ' Grille1.CellBitMap(-1,2); Toute la Ligne N° 2 est dessinée'+Chr(13)+
  • ' Grille1.CellBitMap(2,-1); Toute la Colonne N° 2 est dessinée';
  • type
  • TCellColor = class(TPersistent) // Propriétés rajoutées à Grille
  • private { Déclarations privées } // Variables Utilisées
  • FColor:TColor;FCol:String;FRow:String; // Couleur, Colonne, Ligne
  • Procedure SetCol(Value:String);
  • Procedure SetRow(Value:String);
  • protected { Déclarations protégées }
  • public { Déclarations publiques }
  • Constructor Create(Owner:Tcomponent);
  • published { Déclarations publiées }
  • Property Color:TColor Read FColor Write FColor;
  • Property IndexCol:String Read FCol Write SetCol;
  • Property IndexRow:String Read FRow Write SEtRow;
  • end;
  • type
  • TAbout=String; // Propriété About rajoutée
  • TAide=Boolean; // Propriété Aide sur le Composant
  • TAlignText=(Left,Center,Right); // Propriété Alignement du Texte
  • TAuto=Boolean; // Ajuste la Grille Automatiquement
  • TFormat=String; // Propriété Format pour Numérique
  • Grille = class(TStringGrid)
  • private { Déclarations privées } // Variables Utilisées
  • FAbout:TAbout;FAide:TAide;FAlignText:TAlignText;Fauto:TAuto;FFormat:TFormat;
  • FCellColor:TCellColor;FormAide:TForm;Memo:TMemo;FBitMap:TBitMap;
  • protected { Déclarations protégées }
  • procedure DrawCell(ACol:Longint;ARow:Longint;Rectangle:TRect;State:TGridDrawState); override;
  • procedure MemoDblClick(Sender:TObject);
  • procedure SetBitMap(Value:TBitMap);
  • public { Déclarations publiques }
  • Constructor Create(Owner:Tcomponent);override;
  • destructor Destroy;Override;
  • published { Déclarations publiées }
  • Property About:TAbout read FAbout;
  • Property Aide:TAide read FAide Write FAide;
  • Property AlignText:TAlignText read FAlignText Write FAlignText;
  • Property Automatic:TAuto read FAuto Write FAuto;
  • Property FormatNumeric:TFormat Read FFormat Write FFormat;
  • Property CellColor:TCellColor Read FCellColor Write FCellColor;
  • Property CellPicture:TBitMap Read FBitMap Write SetBitMap;
  • Procedure ChangeColorCell(ACol,ARow:Integer);
  • Procedure CellBitMap(ACol,ARow:Integer);
  • end;
  • procedure Register;
  • implementation
  • Procedure Grille.MemoDblClick(Sender:TObject);
  • Begin
  • FormAide.ModalResult:=mrOk;
  • End;
  • Constructor TCellColor.Create(Owner:TComponent);
  • Begin
  • // Rien Ici
  • End;
  • procedure Grille.SetBitMap(Value:TBitMap);
  • begin
  • If Value<>Nil Then FBitMap.Assign(Value);
  • end;
  • Constructor Grille.Create(Owner:TComponent);
  • Begin
  • Inherited Create(Owner);FixedCols:=0;FixedRows:=0;FAbout:='© Guy Bidi - 2008';
  • Font.Name:= 'Comic Sans MS';ScrollBars:=ssNone;FAlignText:=Center;
  • FAuto:=True;FAide:=False;Font.Style:=[fsBold];FFormat:='';Color:=clMoneyGreen;
  • If Owner Is TForm Then With TForm(Owner)Do Position:=poScreenCenter;
  • FormAide:=TForm.CreateNew(Application);With FormAide Do Begin Left:=0;Top:=0;
  • AutoSize:=True;BorderIcons:=[];BorderStyle:=bsDialog;ClientHeight:=577;
  • Caption:='Les Nouvelles Propriétés du Composant Grille © Guy Bidi - 2008';
  • ClientWidth:=561;Color:=clBtnFace;Font.Charset:=DEFAULT_CHARSET;Font.Style:=[];
  • Font.Color:=clWindowText;Font.Height:=-13;Font.Name:='Century Gothic';
  • OldCreateOrder:=False;Position:=poScreenCenter;PixelsPerInch:=120;End;
  • Memo:=TMemo.Create(Owner);With Memo Do Begin Parent:=FormAide;Left:=0;Top:=0;
  • Width:=567;Height:=608;Hint:='Double-Cliquer pour sortir';Color:=clSkyBlue;
  • Font.Charset:=DEFAULT_CHARSET;Font.Color:=clBlack;Font.Height:=-13;
  • Font.Name:='Century Gothic';Font.Style:=[fsBold];ParentFont:=False;
  • ParentShowHint:=False;ShowHint:=True;Lines.Text:=Mess;
  • WantReturns:=True;OnDblClick:=MemoDblClick;End;
  • FCellColor:=TCellColor.Create(Self);With FCellColor Do Begin
  • FColor:=Color;FCol:='';FRow:='';End;
  • FBitMap:=TBitMap.Create;
  • End;
  • Procedure TCellColor.SetCol(Value:String);
  • Begin
  • If Not(Ord(Copy(Value,1,1))) In [49..59] Then Value:='';FCol:=Value;
  • End;
  • Procedure TCellColor.SetRow(Value:String);
  • Begin
  • If Not(Ord(Copy(Value,1,1))) In [49..59] Then Value:='';FRow:=Value;
  • End;
  • Procedure Grille.DrawCell(ACol,ARow:Integer;Rectangle:TRect;State:TGridDrawState);
  • Var Valeur:Real;Code,i,j:Integer;
  • Begin // Surchage OnDrawCell de la Grille
  • Val(Trim(Cells[ACol,ARow]),Valeur,Code);
  • If (FFormat<>'') And (Code=0) And (Trim(Cells[ACol,ARow])<>'') Then
  • DrawText(Canvas.Handle,PWideChar(FormatFloat(FFormat,Valeur)),
  • -1,Rectangle,DT_RIGHT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
  • Else
  • If FAlignText=Center then DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
  • -1,Rectangle,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
  • Else If FAlignText=Right then DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
  • -1,Rectangle,DT_RIGHT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
  • Else DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
  • -1,Rectangle,DT_LEFT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE);
  • If FAuto=True then Begin
  • Width:=ColCount*DefaultColWidth+(ColCount+1)*GridLineWidth;
  • Height:=RowCount*DefaultRowHeight+(RowCount+1)*GridLineWidth;End;
  • If FAide then Begin FAide:=False;FormAide.ShowModal;End;
  • If (FCellColor.FCol='') And (FCellColor.FRow='') Then Exit;
  • If (FCellColor.FCol<>'') And (FCellColor.FRow<>'') And
  • (StrToInt(FCellColor.FRow)<RowCount) And
  • (StrToInt(FCellColor.FCol)<ColCount) Then Begin
  • ChangeColorCell(StrToInt(FCellColor.Fcol),StrToInt(FCellColor.FRow));Exit;End;
  • If FCellColor.FCol='' Then Begin
  • If StrToInt(FCellColor.FRow)<RowCount Then Begin
  • For i := 0 to ColCount - 1 do For j := 0 to RowCount-1 do Begin
  • ChangeColorCell(i,StrToInt(FCellColor.FRow));End;Exit;End
  • Else Begin MessageDlg('Valeur de Ligne trop grande',mtInformation,[mbOk],0,mbOk);
  • FCellColor.FRow:='';Exit;End;End
  • Else If FCellColor.FRow='' Then Begin
  • If StrToInt(FCellColor.FCol)<ColCount Then Begin
  • For i := 0 to ColCount - 1 do For j := 0 to RowCount-1 do Begin
  • ChangeColorCell(StrToInt(FCellColor.FCol),j);End;Exit; End
  • Else Begin MessageDlg('Valeur de Colonne trop grande',mtInformation,[mbOk],0,mbOk);
  • FCellColor.FCol:='';Exit;End;End;
  • FBitMap:=TBitMap.Create;FBitMap:=Nil;
  • End;
  • Procedure Grille.CellBitMap(ACol,ARow:Integer); // Procedure Publique CellBitMap
  • Var Rect,Rect1:TRect;
  • Begin
  • If ACol<0 Then // Pas de Colonne
  • If ARow<0 Then Begin // Toute la Grille est dessinée...
  • Rect:=BoundsRect;Rect.Right:=Rect.Right-Rect.Left;
  • Rect.Bottom:=Rect.Bottom-Rect.Top;Rect.Left:=0;Rect.Top:=0;End
  • Else // Toute une Colonne est dessinée
  • If ARow>RowCount-1 Then Begin MessageDlg('Valeur de Ligne trop grande',
  • mtInformation,[mbOk],0,mbOk);Exit;End
  • Else Begin // Toute une Ligne est dessinée
  • Rect:=CellRect(0,ARow);Rect1:=CellRect(ColCount-1,ARow);
  • Rect.Right:=Rect1.Right;Rect.Bottom:=Rect1.Bottom;End
  • Else If ARow<0 then
  • If ACol>ColCount-1 Then Begin MessageDlg('Valeur de Ligne erronée',
  • mtInformation,[mbOk],0,mbOk);Exit;End
  • Else Begin // Toute une Colonne est dessinée
  • Rect:=CellRect(ACol,0);Rect1:=CellRect(ACol,RowCount-1);
  • Rect.Right:=Rect1.Right;Rect.Bottom:=Rect1.Bottom;End
  • Else If (ACol>ColCount-1) Or (ARow>RowCount-1) Then Begin
  • MessageDlg('Valeur de Colonne/Ligne erronée',mtInformation,[mbOk],0,mbOk);
  • Exit;End Else Rect:=CellRect(ACol,ARow); // Une seule Cellule est dessinée
  • Canvas.StretchDraw(Rect,CellPicture); // Affiche le dessin dans Cellule(s)
  • End;
  • Procedure Grille.ChangeColorCell(ACol,ARow:Integer); // Changement de Couleur/Cellule
  • Var Valeur:Real;Code:Integer;Rectangle:TRect;
  • Begin
  • Canvas.Brush.Color:=FCellColor.FColor;
  • Rectangle:=CellRect(ACol,ARow);
  • Canvas.TextRect(Rectangle,Rectangle.Left,Rectangle.Top,'');
  • If Cells[ACol,ARow]<>'' then Begin
  • Val(Trim(Cells[ACol,ARow]),Valeur,Code);
  • If (FFormat<>'') And (Code=0) And (Trim(Cells[ACol,ARow])<>'') Then
  • DrawText(Canvas.Handle,PWideChar(FormatFloat(FFormat,Valeur)),
  • -1,Rectangle,DT_RIGHT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
  • Else
  • If FAlignText=Center then DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
  • -1,Rectangle,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
  • Else If FAlignText=Right then DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
  • -1,Rectangle,DT_RIGHT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
  • Else DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
  • -1,Rectangle,DT_LEFT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE);
  • End;
  • end;
  • destructor Grille.Destroy; // Destruction du Composant
  • begin
  • inherited Destroy;
  • end;
  • procedure Register; // Enregistre le Composant Grille
  • begin
  • RegisterComponents('Guy Bidi',[Grille]);
  • end;
  • end.
  • Test du Composant Grille = Fichier TTest.pas (Test.dproj)
  • unit TTest;
  • interface
  • uses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
  • Dialogs,Grids,TGrille,StdCtrls,Buttons,Types;
  • type
  • TFormGrille = class(TForm)Cellules:TSpeedButton;
  • CellBitMapT: TSpeedButton;
  • CellBitMapC: TSpeedButton;
  • CellBitMapCol: TSpeedButton;
  • CellBitMapRow: TSpeedButton;
  • Grille1: Grille;
  • procedure FormShow(Sender:TObject);
  • procedure CellulesClick(Sender:TObject);
  • procedure CellBitMapClick(Sender:TObject);
  • end;
  • var FormGrille:TFormGrille;Flag:Boolean;Ori:TColor;
  • implementation
  • {$R *.dfm}
  • procedure TFormGrille.CellBitMapClick(Sender:TObject);
  • begin
  • case TSpeedButton(Sender).Tag of
  • 0:Grille1.CellBitMap(-1,-1);
  • 1:Grille1.CellBitMap(2,3); // Cellule 2,3
  • 2:Grille1.CellBitMap(3,-1); // Colonne N° 3
  • 3:Grille1.CellBitMap(-1,2); // Ligne N° 2
  • end;
  • end;
  • procedure TFormGrille.CellulesClick(Sender:TObject);
  • Var i:Integer;
  • begin
  • With Grille1 Do Begin If Flag then CellColor.Color:=Color Else
  • CellColor.Color:=Ori;Flag:=Not(Flag);
  • For i:= 0 to 4 do ChangeColorCell(i,i);End;
  • end;
  • procedure TFormGrille.FormShow(Sender:TObject);
  • begin
  • Flag:=False;With Grille1 Do Begin Ori:=Grille1.CellColor.Color;
  • Cells[0,0]:='12345.34';Cells[1,1]:='12.55';Cells[2,2]:='0.75';
  • Cells[3,3]:='Guy Bidi';End;
  • end;
  • end.
unit TGrille;     // Composant Visuel Grille Hérité TStringGrid @ Guy Bidi 2008
interface
uses Windows,SysUtils,Classes,Controls,Grids,Types,Graphics,Forms,StdCtrls,
     Dialogs,ShellApi;
 Const Mess='  Propriété About : Auteur : © Guy Bidi - paounet@free.fr'+Chr(13)+Chr(13)+
      ' 1 - La Propriété Aide à True affiche l''Aide actuelle.'+Chr(13)+Chr(13)+
      ' 2 - La Propriété AlignText :'+Chr(13)+Chr(13)+
      '      Left       :   Aligne à Gauche le texte des  Cellules.'+Chr(13)+
      '      Center  :   Aligne au Centre le texte des Cellules.'+Chr(13)+
      '      Right    :   Aligne à Droite    le texte des Cellules.'+Chr(13)+Chr(13)+
      ' 3 - La Propriété Automatic :  Ajuste la Largeur et Hauteur de la Grille (True ).'+Chr(13)+Chr(13)+
      ' 4 - La Propriété FormatNumeric : '+Chr(13)+Chr(13)+
      '      En utilisant les symbôles de formatage tels que #, 0, . les cellules contenant des'+Chr(13)+
      '      nombres seront formatés à droite comme la fonction FormatFloat (''0.##'',Valeur).'+Chr(13)+Chr(13)+
      ' 5 - La Propriété CellColor: CellCor :  Couleur pour la Cellule choisie.'+Chr(13)+Chr(13)+
      '      IndexCol   : Index de Colonne   /   IndexRow : Index de Ligne.'+Chr(13)+
      '      Si IndexRow/IndexCol est vide alors toute la colonne/Ligne sera affichée '+Chr(13)+
      '      avec la couleur issue de CellColor.'+Chr(13)+Chr(13)+
      ' 6- Utilisation de la Fonction Publiée : ChangeCellColor(Acol,ARow:Integer)'+Chr(13)+Chr(13)+
      '       - Couleur de Cellule : CellColor.Color '+Chr(13)+Chr(13)+
      ' 7 - La Propriété Picture : Image BitMap sélectionnée pour la fonction CellBitMap'+Chr(13)+Chr(13)+
      ' 8- Utilisation de la Fonction Publique : CellBitMap(ACol,ARow:Integer)'+Chr(13)+Chr(13)+
      '          Grille1.CellBitMap(-1,-1) Toute la Grille est dessinée'+Chr(13)+
      '          Grille1.CellBitMap(2,3);   La Cellule(2,3) est dessinée'+Chr(13)+
      '          Grille1.CellBitMap(-1,2);  Toute la Ligne N° 2 est dessinée'+Chr(13)+
      '          Grille1.CellBitMap(2,-1);  Toute la Colonne N° 2 est dessinée';
type
  TCellColor = class(TPersistent)                     // Propriétés rajoutées à Grille
  private             { Déclarations privées }        // Variables Utilisées
  FColor:TColor;FCol:String;FRow:String;              // Couleur, Colonne, Ligne
  Procedure SetCol(Value:String);
  Procedure SetRow(Value:String);
  protected           { Déclarations protégées }
  public              { Déclarations publiques }
    Constructor Create(Owner:Tcomponent);
  published           { Déclarations publiées }
    Property Color:TColor Read FColor Write FColor;
    Property IndexCol:String Read FCol Write SetCol;
    Property IndexRow:String Read FRow Write SEtRow;
end;
type
  TAbout=String;                            // Propriété About rajoutée
  TAide=Boolean;                            // Propriété Aide sur le Composant
  TAlignText=(Left,Center,Right);           // Propriété Alignement du Texte
  TAuto=Boolean;                            // Ajuste la Grille Automatiquement
  TFormat=String;                           // Propriété Format pour Numérique
  Grille = class(TStringGrid)
  private             { Déclarations privées }        // Variables Utilisées
    FAbout:TAbout;FAide:TAide;FAlignText:TAlignText;Fauto:TAuto;FFormat:TFormat;
    FCellColor:TCellColor;FormAide:TForm;Memo:TMemo;FBitMap:TBitMap;
  protected           { Déclarations protégées }
   procedure DrawCell(ACol:Longint;ARow:Longint;Rectangle:TRect;State:TGridDrawState); override;
   procedure MemoDblClick(Sender:TObject);
   procedure SetBitMap(Value:TBitMap);
  public              { Déclarations publiques }
    Constructor Create(Owner:Tcomponent);override;
    destructor Destroy;Override;
  published           { Déclarations publiées }
    Property About:TAbout read FAbout;
    Property Aide:TAide read FAide Write FAide;
    Property AlignText:TAlignText read FAlignText Write FAlignText;
    Property Automatic:TAuto read FAuto Write FAuto;
    Property FormatNumeric:TFormat Read FFormat Write FFormat;
    Property CellColor:TCellColor Read FCellColor Write FCellColor;
    Property CellPicture:TBitMap Read FBitMap Write SetBitMap;
    Procedure ChangeColorCell(ACol,ARow:Integer);
    Procedure CellBitMap(ACol,ARow:Integer);
end;
procedure Register;
implementation
Procedure Grille.MemoDblClick(Sender:TObject);
Begin
  FormAide.ModalResult:=mrOk;
End;
Constructor TCellColor.Create(Owner:TComponent);
Begin
    // Rien Ici
End;
procedure Grille.SetBitMap(Value:TBitMap);
begin
  If Value<>Nil Then FBitMap.Assign(Value);
end;
Constructor Grille.Create(Owner:TComponent);
Begin
  Inherited Create(Owner);FixedCols:=0;FixedRows:=0;FAbout:='© Guy Bidi - 2008';
  Font.Name:= 'Comic Sans MS';ScrollBars:=ssNone;FAlignText:=Center;
  FAuto:=True;FAide:=False;Font.Style:=[fsBold];FFormat:='';Color:=clMoneyGreen;
  If Owner Is TForm Then With TForm(Owner)Do Position:=poScreenCenter;
  FormAide:=TForm.CreateNew(Application);With FormAide Do Begin Left:=0;Top:=0;
  AutoSize:=True;BorderIcons:=[];BorderStyle:=bsDialog;ClientHeight:=577;
  Caption:='Les Nouvelles Propriétés du Composant Grille © Guy Bidi - 2008';
  ClientWidth:=561;Color:=clBtnFace;Font.Charset:=DEFAULT_CHARSET;Font.Style:=[];
  Font.Color:=clWindowText;Font.Height:=-13;Font.Name:='Century Gothic';
  OldCreateOrder:=False;Position:=poScreenCenter;PixelsPerInch:=120;End;
  Memo:=TMemo.Create(Owner);With Memo Do Begin Parent:=FormAide;Left:=0;Top:=0;
  Width:=567;Height:=608;Hint:='Double-Cliquer pour sortir';Color:=clSkyBlue;
  Font.Charset:=DEFAULT_CHARSET;Font.Color:=clBlack;Font.Height:=-13;
  Font.Name:='Century Gothic';Font.Style:=[fsBold];ParentFont:=False;
  ParentShowHint:=False;ShowHint:=True;Lines.Text:=Mess;
  WantReturns:=True;OnDblClick:=MemoDblClick;End;
  FCellColor:=TCellColor.Create(Self);With FCellColor Do Begin
    FColor:=Color;FCol:='';FRow:='';End;
  FBitMap:=TBitMap.Create;
End;
Procedure TCellColor.SetCol(Value:String);
Begin
  If Not(Ord(Copy(Value,1,1))) In [49..59] Then Value:='';FCol:=Value;
End;
Procedure TCellColor.SetRow(Value:String);
Begin
  If Not(Ord(Copy(Value,1,1))) In [49..59] Then Value:='';FRow:=Value;
End;
Procedure Grille.DrawCell(ACol,ARow:Integer;Rectangle:TRect;State:TGridDrawState);
Var Valeur:Real;Code,i,j:Integer;
Begin                            // Surchage OnDrawCell de la Grille
  Val(Trim(Cells[ACol,ARow]),Valeur,Code);
  If (FFormat<>'') And (Code=0) And (Trim(Cells[ACol,ARow])<>'') Then
      DrawText(Canvas.Handle,PWideChar(FormatFloat(FFormat,Valeur)),
      -1,Rectangle,DT_RIGHT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
   Else
      If FAlignText=Center then DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
      -1,Rectangle,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
      Else If FAlignText=Right then DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
      -1,Rectangle,DT_RIGHT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
      Else DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
      -1,Rectangle,DT_LEFT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE);
  If FAuto=True then Begin
    Width:=ColCount*DefaultColWidth+(ColCount+1)*GridLineWidth;
    Height:=RowCount*DefaultRowHeight+(RowCount+1)*GridLineWidth;End;
  If FAide then Begin FAide:=False;FormAide.ShowModal;End;
  If (FCellColor.FCol='') And (FCellColor.FRow='') Then Exit;
  If (FCellColor.FCol<>'') And (FCellColor.FRow<>'') And
    (StrToInt(FCellColor.FRow)<RowCount) And
    (StrToInt(FCellColor.FCol)<ColCount) Then Begin
    ChangeColorCell(StrToInt(FCellColor.Fcol),StrToInt(FCellColor.FRow));Exit;End;
  If FCellColor.FCol='' Then Begin
    If StrToInt(FCellColor.FRow)<RowCount Then Begin
      For i := 0 to ColCount - 1 do For j := 0 to RowCount-1 do Begin
        ChangeColorCell(i,StrToInt(FCellColor.FRow));End;Exit;End
    Else Begin MessageDlg('Valeur de Ligne trop grande',mtInformation,[mbOk],0,mbOk);
      FCellColor.FRow:='';Exit;End;End
  Else If FCellColor.FRow='' Then Begin
      If StrToInt(FCellColor.FCol)<ColCount Then Begin
        For i := 0 to ColCount - 1 do For j := 0 to RowCount-1 do Begin
          ChangeColorCell(StrToInt(FCellColor.FCol),j);End;Exit; End
      Else Begin MessageDlg('Valeur de Colonne trop grande',mtInformation,[mbOk],0,mbOk);
        FCellColor.FCol:='';Exit;End;End;
  FBitMap:=TBitMap.Create;FBitMap:=Nil;
End;
Procedure Grille.CellBitMap(ACol,ARow:Integer); // Procedure Publique CellBitMap
Var Rect,Rect1:TRect;
Begin
  If ACol<0 Then                            // Pas de Colonne
    If ARow<0 Then Begin                    // Toute la Grille est dessinée...
      Rect:=BoundsRect;Rect.Right:=Rect.Right-Rect.Left;
      Rect.Bottom:=Rect.Bottom-Rect.Top;Rect.Left:=0;Rect.Top:=0;End
    Else                                   // Toute une Colonne est dessinée
      If ARow>RowCount-1 Then Begin MessageDlg('Valeur de Ligne trop grande',
        mtInformation,[mbOk],0,mbOk);Exit;End
      Else Begin                           // Toute une Ligne est dessinée
        Rect:=CellRect(0,ARow);Rect1:=CellRect(ColCount-1,ARow);
        Rect.Right:=Rect1.Right;Rect.Bottom:=Rect1.Bottom;End
  Else If ARow<0 then
    If ACol>ColCount-1 Then Begin MessageDlg('Valeur de Ligne erronée',
      mtInformation,[mbOk],0,mbOk);Exit;End
    Else Begin                             // Toute une Colonne est dessinée
      Rect:=CellRect(ACol,0);Rect1:=CellRect(ACol,RowCount-1);
      Rect.Right:=Rect1.Right;Rect.Bottom:=Rect1.Bottom;End
  Else If (ACol>ColCount-1) Or (ARow>RowCount-1) Then Begin
    MessageDlg('Valeur de Colonne/Ligne erronée',mtInformation,[mbOk],0,mbOk);
  Exit;End Else Rect:=CellRect(ACol,ARow); // Une seule Cellule est dessinée
  Canvas.StretchDraw(Rect,CellPicture);    // Affiche le dessin dans Cellule(s)
End;
Procedure Grille.ChangeColorCell(ACol,ARow:Integer); // Changement de Couleur/Cellule
Var Valeur:Real;Code:Integer;Rectangle:TRect;
Begin
  Canvas.Brush.Color:=FCellColor.FColor;
  Rectangle:=CellRect(ACol,ARow);
  Canvas.TextRect(Rectangle,Rectangle.Left,Rectangle.Top,'');
  If Cells[ACol,ARow]<>'' then Begin
    Val(Trim(Cells[ACol,ARow]),Valeur,Code);
  If (FFormat<>'') And (Code=0) And (Trim(Cells[ACol,ARow])<>'') Then
      DrawText(Canvas.Handle,PWideChar(FormatFloat(FFormat,Valeur)),
      -1,Rectangle,DT_RIGHT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
   Else
      If FAlignText=Center then DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
      -1,Rectangle,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
      Else If FAlignText=Right then DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
      -1,Rectangle,DT_RIGHT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
      Else DrawText(Canvas.Handle,PWideChar(Cells[ACol,ARow]),
      -1,Rectangle,DT_LEFT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE);
  End;
end;
destructor Grille.Destroy;             // Destruction du Composant
begin
  inherited Destroy;
end;
procedure Register;                   // Enregistre le Composant Grille
begin
  RegisterComponents('Guy Bidi',[Grille]);
end;
end.

Test du Composant Grille = Fichier TTest.pas (Test.dproj)
unit TTest;
interface
uses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
     Dialogs,Grids,TGrille,StdCtrls,Buttons,Types;
type
  TFormGrille = class(TForm)Cellules:TSpeedButton;
    CellBitMapT: TSpeedButton;          
    CellBitMapC: TSpeedButton;
    CellBitMapCol: TSpeedButton;
    CellBitMapRow: TSpeedButton;
    Grille1: Grille;
    procedure FormShow(Sender:TObject);
    procedure CellulesClick(Sender:TObject);
    procedure CellBitMapClick(Sender:TObject);
  end;
var FormGrille:TFormGrille;Flag:Boolean;Ori:TColor;
implementation
{$R *.dfm}
procedure TFormGrille.CellBitMapClick(Sender:TObject);
begin
  case TSpeedButton(Sender).Tag of
    0:Grille1.CellBitMap(-1,-1);
    1:Grille1.CellBitMap(2,3);     // Cellule 2,3
    2:Grille1.CellBitMap(3,-1);    // Colonne N° 3
    3:Grille1.CellBitMap(-1,2);    // Ligne N° 2
  end;
end;
procedure TFormGrille.CellulesClick(Sender:TObject);
Var i:Integer;
begin
  With Grille1 Do Begin If Flag then CellColor.Color:=Color Else
    CellColor.Color:=Ori;Flag:=Not(Flag);
  For i:= 0 to 4 do ChangeColorCell(i,i);End;
end;
procedure TFormGrille.FormShow(Sender:TObject);
begin
    Flag:=False;With Grille1 Do Begin Ori:=Grille1.CellColor.Color;
    Cells[0,0]:='12345.34';Cells[1,1]:='12.55';Cells[2,2]:='0.75';
    Cells[3,3]:='Guy Bidi';End;
end;
end.


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  • Grille.dcuTélécharger ce fichier [Réservé aux membres club]2 257 octets
  • Grille.dpkTélécharger ce fichier [Réservé aux membres club]560 octets
  • Grille.dprojTélécharger ce fichier [Réservé aux membres club]9 977 octets
  • Grille.dproj.localTélécharger ce fichier [Réservé aux membres club]508 octets
  • Grille.identcacheTélécharger ce fichier [Réservé aux membres club]47 octets
  • Grille.resTélécharger ce fichier [Réservé aux membres club]8 636 octets
  • Help.dproj.localTélécharger ce fichier [Réservé aux membres club]1 239 octets
  • Help.icoTélécharger ce fichier [Réservé aux membres club]Voir ce fichier4 286 octets
  • Help.identcacheTélécharger ce fichier [Réservé aux membres club]76 octets
  • Test.dcuTélécharger ce fichier [Réservé aux membres club]4 155 octets
  • Test.dfmTélécharger ce fichier [Réservé aux membres club]463 octets
  • Test.dprTélécharger ce fichier [Réservé aux membres club]Voir ce fichier241 octets
  • Test.dprojTélécharger ce fichier [Réservé aux membres club]5 205 octets
  • Test.dproj.localTélécharger ce fichier [Réservé aux membres club]514 octets
  • Test.icoTélécharger ce fichier [Réservé aux membres club]Voir ce fichier2 462 octets
  • Test.identcacheTélécharger ce fichier [Réservé aux membres club]85 octets
  • Test.resTélécharger ce fichier [Réservé aux membres club]8 540 octets
  • Tgrille.bmpTélécharger ce fichier [Réservé aux membres club]Voir ce fichier1 334 octets
  • Tgrille.dcrTélécharger ce fichier [Réservé aux membres club]1 716 octets
  • Tgrille.dcuTélécharger ce fichier [Réservé aux membres club]19 577 octets
  • TGrille.pasTélécharger ce fichier [Réservé aux membres club]Voir ce fichier11 321 octets
  • Tgrille.pas.oriTélécharger ce fichier [Réservé aux membres club]7 478 octets
  • Ttest.dcuTélécharger ce fichier [Réservé aux membres club]5 693 octets
  • Ttest.dfmTélécharger ce fichier [Réservé aux membres club]16 943 octets
  • Ttest.pasTélécharger ce fichier [Réservé aux membres club]Voir ce fichier1 363 octets

Télécharger le zip


 Historique

02 janvier 2009 19:58:19 :
Fichier Ttest.pas fourni pour tester le compo GRILLE
05 janvier 2009 19:13:53 :
Rajout des codes *.pas du programme Test.exe.. Composant fait avec Delphi 2009... mais ce code doit fonctionner avec Delphi 7 et+

 Sources du même auteur

Source avec Zip Source avec une capture COMPOSANT LABEL3D TOUTE VERSION DE DELPHI.
Source avec Zip CODES-SOURCES DU TUTORIEL PASSWORD ET GET PASSORD
Source avec Zip Source avec une capture LES CODES DU TUTORIEL SUR LA PROTECTION DES LOGICIELS PAR FI...
Source avec Zip Source avec une capture COMPOSANT TPASSWORD COMPOSITE GÉNÉRANT UN MOT DE PASSE ET UN...
Source avec Zip TSPEEDBUTTON TYPE VA-ET-VIENT

 Sources de la même categorie

Source avec Zip COMPOSANT THORLOGE par Michel34
Source avec Zip COMMANDS MANAGER - BESOIN DE COMMANDES DANS VOS PROGRAMMES T... par f0xi
Source avec Zip Source avec une capture COMPOSANT TZSIMAGE par ThWilliam
Source avec Zip Source avec une capture UTILISER LES COMPOSANTS PAR LEURS NUMÉROS par Dany3
Source avec Zip Source avec une capture TQGRID UN STRINGGRID AMÉLIORER. par yanb

Commentaires et avis

Commentaire de offlake le 31/12/2008 23:41:44

Bon Code!!
BY OFFLAKE

Commentaire de Forman le 01/01/2009 13:35:45

Salut,

pourrais-tu remplacer les *.dcu par des *.pas?
Merci d'avance et bonne année.

Commentaire de Delphiprog le 04/01/2009 09:03:55 administrateur CS

Peut-être est-ce un bon code mais :
- tu ne respectes aucune convention d'écriture dans la manière de nommer tes composants et/ou classes.
- le code est tassé au point de devenir illisible et incompréhensible pour un humain
- certaines déclarations n'ont rien à faire dans la partie Interface de l'unité (const Mess)
- A quoi servent la déclaration et l'implémentation de "Constructor TCellColor.Create(Owner:TComponent);" si tu ne mets aucun code dedans ?
- Idem pour le destructeur suivant :
destructor Grille.Destroy; // Destruction du Composant
begin
inherited Destroy;
end;
Ce code ne sert à rien en l'état.

Globalement, le concept est intéressant mais le travail ne semble pas vraiment fini et soigné.

Commentaire de yvessimon le 05/01/2009 14:12:36

Bonjour,


Impossible d'ouvrir le fichier

Ttest.pas"   Le fichier spécifié est introuvable.

Est-il possible d'avoir un exemple qui fonctionne ?

Merci

Commentaire de Michel34 le 05/01/2009 16:08:11

Salut a toutes et tous , et j'en profite pour presenter mes meilleures voeux a toute la communaute du site.

he bien impossible d'executer le test , manque le fichier  .PAS.
et impossible de mettre en place le TGrille.BPL , dans quelle version de Delphi a t'il ete creé , j'ai D7 pro.
A+ et bonne programmation.

Commentaire de AhPuch le 06/01/2009 11:44:12

Bonjour et meilleurs voeux à tous.

Je suis sur D7 pro et beaucoup d'erreurs de compilations ex

[Erreur] TGrille.pas(107): Types incompatibles
[Erreur] TGrille.pas(111): Types incompatibles
[Avertissement] TGrille.pas(118): Transtypage ambigu de String en PWideChar
[Avertissement] TGrille.pas(121): Transtypage ambigu de String en PWideChar
[Avertissement] TGrille.pas(123): Transtypage ambigu de String en PWideChar
[Avertissement] TGrille.pas(125): Transtypage ambigu de String en PWideChar
[Erreur] TGrille.pas(140): Trop de paramètres originaux
[Erreur] TGrille.pas(146): Trop de paramètres originaux
[Erreur] TGrille.pas(159): Trop de paramètres originaux
[Erreur] TGrille.pas(165): Trop de paramètres originaux
[Erreur] TGrille.pas(170): Trop de paramètres originaux
[Avertissement] TGrille.pas(183): Transtypage ambigu de String en PWideChar
[Avertissement] TGrille.pas(186): Transtypage ambigu de String en PWideChar
[Avertissement] TGrille.pas(188): Transtypage ambigu de String en PWideChar
[Avertissement] TGrille.pas(190): Transtypage ambigu de String en PWideChar
[Erreur fatale] Ttest.pas(4): Impossible de compiler l'unité utilisée 'TGrille.pas'

Genre
Procedure TCellColor.SetCol(Value:String);
Begin
  If Not(Ord(Copy(Value,1,1))) In [49..59] Then Value:='';FCol:=Value;
End;
Ord demande un numerique...

Commentaire de Paounet le 06/01/2009 13:49:37

POUR DELPHI 7 :

If Not(Ord(Copy(Value,1,1))) In [49..59] Then Value:='';FCol:=Value; peut être remplacé par :
If Ord(Copy(Value,1,1)) In [49..59] Then FCol:=Value Else FCol:='';  ou
If Copy(Value,1,1) In ['0'..'9'] Then FCol:=Value Else FCol:='';  
------------------------------------------------------------------------
PWideChar = essayer PChar... PAnsiChar
------------------------------------------------------------------------
Pour MessageDlg remplacez le par la fonction MessageBox ou remplacer dans Uses
Dialogs par QDialogs

Commentaire de AhPuch le 07/01/2009 11:17:42

Bonjour,

Pourquoi Grille et pas TGrille ?

Commentaire de Paounet le 07/01/2009 13:14:26

Pourquoi Grille et pas TGrille ? = parce que le composant s'appelle Grille..
Voir --> Grille = class(TStringGrid)etc...

Commentaire de cirec le 07/01/2009 21:54:14 administrateur CS

@Paounet:

le fait d'avoir choisi de nommer le composant "Grille" à la place de "TGrille" est une grossière erreur de débutant !!!!!

les déclarations de Type commencent toujours par un "T" sauf exception (Ex "I" pour les Interfaces)

on ne met qu'une seule instruction par ligne

L'écriture de code n'est pas quelque chose de libre
il y a des conventions qu'il faut respecter autant que possible ce qui permet à toute la communauté de lire et comprendre le code avec plus de facilité.

http://www.delphifr.com/tutoriaux/CONVENTIONS_413.aspx

regarde ce tutoriel et reprend le code en suivant les conseils de DelphiProg et des autres avant de voir plus loin.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,499 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales