procedure TForm1.btnRegionCountryClick(Sender: TObject);
Var I : Integer = -1;
Mode : String = ''; {Valid 'O' 'B'}
Region : String[2] = '';
Country : String[80] = '';
Indie : String[1] = '';
RCD : String[80] = '';
LB5RCD : String[40] = '';
NilCount : Integer = -1;
begin
{'[AG][Solomon Islands][I]'}
i := ListBox5.ItemIndex;
if i =-1 then begin exit; end;
LB5RCD := Listbox5.Items[i];
ToTop(i,Listbox5);
RCD := GetRegionCountry(i);
Region := ExtractWord(1,RCD,['[',']']);
Country := ExtractWord(2,RCD,['[',']']);
Indie := ExtractWord(3,RCD,['[',']']);
Mode := 'B';
if Indie = 'O' then begin Mode := 'O' end;
CountryRegion(MODE, Region,Country); // <--- Makes the call
ListBox4.ItemIndex := 0;
ListBox4.Selected[i] := False;
ListBox3.ItemIndex := 0;
ListBox3.Selected[i] := False;
ListBox5.ItemIndex := 0;
ListBox5.Selected[i] := False;
end;
{How it works: }
{ Mode = 'B' Both the Region field and Country field can be change based on }
{ the AREGION and/or ACOUNTRY. }
{ Mode = 'O' Only the Country field in the Record can be changed based on the }
{ AREGION. The Region code in the record CAN NOT be changed as the country has}
{ mutipual region codes. }
procedure TForm1.CountryRegion(AMODE : String; AREGION : String; ACOUNTRY : STRING);
Var i : Integer = -1;
BMode : TChgMode;
Country : String[45] = '';
Region : String[2] = '';
City : String[45] = '';
LB4RCD : String[180] = '';
NilCount : Integer = -1;
a : Integer = -1;
Begin
{[00F][8927][Broadus][US][K1][45.47314456][-105.46488607]}
{ TChgMode = (iRegion, iCountry, iRegionCity, , iCityCountry)}
for i := 0 to Listbox4.Items.Count -1 do begin //<-- enter the for loop
ListBox4.ItemIndex := i;
LB4RCD := Listbox4.Items[i];
Region := ExtractWord(5,LB4RCD,['[',']']);
Country := ExtractWord(4,LB4RCD,['[',']']);
if (Region <> AREGION) And (Country <> ACOUNTRY) then begin Continue; end;
Edit8.Text := LB4RCD;
BMode := DetermineWhichNils(LB4RCD);
NilCount := CountWhat(ANIL, LB4RCD);
if (BMODE = iZeroNils) OR (BMODE = iAllThree) then Continue
else if (NilCount = 1) And (BMODE = iCITY) then Continue
else if (NilCount = 2) And (BMODE = iRegionCountry) then Continue
else if (AMODE = 'O') And (BMODE = iRegion) then Continue;
ListBox4.ItemIndex := i;
ToTop(i,Listbox4);
Application.ProcessMessages;
{ Region = 'AG' AREGION = 'AG' Country = ANIL BMode = 'B'}
if (Region = AREGION) And (AMODE = 'B') then Begin
Edit4.Text := ACOUNTRY;
btnChgCountryClick(Nil);
Application.ProcessMessages;
end;
{ Region = 'ANIL' AREGION = 'AG' Country = 'a Country' BMode = 'B'}
if (Country = ACOUNTRY) And (AMODE = 'B') then Begin
Edit5.Text := AREGION;
btnChgRegionClick(Nil);
Application.ProcessMessages;
end;
end; {end of for loop} //<--- Should exit after one time thru
end; {end of procedure CountryRegion}