//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "FrmSysLogF.h"
#include "AppGlobalF.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFrmSysLog *FrmSysLog = NULL;
//---------------------------------------------------------------------------
__fastcall TFrmSysLog::TFrmSysLog(TComponent* Owner)
    : TForm(Owner)
{
    reMsg->Lines->Clear();
}
//---------------------------------------------------------------------------

void __fastcall TFrmSysLog::btnClearClick(TObject *Sender)
{
#if 0
    lbLog->Items->Clear();
#else
    reMsg->Lines->Clear();
#endif
}
//---------------------------------------------------------------------------

void __fastcall TFrmSysLog::btnCopyClick(TObject *Sender)
{
    try
    {
        reMsg->SelectAll();
        reMsg->CopyToClipboard();
    }
    catch(Exception &e)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmSysLog::OnWMLogDisplayMessage(TMessage &Msg)
{
    IPC_LOG_MESSAGE *pLog = (IPC_LOG_MESSAGE *)Msg.WParam;

    if (pLog)
    {
        IPC_LOG_MESSAGE Log;
        Log.Kind = pLog->Kind;
        Log.Flag = pLog->Flag;
        Log.Len  = pLog->Len;
        Log.Tm   = pLog->Tm;
        memcpy(Log.Msg, pLog->Msg, sizeof(Log.Msg));

        //SAFE_DELETE(pLog);

        //ReplyMessage(0);

        if (chkLogPause->Checked) return;
        LogWrite(&Log);
    }
}
//---------------------------------------------------------------------------

void TFrmSysLog::LogWrite(IPC_LOG_MESSAGE *ALog)
{
#if 0
	if(lbLog->Items->Count > g_AppCfg.nMaxLogLines) lbLog->Items->Delete(lbLog->Items->Count-1);
	lbLog->Items->Insert(0, ALog->Tm.FormatString("hh:nn:ss") + String(ALog->Msg));
#else

    try
    {
        while (reMsg->Lines->Count >= g_AppCfg.nMaxLogLines)
            reMsg->Lines->Delete(0);

        reMsg->Lines->Add(ALog->Tm.FormatString("hh:nn:ss") + String(ALog->Msg));
    }
    __finally
    {
        //Application->ProcessMessages();
    }
#endif
}
//---------------------------------------------------------------------------

