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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
| unit Chrono_chrono;
interface
uses WinTypes, WinProcs, Messages, SysUtils, Classes, Controls,
Forms, Graphics, Extctrls;
{ Unit-wide declarations }
type
Pos_verticale = (Haut,Bas,Milieu_haut,Milieu_bas,Centre,Haut_et_bas);
{ var }
{ . . . }
type
TChronologie = class(TPanel)
private
{ Private fields of TChronologie }
FAnnee_debut : Integer;
FAnnee_fin : Integer;
FCommentaire : TStrings;
FDate_debut : String;
FDate_fin : String;
FLien_vers : String;
FNumero_chronologie : Integer;
FTitre : String;
FVerticale : pos_verticale;
{ Private methods of TChronologie }
{ Method to set variable and property values and create objects }
procedure AutoInitialize;
{ Method to free any objects created by AutoInitialize }
procedure AutoDestroy;
function GetAnnee_debut : Integer;
procedure SetAnnee_debut(Value : Integer);
function GetAnnee_fin : Integer;
procedure SetAnnee_fin(Value : Integer);
function GetCommentaire : TStrings;
procedure SetCommentaire(Value : TStrings);
function GetDate_debut : String;
procedure SetDate_debut(Value : String);
function GetDate_fin : String;
procedure SetDate_fin(Value : String);
function GetLien_vers : String;
procedure SetLien_vers(Value : String);
function GetNumero_chronologie : Integer;
procedure SetNumero_chronologie(Value : Integer);
function GetTitre : String;
procedure SetTitre(Value : String);
function GetVerticale : pos_verticale;
procedure SetVerticale(Value : pos_verticale);
protected
{ Protected fields of TChronologie }
{ Protected methods of TChronologie }
procedure Click; override;
procedure KeyPress(var Key : Char); override;
procedure Loaded; override;
procedure Paint; override;
public
{ Public fields and properties of TChronologie }
Echelle : real;
{ Public methods of TChronologie }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Place;
published
{ Published properties of TChronologie }
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property Annee_debut : Integer
read GetAnnee_debut write SetAnnee_debut
default -2000;
property Annee_fin : Integer
read GetAnnee_fin write SetAnnee_fin
default 2013;
property Commentaire : TStrings
read GetCommentaire write SetCommentaire;
property Date_debut : String read GetDate_debut write SetDate_debut;
property Date_fin : String read GetDate_fin write SetDate_fin;
property Lien_vers : String read GetLien_vers write SetLien_vers;
property Numero_chronologie : Integer
read GetNumero_chronologie write SetNumero_chronologie
default 0;
property Titre : String read GetTitre write SetTitre;
property Verticale : pos_verticale
read GetVerticale write SetVerticale;
end;
procedure Register;
implementation
procedure Register;
begin
{ Register TChronologie with Chronologie as its
default page on the Delphi component palette }
RegisterComponents('Chronologie', [TChronologie]);
end;
{ Method to set variable and property values and create objects }
procedure TChronologie.AutoInitialize;
begin
FAnnee_debut := -2000;
FAnnee_fin := 2013;
FCommentaire := TStringList.Create;
FDate_debut := 'XX/XX/1968';
FDate_fin := '01/01/1968';
FNumero_chronologie := 0;
end; { of AutoInitialize }
{ Method to free any objects created by AutoInitialize }
procedure TChronologie.AutoDestroy;
begin
FCommentaire.Free;
end; { of AutoDestroy }
function TChronologie.GetAnnee_debut : Integer;
begin
Result := FAnnee_debut;
end;
procedure TChronologie.SetAnnee_debut(Value : Integer);
begin
FAnnee_debut := Value;
{ If changing this property affects the appearance of
the component, call Invalidate here so the image will be
updated. }
{ Invalidate; }
end;
function TChronologie.GetAnnee_fin : Integer;
begin
Result := FAnnee_fin;
end;
procedure TChronologie.SetAnnee_fin(Value : Integer);
begin
FAnnee_fin := Value;
{ If changing this property affects the appearance of
the component, call Invalidate here so the image will be
updated. }
{ Invalidate; }
end;
function TChronologie.GetCommentaire : TStrings;
begin
Result := FCommentaire;
end;
procedure TChronologie.SetCommentaire(Value : TStrings);
begin
{ Use Assign method because TStrings is an object type
and FCommentaire has been created. }
FCommentaire.Assign(Value);
{ If changing this property affects the appearance of
the component, call Invalidate here so the image will be
updated. }
{ Invalidate; }
end;
function TChronologie.GetDate_debut : String;
begin
Result := FDate_debut;
end;
procedure TChronologie.SetDate_debut(Value : String);
begin
FDate_debut := Value;
{ If changing this property affects the appearance of
the component, call Invalidate here so the image will be
updated. }
{ Invalidate; }
end;
function TChronologie.GetDate_fin : String;
begin
Result := FDate_fin;
end;
procedure TChronologie.SetDate_fin(Value : String);
begin
FDate_fin := Value;
{ If changing this property affects the appearance of
the component, call Invalidate here so the image will be
updated. }
{ Invalidate; }
end;
function TChronologie.GetLien_vers : String;
begin
Result := FLien_vers;
end;
procedure TChronologie.SetLien_vers(Value : String);
begin
FLien_vers := Value;
{ If changing this property affects the appearance of
the component, call Invalidate here so the image will be
updated. }
{ Invalidate; }
end;
function TChronologie.GetNumero_chronologie : Integer;
begin
Result := FNumero_chronologie;
end;
procedure TChronologie.SetNumero_chronologie(Value : Integer);
begin
FNumero_chronologie := Value;
{ If changing this property affects the appearance of
the component, call Invalidate here so the image will be
updated. }
{ Invalidate; }
end;
function TChronologie.GetTitre : String;
begin
Result := FTitre;
end;
procedure TChronologie.SetTitre(Value : String);
begin
FTitre := Value;
{ If changing this property affects the appearance of
the component, call Invalidate here so the image will be
updated. }
{ Invalidate; }
end;
function TChronologie.GetVerticale : pos_verticale;
begin
Result := FVerticale;
end;
procedure TChronologie.SetVerticale(Value : pos_verticale);
begin
FVerticale := Value;
{ If changing this property affects the appearance of
the component, call Invalidate here so the image will be
updated. }
{ Invalidate; }
end;
{ Override OnClick handler from TPanel }
procedure TChronologie.Click;
begin
{ Code to execute before activating click
behavior of component's parent class }
{ Activate click behavior of parent }
inherited Click;
{ Code to execute after click behavior
of parent }
end;
{ Override OnKeyPress handler from TPanel }
procedure TChronologie.KeyPress(var Key : Char);
const
TabKey = Char(VK_TAB);
EnterKey = Char(VK_RETURN);
begin
{ Key contains the character produced by the keypress.
It can be tested or assigned a new value before the
call to the inherited KeyPress method. Setting Key
to #0 before call to the inherited KeyPress method
terminates any further processing of the character. }
{ Activate KeyPress behavior of parent }
inherited KeyPress(Key);
{ Code to execute after KeyPress behavior of parent }
end;
constructor TChronologie.Create(AOwner: TComponent);
begin
{ Call the Create method of the container's parent class }
inherited Create(AOwner);
{ AutoInitialize sets the initial values of variables }
{ (including subcomponent variables) and properties; }
{ also, it creates objects for properties of standard }
{ Delphi object types (e.g., TFont, TTimer, TPicture) }
{ and for any variables marked as objects. }
{ AutoInitialize method is generated by Component Create. }
AutoInitialize;
{ Code to perform other tasks when the container is created }
end;
destructor TChronologie.Destroy;
begin
{ AutoDestroy, which is generated by Component Create, frees any }
{ objects created by AutoInitialize. }
AutoDestroy;
{ Here, free any other dynamic objects that the component methods }
{ created but have not yet freed. Also perform any other clean-up }
{ operations needed before the component is destroyed. }
{ Last, free the component by calling the Destroy method of the }
{ parent class. }
inherited Destroy;
end;
procedure TChronologie.Loaded;
begin
inherited Loaded;
{ Perform any component setup that depends on the property
values having been set }
end;
procedure TChronologie.Paint;
begin
{ Make this component look like its parent component by calling
its parent's Paint method. }
inherited Paint;
{ To change the appearance of the component, use the methods
supplied by the component's Canvas property (which is of
type TCanvas). For example, }
{ Canvas.Rectangle(0, 0, Width, Height); }
end;
procedure TChronologie.Place;
var x1, x2 : integer;
begin
if (FAnnee_fin-FAnnee_debut)>0 then
Echelle:=parent.width/(FAnnee_fin-FAnnee_debut)
else
Echelle:=0;
x1:=trunc((strtoint(copy(fdate_debut,7,255))-FAnnee_debut)*Echelle);
if x1<0 then x1:=0;
left:=x1;
x2:=trunc((strtoint(copy(fdate_fin,7,255))-FAnnee_debut)*Echelle);
if x2>parent.width then x2:=parent.width;
Width:=x2-x1;
case fVerticale of
Haut : Top:=(fNumero_chronologie-1)*Height;
Milieu_haut : Top:=(parent.Height div 2)-(fNumero_chronologie)*Height;
Centre : begin
if fNumero_chronologie mod 2=0 then
begin
Top:=(parent.Height div 2)-((fNumero_chronologie div 2))*Height;
end else
begin
Top:=(parent.Height div 2)+(fNumero_chronologie div 2)*Height;
end;
end;
Milieu_bas : Top:=(parent.Height div 2)+(fNumero_chronologie-1)*Height;
Bas : Top:=parent.Height-(fNumero_chronologie)*Height;
Haut_et_bas : begin
if fNumero_chronologie mod 2=0 then
begin
Top:=((fNumero_chronologie div 2)-1)*Height; // haut
end else
begin
Top:=parent.Height-((fNumero_chronologie div 2)+1)*Height; // bas
end;
end;
end
end;
end. |
Partager