unit ZoneList;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  dxCore, dxButtons, eq2mapedfn, StdCtrls, ProCtrls;

type
  TForm7 = class(TForm)
    dxButton1: TdxButton;
    dxButton2: TdxButton;
    ZoneList: TListBox;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure dxButton1Click(Sender: TObject);
    procedure ZoneListClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    ZoneFileName : string;
    ZoneID : TStringList;
    function ReadZoneNames : boolean;
  end;

var
  Form7: TForm7;
  FilePath : string;

implementation

{$R *.DFM}

procedure TForm7.FormCreate(Sender: TObject);
var
        ix : integer;
begin
        ZoneFileName := '';
        ZoneID := TStringList.Create;
        FilePath := ExtractFilePath(Application.EXEName)+'zonenames.dat';
        ix := GetSystemDefaultLangID;
        if lo(ix)<>LANG_KOREAN then begin
                Font.Name := 'MS Sans Serif';
                Font.Size := 8;
                dxbutton1.Caption := '&Ok';
                dxbutton2.Caption := '&Cancel';
                self.Caption := 'Open Zone';
        end;
end;

function TForm7.ReadZoneNames : boolean;
var
        tl : TStringList;
        ix, ipos : integer;
        sx : string;
begin
        result := false;
        ZoneID.Clear;
        ZoneList.Items.Clear;
        ZoneList.Items.BeginUpdate;
        try
        tl := TStringList.Create;
        try
        tl.LoadFromFile(FilePath);
        if tl.Count>0 then
        for ix := 0 to pred(tl.Count) do begin
                sx := trim(tl.Strings[ix]);
                if sx<>'' then begin
                        ipos := poschrev(#32,sx);
                        if ipos>0 then begin
                                ZoneList.Items.Add(copy(sx,1,ipos-1));
                                ZoneID.Add(Copy(sx,ipos+1,length(sx)-ipos));
                        end;
                end;
        end;
        result := true;
        finally
        tl.free;
        end;
        except
        end;
        ZoneList.Items.EndUpdate;
end;


procedure TForm7.FormShow(Sender: TObject);
begin
        ReadZoneNames;
end;

procedure TForm7.FormDestroy(Sender: TObject);
begin
        ZoneID.Free;
end;

procedure TForm7.dxButton1Click(Sender: TObject);
var
        ix : integer;
begin
        ix := ZoneList.ItemIndex;
        if ix>-1 then ZoneFileName := 'icons_'+ZoneID.Strings[ix]+'.xml';
end;

procedure TForm7.ZoneListClick(Sender: TObject);
begin
        dxbutton1.Enabled := ZoneList.ItemIndex > -1;
end;

end.
