home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 5
/
ctrom5b.zip
/
ctrom5b
/
PROGRAM
/
DELPHI
/
MAXPACK
/
USERINFO.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-04-27
|
4KB
|
90 lines
unit UserInfo;
{WHAT THE HECK IS THE IDEA HERE?
TUserInfo is the innocent looking ancestor class to a slew of components that are starting
to run my apps for me. It is appropriately simple and you can peruse how the three first
level childen I included rely on it to get updated. If you catch on to how this could be
used you will realize that as soon as you have one UserInfo Component rely on another
(via you having setup a 'field' and 'property' to link them) you'll run into one component
not beeing initialized before another, pointers beeing off and the whole thing blowing up
at you. If that happens, check/adjust the Component Creation Order.}
{-----------------------------------------------------------------------------------------}
{ USERINFO }
{-----------------------------------------------------------------------------------------}
interface
uses
Classes;
Type
TUserInfo = class(TComponent)
private
fUpdateLoaded : Boolean;
protected
public
Constructor Create(aOwner:TComponent); Override;
procedure Loaded; Override;
function Update:Boolean; Virtual;
procedure NilIfSet(TheComponent,AComponent: TComponent);
procedure SetIfNil(TheComponent,AComponent: TComponent);
published
property UpdateOnLoad : Boolean read fUpdateLoaded write fUpdateLoaded;
end;
implementation
{-----------------------------------------------------------------------------------------}
{ OBJECT CREATION }
{-----------------------------------------------------------------------------------------}
Constructor TUserInfo.Create(aOwner:TComponent);
begin
inherited Create(aOwner);
end;
procedure TUserInfo.Loaded;
begin
inherited Loaded;
if fUpdateLoaded then {e.g. the component can call the update proc to set itself up}
Update; {because you set the property so}
end;
function TUserInfo.Update:Boolean; {The 'Ancestor' update will not kick in while designing}
begin
Result:= not (csDesigning in ComponentState);
{you will usually override update to get and set some information. these child procs
should be coded like this:
Result:= INHERITED Update [and (fSourceForMoreBasicUserInfo<>nil)];
if Result then
doSomeThingReal;
}
end;
{-----------------------------------------------------------------------------------------}
{ NilIfSet / SetIfNil Notification and Init Procedure Assistants }
{-----------------------------------------------------------------------------------------}
{Ever write a Notification proc and get annoyed? I wrote the first proc to get over that.
the second proc was written to accomodate the 'search and set' method of filling missing
links to other components when you already found one. makes no sense? you dont need it.}
procedure TUserInfo.NilIfSet(TheComponent,AComponent: TComponent);
begin
if TheComponent <> nil then
if TheComponent = AComponent then
TheComponent := nil;
end;
procedure TUserInfo.SetIfNil(TheComponent,AComponent: TComponent);
begin
if TheComponent = nil then
TheComponent := AComponent;
end;
{-----------------------------------------------------------------------------------------}
{ }
{-----------------------------------------------------------------------------------------}
end.