Francois PIETTE wrote:
>> A TIcsLogger could be linked to the ICS components
> 
> Arno,
> 
> I don't know how you intend to implement your logging classe but your last
> messages about compiler trouble make me thinking you are planning to
> change TWSocket base class to add logging feature.
> 
> I don't think it is the right way to do it. It would probably cause a lot
> of trouble in many TWSocket derived classes. It is probably much better
> to add a property to TCustomWSocket, maybe :
>     FLoggerClass : TIcsLogger;
> If this property is not assigned, the component behave as usual. If the
> property is assigned, the component start logging using the logger class.
> 
> What do you think ?

Yes exactly, this is what I've done a component TIcsLogger.

*However, in order to save a lot duplicated code implementing the new property
"IcsLogger" I made in fact a new tiny base class, but so far there's no problem 
with
derived classes, base class below.


TIcsBaseLogComp = class(TComponent)
    protected
        FIcsLogger  : TIcsLogger;
        procedure   SetIcsLogger(const Value : TIcsLogger); virtual;
        procedure   Notification(AComponent  : TComponent;
                                 Operation   : TOperation); override;
    public
        procedure   DebugLog(LogOption : TLogOption;
                             const Msg : string); virtual;
        function    CheckLogOptions(const LogOption: TLogOption): Boolean; 
virtual;
    published
        property    IcsLogger : TIcsLogger                read  FIcsLogger
                                                          write SetIcsLogger;
    end; 

{ TIcsLogComp }

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}

function TIcsBaseLogComp.CheckLogOptions(const LogOption: TLogOption): Boolean;
begin
    Result := Assigned(FIcsLogger) and (LogOption in FIcsLogger.LogOptions);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TIcsBaseLogComp.DebugLog(LogOption: TLogOption; const Msg: string);
begin
    if Assigned(FIcsLogger) then
        if loAddStamp in FIcsLogger.FLogOptions then
            FIcsLogger.DoDebugLog(Self, LogOption,
                                  IcsLoggerAddTimeStamp + ' ' + Msg)
        else
            FIcsLogger.DoDebugLog(Self, LogOption, Msg);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TIcsBaseLogComp.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
    inherited Notification(AComponent, Operation);
    if Operation = opRemove then begin
        if AComponent = FIcsLogger then
            FIcsLogger := nil;
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TIcsBaseLogComp.SetIcsLogger(const Value: TIcsLogger);
begin
    FIcsLogger := Value;
    if Value <> nil then
        Value.FreeNotification(Self);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}

> 
> --
> [EMAIL PROTECTED]
> http://www.overbyte.be
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to