Changeset 429 for ModularSystem/UModularSystem.pas
- Timestamp:
- Oct 17, 2012, 1:21:41 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ModularSystem/UModularSystem.pas
r428 r429 22 22 FRunning: Boolean; 23 23 FInstalled: Boolean; 24 Manager: TModuleManager;24 FManager: TModuleManager; 25 25 FVersion: string; 26 26 FIdentification: string; … … 34 34 procedure SetRunning(AValue: Boolean); 35 35 protected 36 procedure BeforeStart; virtual; 37 procedure AfterStart; virtual; 38 procedure BeforeStop; virtual; 39 procedure AfterStop; virtual; 36 procedure DoStart; virtual; 37 procedure DoStop; virtual; 38 procedure DoInstall; virtual; 39 procedure DoUninstall; virtual; 40 procedure DoUpgrade; virtual; 40 41 public 41 42 API: TAPI; 42 procedure Start; virtual;43 procedure Stop; virtual;44 procedure Install; virtual;45 procedure Uninstall; virtual;46 procedure Upgrade; virtual;43 procedure Start; 44 procedure Stop; 45 procedure Install; 46 procedure Uninstall; 47 procedure Upgrade; 47 48 procedure EnumModulesStart(ModuleList: TStringList); 48 49 procedure EnumModulesStop(ModuleList: TStringList); … … 56 57 property Enabled: Boolean read FEnabled write SetEnabled; 57 58 published 59 property Manager: TModuleManager read FManager; 58 60 property Version: string read FVersion write FVersion; 59 61 property Identification: string read FIdentification write FIdentification; … … 260 262 begin 261 263 Modules.Add(Module); 262 Module. Manager := Self;264 Module.FManager := Self; 263 265 Module.API := API; 264 266 Module.Enabled := Enabled; … … 310 312 inherited; 311 313 Modules := TObjectList.Create; 314 //Modules.OwnsObjects := False; 312 315 end; 313 316 … … 316 319 StopAll; 317 320 FreeAndNil(Modules); 318 inherited Destroy;321 inherited; 319 322 end; 320 323 … … 344 347 RootKey := Context.RootKey; 345 348 for I := 0 to Modules.Count - 1 do 346 with TModule(Modules[I]) do begin 349 with TModule(Modules[I]) do 350 if Enabled then begin 347 351 OpenKey(Context.Key + '\' + Identification, True); 348 352 WriteBool('Run', Running); … … 361 365 end; 362 366 363 procedure TModule.BeforeStart; 364 begin 365 if Running then Exit; 367 procedure TModule.DoStart; 368 begin 369 370 end; 371 372 procedure TModule.DoStop; 373 begin 374 375 end; 376 377 procedure TModule.DoInstall; 378 begin 379 380 end; 381 382 procedure TModule.DoUninstall; 383 begin 384 385 end; 386 387 procedure TModule.DoUpgrade; 388 begin 389 390 end; 391 392 procedure TModule.SetInstalled(AValue: Boolean); 393 begin 394 if FInstalled = AValue then Exit; 395 if AValue then Install else Uninstall; 396 end; 397 398 procedure TModule.SetEnabled(AValue: Boolean); 399 begin 400 if FEnabled = AValue then Exit; 401 FEnabled := AValue; 402 if not FEnabled and FInstalled then Uninstall; 403 end; 404 405 procedure TModule.Start; 406 begin 407 if not Enabled or Running then Exit; 366 408 if not Installed then Install; 367 409 Manager.StartDependencies(Identification, Dependencies); 368 end; 369 370 procedure TModule.AfterStart; 371 begin 410 DoStart; 372 411 FRunning := True; 373 412 end; 374 413 375 procedure TModule. BeforeStop;414 procedure TModule.Stop; 376 415 begin 377 416 if not Running then Exit; 378 417 FRunning := False; 379 418 Manager.StopDependencies(Identification); 380 end; 381 382 procedure TModule.AfterStop; 383 begin 384 end; 385 386 procedure TModule.SetInstalled(AValue: Boolean); 387 begin 388 if FInstalled = AValue then Exit; 389 if AValue then Install else Uninstall; 390 end; 391 392 procedure TModule.SetEnabled(AValue: Boolean); 393 begin 394 if FEnabled = AValue then Exit; 395 FEnabled := AValue; 396 if not FEnabled and FInstalled then Uninstall; 397 end; 398 399 procedure TModule.Start; 400 begin 401 BeforeStart; 402 AfterStart; 403 end; 404 405 procedure TModule.Stop; 406 begin 407 BeforeStop; 408 AfterStop; 419 DoStop; 409 420 end; 410 421 411 422 procedure TModule.Install; 412 423 begin 413 if Installed then Exit;424 if not Enabled or Installed then Exit; 414 425 Manager.InstallDependencies(Identification, Dependencies); 415 426 FInstalled := True; 416 427 if Assigned(Manager.FOnModuleChange) then 417 428 Manager.FOnModuleChange(Manager, Self); 429 DoInstall; 418 430 end; 419 431 … … 424 436 Manager.UninstallDependencies(Identification); 425 437 FInstalled := False; 438 DoUninstall; 426 439 if Assigned(Manager.FOnModuleChange) then 427 440 Manager.FOnModuleChange(Manager, Self); … … 430 443 procedure TModule.Upgrade; 431 444 begin 432 if not Running then Exit; 445 if not Enabled or not Installed then Exit; 446 if Running then try 447 Stop; 448 DoUpgrade; 449 finally 450 Start; 451 end else DoUpgrade; 433 452 end; 434 453 … … 474 493 begin 475 494 Running := False; 476 Description.Free;477 Dependencies.Free;478 inherited Destroy;495 FreeAndNil(FDescription); 496 FreeAndNil(FDependencies); 497 inherited; 479 498 end; 480 499
Note:
See TracChangeset
for help on using the changeset viewer.