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
| Procedure Tf_comment.GenereAndShow(annee,demande : Integer);
var
h_depart, pos_top, w_marge, w_comment, h_total,h_comment, w_label, h_label, id_util, nb_comment : integer;
nom_util:String;
n_date, n_util: TLabel;
n_comment: TMemo;
begin
// Initialisation des variables de mise en forme
h_depart := 50;
pos_top := h_depart;
nb_comment := 0;
h_comment := 110;
w_comment := 400;
h_label := 20;
w_marge := 20;
w_label := 70;
txt_dem.Caption := IntToStr(annee)+' - '+IntToStr(demande);
// Récupération des données dans DBF
ds_comment.DataSet.Open;
ds_comment.DataSet.Filtered := false;
ds_comment.DataSet.Filter:='annee='+IntToStr(annee)+' AND id='+IntToStr(demande);
ds_comment.DataSet.Filtered := true;
ds_comment.DataSet.Last;
// Boucle sur les données à afficher
while not ds_comment.DataSet.BOF do
begin
nb_comment := nb_comment + 1;
// TLabel pour date
n_date := TLabel.Create(self);
with n_date do
begin
name:= 'l_date_'+IntToStr(nb_comment);
parent:=self;
Top:=pos_top;
Left:=w_marge;
Autosize:=false;
Wordwrap:=true;
Width:= w_label;
Caption:=ds_comment.DataSet.FieldByName('date_heure').AsString;
Height:= h_label;
end;
// TLabel pour utilisateur
n_util := TLabel.Create(self);
id_util := ds_comment.DataSet.FieldByName('id_user').AsInteger;
if ds_user.DataSet.Locate('id_user', varArrayOf([id_util]),[]) = true then
nom_util := ds_user.DataSet.FieldByName('username').AsString
else
nom_util := 'Inconnu';
with n_util do
begin
name:= 'l_util_'+IntToStr(nb_comment);
parent:=self;
Top:=pos_top + h_label;
Left:=w_marge;
Autosize:=false;
Wordwrap:=true;
Width:=w_label;
Caption:= nom_util;
Height:= h_label;
end;
// TMemo pour commentaires
n_comment := TMemo.Create(self);
with n_comment do
begin
name:= 'm_memo_'+IntToStr(nb_comment);
parent:=self;
Top:=pos_top;
Left:= w_label + ( 2 * w_marge );
Width:=w_comment;
Text:=ds_comment.DataSet.FieldByName('commentair').AsString;
Height:=h_comment;
ScrollBars:= ssAutoVertical;
ReadOnly:=true;
end;
pos_top := pos_top + h_comment + w_marge;
ds_comment.DataSet.Prior;
end;
ds_comment.DataSet.Close;
// Positionnement de la fenêtre formulaire
h_total:= h_depart + ( nb_comment * ( h_comment + w_marge ) );
if h_total > hauteur_ecran then
height := hauteur_ecran
else
height := h_total;
top := round( ( hauteur_ecran - Height )/2);
left := largeur_ecran-width;
Show;// ou showmodal le cas écheant
end; |
Partager