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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
| unit TypLiv;
//-------------------------------------------------------------------------------
interface
//-------------------------------------------------------------------------------
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons, phcunit;
//-------------------------------------------------------------------------------
type TFrmTypLiv=class(TForm)
BtnModTypLiv: TButton;
BtnSupTypLiv: TButton;
BtnRetFrmTypLiv: TSpeedButton;
BtnFinTypLiv: TSpeedButton;
BtnEntTypLiv: TButton;
BtnOuvTypLiv: TBitBtn;
CbTypLiv: TComboBox;
BtnCpyTypLiv: TSpeedButton;
SavTypLiv: TSpeedButton;
PnlTypLivLigEta: TPanel;
LblTitreFrmTypLiv: TLabel;
procedure FormCreate(Sender: TObject);
procedure BtnOuvTypLivClick(Sender: TObject);
procedure CbColorItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure BtnCpyTypLivClick(Sender: TObject);
procedure BtnRetTypLivClick(Sender: TObject);
procedure BtnFinTypLivClick(Sender: TObject);
procedure SavTypLivClick(Sender: TObject);
procedure CbTypLivChange(Sender: TObject);
procedure BtnSupTypLivClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
procedure BtnModTypLivClick(Sender: TObject);procedure BtnEntTypLivClick(Sender: TObject);
procedure CbTypLivEnter(Sender: TObject);
procedure FormShow(Sender: TObject);
//-------------------------------------------------------------------------------
private { Déclarations privées }
//-------------------------------------------------------------------------------
public end; { Déclarations publiques }
//-------------------------------------------------------------------------------
var FrmTypLiv: TFrmTypLiv;
//-------------------------------------------------------------------------------
implementation {$R *.dfm}
//-------------------------------------------------------------------------------
procedure TFrmTypLiv.FormCreate(Sender: TObject);
var HandleMenu : THandle;
begin HandleMenu := GetSystemMenu(Handle, False); //récupération du Handle du menu
EnableMenuItem(HandleMenu, SC_CLOSE, MF_DISABLED); // mise à Disabled croix de fermeture
BtnOuvTypLivClick(self);end;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.BtnOuvTypLivClick(Sender: TObject); {Ouvrir fichier des Types de livres}
Var F : textfile; Txt, CheminFichier, NomFichier, ExtFichier, NFichPhys:string;
begin {1} //Affectation des variables
txt:=''; CheminFichier:=ExtractFilePath(Application.ExeName); ExtFichier:='txt';
NomFichier:='TomTypLiv01';
NFichPhys:=CheminFichier+NomFichier+'.'+ExtFichier;
AssignFile(F,NFichPhys); {$I-} //La vérification d'E/S est désactivée
Reset(F); {$I+} //La vérification d'E/S est activée
if {if1} IoResult=0
then //Renvoie l'état de la dernière opération d'E/S
begin{2}CbTypLiv.items.Clear;CbTypLiv.Items.LoadFromFile(NFichPhys);CloseFile(F);
PnlTypLivLigEta.Caption := 'Fichier "Type Livre" chargé ou re-chargé dans la boîte déroulante !';end {2}
else begin {3}
Txt:='Fichier'+#13#10+NomFichier+#13#10+' non présent ou endommagé '+#13#10; Txt:=Txt+'Restaurez le fichier'+#13#10;
ShowMessage(txt);rewrite(F);Exit;end;{3}
end;{1}
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.CbColorItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin //on dessine le fond des lignes en alternant les couleurs
if index mod 2<>1 then begin CbTypLiv.canvas.brush.color:=clCaptionText; CbTypLiv.canvas.fillrect(rect);end
else begin CbTypLiv.canvas.brush.color:=clinactivecaptiontext;CbTypLiv.canvas.fillrect(rect);end;
{on affiche le texte}CbTypLiv.canvas.textout(rect.left+30,rect.top+2,CbTypLiv.items[index]);
if (odSelected in state) then begin CbTypLiv.canvas.brush.color:=clsilver;CbTypLiv.canvas.fillrect(rect);
CbTypLiv.canvas.font.color:=clred;
CbTypLiv.canvas.font.style:=CbTypLiv.canvas.font.style +[fsbold];
CbTypLiv.canvas.textout(rect.left+120,rect.top+0,CbTypLiv.items[index]);end;
end;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.FormKeyPress(Sender: TObject; var Key: Char);
begin Case key of
#13:begin PnlTypLivLigEta.Caption :='Evénement on KEYPRESSED : touche "Enter " enfoncée';BtnEntTypLivClick(self);end;
#27:begin PnlTypLivLigEta.Caption :='Evénement on KEYPRESSED : touche "Escape" enfoncée';BtnRetTypLivClick(self);end;
end;{of case}end;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.BtnEntTypLivClick(Sender: TObject);
begin If cbTypliv.Text<>'' then cbtypliv.Items.Add(PLMAJ(Minuscule(CbTypLiv.Text)));CbTypLiv.Text:='';
CbTypLiv.SetFocus;PnlTypLivLigEta.Caption:='Bouton "Enter" a été activé !';end;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.BtnCpyTypLivClick(Sender: TObject);
var Txt, CheminFichier, NomFichier,NomFichierBu,ExtFichier,NFichPhys,NFichPhysBU:string;
begin
PnlTypLivLigEta.Caption:='L'' action de "Copie" a été invoquée !';
Txt:='Voulez-vous effectuer une copie du fichier ?';
case MessageDlgPos(Txt,mtConfirmation,[mbYes,mbNo],0,530,390) of
mrNo : Begin close;end;
mrYes :begin //Copie du Fichier des Titres de livres
CheminFichier:=ExtractFilePath(Application.ExeName);
NomFichier:='TomTypLiv01';
NomFichierBU:='TomTypLiv01BU';
ExtFichier:='txt';
NFichPhys:=CheminFichier+NomFichier+'.'+ExtFichier;
NFichPhysBU:=CheminFichier+NomFichierBU+'.'+ExtFichier;
PhcCpyFic(NFichPhys,NFichPhysBU,false,false,true);
End; end; {of case} End;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.BtnRetTypLivClick(Sender: TObject); // Fermeture de la fenêtre
begin with FrmTypLiv do begin close; end;end;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.BtnFinTypLivClick(Sender: TObject);
begin btnCpyTypLivClick(self);with FrmTypLiv do begin close; end;end;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.SavTypLivClick(Sender: TObject);
Var F : textfile; CheminFichier, NomFichier, ExtFichier, NFichPhys:string;
begin CheminFichier:=ExtractFilePath(Application.ExeName); ExtFichier:='txt';
NomFichier:='TomTypLiv01';
NFichPhys:=CheminFichier+NomFichier+'.'+ExtFichier;
AssignFile(F,NFichPhys);
CbTypLiv.Items.SaveToFile(NFichPhys);
PnlTypLivLigEta.Caption :='L''action de sauvegarde a été invoquée !';end;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.CbTypLivChange(Sender: TObject);
var i : Integer;keypressed:word;
begin
i:= CbTypLiv.ItemIndex;
PnlTypLivLigEta.Caption := 'On Change !';
if keypressed = VK_DELETE then showmessage ('Delete');
//ComboBox.Items.Delete(Index); voir si pas mettre crochets //combobox.DeleteSelected
//LblSelTypLiv.Caption := 'Tu as clické sur : ' + CbTypLiv.Items.Strings[i] + ' à la position : ' + IntToStr(i + 1);
end;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.BtnSupTypLivClick(Sender: TObject);
begin PnlTypLivLigEta.Caption := '';i := CbTypLiv.ItemIndex;
PnlTypLivLigEta.Caption := '" '+cbTypLiv.items[i]+' " a été supprimé via le bouton "Supprime" !';
CBTypLiv.Items.Delete(I); //combobox.DeleteSelected //pour plusieurs items (propopriété multiselect)
end;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin case key of
VK_DELETE:begin PnlTypLivLigEta.Caption :='Evénement on KEYDOWN : touche "Delete" enfoncée';BtnSupTypLivClick(self);;end;
VK_INSERT:begin PnlTypLivLigEta.Caption :='Evénement on KEYDOWN : touche "Insert" enfoncée';end;
VK_ESCAPE:begin PnlTypLivLigEta.Caption :='Evénement on KEYDOWN : touche "Escape" enfoncée';BtnFinTypLivClick(self);end;
VK_F3 :begin PnlTypLivLigEta.Caption :='Evénement on KEYDOWN : touche "F3" enfoncée';BtnFinTypLivClick(self);end;
VK_F11 :begin PnlTypLivLigEta.Caption :='Evénement on KEYDOWN : touche "F11" enfoncée';end;
VK_F12 :begin PnlTypLivLigEta.Caption :='Evénement on KEYDOWN : touche "F12" enfoncée';end;
end {of case}end;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.BtnModTypLivClick(Sender: TObject);
var i :integer;
begin PnlTypLivLigEta.Caption := '';cbtypliv.text:='';i := CbTypLiv.ItemIndex;
PnlTypLivLigEta.Caption := '" '+cbTypLiv.items[i]+' " a été modifié via le bouton "Modifie" !';
CbTypLiv.text:=CbTypLiv.items[i]+'mod';CBTypLiv.setfocus; end;
//CbTypLiv.Items.Add(PLMAJ(Minuscule(CbTypLiv.Text)));CbTypLiv.Text:='';CbTypLiv.SetFocus;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.CbTypLivEnter(Sender: TObject);
begin
CBTypLiv.Perform(CB_SHOWDROPDOWN, Integer(True), 0);
end;
//---------------------------------------------------------------------------------------------------
procedure TFrmTypLiv.FormShow(Sender: TObject);
begin CbTypliv.SetFocus end;
//---------------------------------------------------------------------------------------------------
end. |
Partager