unit SectionEditor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TfrmSectionEditor = class(TForm)
    Label1: TLabel;
    txtName: TEdit;
    Label2: TLabel;
    txtVOffset: TEdit;
    Label3: TLabel;
    txtVSize: TEdit;
    txtROffset: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    txtRSize: TEdit;
    Label6: TLabel;
    txtFlags: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmSectionEditor: TfrmSectionEditor;

implementation

uses Sections;

{$R *.dfm}

procedure TfrmSectionEditor.FormShow(Sender: TObject);
begin
  txtName.Text    := frmSections.lsSections.Selected.Caption;
  txtVOffset.Text := frmSections.lsSections.Selected.SubItems[0];
  txtVSize.Text   := frmSections.lsSections.Selected.SubItems[1];
  txtROffset.Text := frmSections.lsSections.Selected.SubItems[2];
  txtRSize.Text   := frmSections.lsSections.Selected.SubItems[3];
  txtFlags.Text   := frmSections.lsSections.Selected.SubItems[4];
  SetWindowPos(frmSectionEditor.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE)
end;

procedure TfrmSectionEditor.Button1Click(Sender: TObject);
begin
  if EditSection(frmSections.lsSections.Selected.Index, txtName.Text, HexToInt(txtVOffset.Text), HexToInt(txtVSize.Text), HexToInt(txtROffset.Text), HexToInt(txtRSize.Text), HexToInt(txtFlags.Text)) then
  begin
    frmSections.lsSections.Selected.Caption     := txtName.Text;
    frmSections.lsSections.Selected.SubItems[0] := txtVOffset.Text;
    frmSections.lsSections.Selected.SubItems[1] := txtVSize.Text;
    frmSections.lsSections.Selected.SubItems[2] := txtROffset.Text;
    frmSections.lsSections.Selected.SubItems[3] := txtRSize.Text;
    frmSections.lsSections.Selected.SubItems[4] := txtFlags.Text;
  end
  else
    MessageBox(Application.Handle, PChar('Failed to write section data.'), PChar('Error'), MB_ICONEXCLAMATION);
end;

procedure TfrmSectionEditor.Button2Click(Sender: TObject);
begin
  frmSectionEditor.Hide;
end;

end.
