/*
  ICS Network Monitor demo, one packet window - C++Builder translation of the Delphi demo
  OverbyteIcsNetMon2.pas (demos-delphi-vcl), ICS V9.8.

  Shows every field of the packet selected in the main form's packet grid. The window position is
  kept in the ICS ini file.
*/

#include <vcl.h>
#pragma hdrstop

#include "OverbyteIcsNetMon2.h"
#include "OverbyteIcsNetMon1.h"

#include <memory>

#pragma package(smart_init)
#pragma resource "*.dfm"

TFormOneRow *FormOneRow;

using namespace Netmonini;

__fastcall TFormOneRow::TFormOneRow(TComponent *Owner)
    : TForm(Owner)
{
}

void __fastcall TFormOneRow::FormClose(TObject *Sender, TCloseAction &Action)
{
    std::unique_ptr<TIcsIniFile> IniFile(new TIcsIniFile(GetIcsIniFileName(), true));   // PreserveAnsi: Delphi default
    // form positions
    IniFile->WriteInteger(SectionRow1Window, KeyWidth, Width);
    IniFile->WriteInteger(SectionRow1Window, KeyHeight, Height);
    IniFile->WriteInteger(SectionRow1Window, KeyTop, Top);
    IniFile->WriteInteger(SectionRow1Window, KeyLeft, Left);
    IniFile->UpdateFile();
}

void __fastcall TFormOneRow::FormShow(TObject *Sender)
{
    std::unique_ptr<TIcsIniFile> IniFile(new TIcsIniFile(GetIcsIniFileName(), true));
    // form positions, default to the right of the main form
    Width = IniFile->ReadInteger(SectionRow1Window, KeyWidth, Width);
    Height = IniFile->ReadInteger(SectionRow1Window, KeyHeight, Height);
    Top = IniFile->ReadInteger(SectionRow1Window, KeyTop, MonForm->Top);
    Left = IniFile->ReadInteger(SectionRow1Window, KeyLeft, MonForm->Left + MonForm->Width + 20);
}
