Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort contest names in dropdown list #135

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions Ini.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface
DEFAULTWEBSERVER = 'http://www.dxatlas.com/MorseRunner/MrScore.asp';
type
// Adding a contest: Append new TSimContest enum value for each contest.
// Adding a contest: update menu in Main.dfm.
TSimContest = (scWpx, scCwt, scFieldDay, scNaQp, scHst, scCQWW);
TRunMode = (rmStop, rmPileup, rmSingle, rmWpx, rmHst);

Expand All @@ -36,14 +35,14 @@ interface

// Contest definition.
TContestDefinition = record
Name: PChar; // Contest Name.
Name: PChar; // Contest Name. Used in SimContestCombo dropdown box.
Key: PChar; // Identifying key (used in Ini files)
ExchType1: TExchange1Type;
ExchType2: TExchange2Type;
ExchFieldEditable: Boolean; // whether the Exchange field is editable
ExchDefault: PChar; // contest-specific Exchange default message
Msg: PChar; // Exchange error message
T: TSimContest; // used to verify array ordering
T: TSimContest; // used to verify array ordering and lookup by Name
end;

PContestDefinition = ^TContestDefinition;
Expand All @@ -60,10 +59,11 @@ TContestDefinition = record
Note: The order of this table must match the declared order of
TSimContest above.

Adding a contest: update ContestDefinitions[] array. (append at end until sorting is added)
Adding a contest: update ContestDefinitions[] array (append at end
because .INI uses TSimContest value).
}
ContestDefinitions: array[TSimContest] of TContestDefinition = (
(Name: 'CQ Wpx';
(Name: 'CQ WPX';
Key: 'CqWpx';
ExchType1: etRST;
ExchType2: etSerialNr;
Expand All @@ -73,7 +73,7 @@ TContestDefinition = record
T:scWpx),
// 'expecting RST (e.g. 5NN)'

(Name: 'CWOPS Cwt';
(Name: 'CWOPS CWT';
Key: 'Cwt';
ExchType1: etOpName;
ExchType2: etCwopsNumber;
Expand Down Expand Up @@ -170,6 +170,7 @@ TContestDefinition = record
procedure FromIni;
procedure ToIni;
function IsNum(Num: String): Boolean;
function FindContestByName(const AContestName : String) : TSimContest;


implementation
Expand All @@ -187,7 +188,8 @@ procedure FromIni;
V:= ReadInteger(SEC_TST, 'SimContest', Ord(scWpx));
SimContest := TSimContest(V);
ActiveContest := @ContestDefinitions[SimContest];
MainForm.SimContestCombo.ItemIndex := V;
MainForm.SimContestCombo.ItemIndex :=
MainForm.SimContestCombo.Items.IndexOf(ActiveContest.Name);

// Adding a contest: read contest-specfic Exchange Strings from .INI file.
// load contest-specific Exchange Strings
Expand Down Expand Up @@ -331,6 +333,23 @@ function IsNum(Num: String): Boolean;
end;


function FindContestByName(const AContestName : String) : TSimContest;
var
C : TContestDefinition;
begin
for C in ContestDefinitions do
if CompareText(AContestName, C.Name) = 0 then
begin
Result := C.T;
// DebugLn('Ini.FindContestByName(%s) --> %s', [AContestName, DbgS(Result)]);
Exit;
end;

raise Exception.Create(
Format('error: ''%s'' is an unsupported contest name', [AContestName]));
Halt;
end;


end.

7 changes: 0 additions & 7 deletions Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -950,13 +950,6 @@ object MainForm: TMainForm
TabOrder = 0
TabStop = False
OnChange = SimContestComboChange
Items.Strings = (
'CQ WPX'
'CWOPS CWT'
'ARRL Field Day'
'NCJ NAQP'
'HST (High Speed Test)'
'CQ WW')
end
object ExchangeEdit: TEdit
Left = 76
Expand Down
23 changes: 20 additions & 3 deletions Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ TMainForm = class(TForm)
Selected: Boolean);
procedure mnuShowCallsignInfoClick(Sender: TObject);
procedure SimContestComboChange(Sender: TObject);
procedure SimContestComboPopulate;
procedure ExchangeEditExit(Sender: TObject);
procedure Edit4Exit(Sender: TObject);

Expand Down Expand Up @@ -452,6 +453,9 @@ procedure TMainForm.FormCreate(Sender: TObject);
ListView2.Visible:= False;
ListView2.Clear;

// populate and sort SimContestCombo
SimContestComboPopulate;

// load DXCC support
gDXCCList := TDXCC.Create;

Expand Down Expand Up @@ -890,7 +894,8 @@ procedure TMainForm.SetContest(AContestNum: TSimContest);
scCQWW]) then
begin
ShowMessage('The selected contest is not yet supported.');
SimContestCombo.ItemIndex:= Ord(Ini.SimContest);
SimContestCombo.ItemIndex :=
SimContestCombo.Items.IndexOf(ActiveContest.Name);
Exit;
end;

Expand All @@ -903,7 +908,8 @@ procedure TMainForm.SetContest(AContestNum: TSimContest);

Ini.SimContest := AContestNum;
Ini.ActiveContest := @ContestDefinitions[AContestNum];
SimContestCombo.ItemIndex := Ord(AContestNum);
SimContestCombo.ItemIndex :=
SimContestCombo.Items.IndexOf(Ini.ActiveContest.Name);
WipeBoxes;

// clear any status messages
Expand Down Expand Up @@ -1260,7 +1266,18 @@ procedure TMainForm.SetBw(BwNo: integer);

procedure TMainForm.SimContestComboChange(Sender: TObject);
begin
SetContest(TSimContest(SimContestCombo.ItemIndex));
SetContest(FindContestByName(SimContestCombo.Items[SimContestCombo.ItemIndex]));
end;

{ add contest names to SimContest Combo box and sort }
procedure TMainForm.SimContestComboPopulate;
var
C: TContestDefinition;
begin
SimContestCombo.Items.Clear;
for C in ContestDefinitions do
SimContestCombo.Items.Add(C.Name);
SimContestCombo.Sorted:= True;
end;

procedure TMainForm.ComboBox2Change(Sender: TObject);
Expand Down