home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / DELPHI / MAXPACK / USERINFO.PAS < prev    next >
Pascal/Delphi Source File  |  1995-04-27  |  4KB  |  90 lines

  1. unit UserInfo;
  2.  
  3. {WHAT THE HECK IS THE IDEA HERE?
  4. TUserInfo is the innocent looking ancestor class to a slew of components that are starting
  5. to run my apps for me. It is appropriately simple and you can peruse how the three first
  6. level childen I included rely on it to get updated. If you catch on to how this could be
  7. used you will realize that as soon as you have one UserInfo Component rely on another
  8. (via you having setup a 'field' and 'property' to link them) you'll run into one component
  9. not beeing initialized before another, pointers beeing off and the whole thing blowing up
  10. at you. If that happens, check/adjust the Component Creation Order.}
  11.  
  12. {-----------------------------------------------------------------------------------------}
  13. { USERINFO                                                                                }
  14. {-----------------------------------------------------------------------------------------}
  15.  
  16. interface
  17.  
  18. uses
  19.   Classes;
  20.  
  21. Type
  22.   TUserInfo = class(TComponent)
  23.   private
  24.     fUpdateLoaded   : Boolean;
  25.   protected
  26.   public
  27.     Constructor Create(aOwner:TComponent); Override;
  28.     procedure Loaded; Override;
  29.     function Update:Boolean; Virtual;
  30.     procedure NilIfSet(TheComponent,AComponent: TComponent);
  31.     procedure SetIfNil(TheComponent,AComponent: TComponent);
  32.   published
  33.     property UpdateOnLoad  : Boolean read fUpdateLoaded write fUpdateLoaded;
  34.     end;
  35.  
  36. implementation
  37.  
  38. {-----------------------------------------------------------------------------------------}
  39. { OBJECT CREATION                                                                         }
  40. {-----------------------------------------------------------------------------------------}
  41.  
  42. Constructor TUserInfo.Create(aOwner:TComponent);
  43. begin
  44.   inherited Create(aOwner);
  45. end;
  46.  
  47. procedure TUserInfo.Loaded;
  48. begin
  49.   inherited Loaded;
  50.   if fUpdateLoaded then  {e.g. the component can call the update proc to set itself up}
  51.     Update;              {because you set the property so}
  52. end;
  53.  
  54. function TUserInfo.Update:Boolean; {The 'Ancestor' update will not kick in while designing}
  55. begin
  56.   Result:= not (csDesigning in ComponentState);
  57.   {you will usually override update to get and set some information. these child procs
  58.   should be coded like this:
  59.     Result:= INHERITED Update [and (fSourceForMoreBasicUserInfo<>nil)];
  60.     if Result then
  61.       doSomeThingReal;
  62.   }
  63. end;
  64.  
  65. {-----------------------------------------------------------------------------------------}
  66. { NilIfSet / SetIfNil   Notification and Init Procedure Assistants                        }
  67. {-----------------------------------------------------------------------------------------}
  68. {Ever write a Notification proc and get annoyed? I wrote the first proc to get over that.
  69. the second proc was written to accomodate the 'search and set' method of filling missing
  70. links to other components when you already found one. makes no sense? you dont need it.}
  71.  
  72. procedure TUserInfo.NilIfSet(TheComponent,AComponent: TComponent);
  73. begin
  74.   if TheComponent <> nil then
  75.     if TheComponent = AComponent then
  76.       TheComponent := nil;
  77. end;
  78.  
  79. procedure TUserInfo.SetIfNil(TheComponent,AComponent: TComponent);
  80. begin
  81.   if TheComponent = nil then
  82.     TheComponent := AComponent;
  83. end;
  84.  
  85. {-----------------------------------------------------------------------------------------}
  86. {                                                                                         }
  87. {-----------------------------------------------------------------------------------------}
  88.  
  89. end.
  90.