The refactoring is almost complete:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4TfeTE8Y_LnR2lRWPIl3Dq6-xhxyAXgP41S9DC3pEac70i3uw1EgcfssZeS6TOwD9O-Zr6e6QQLFeeRYdbK2XxIdpSaEurNOSF3d-8RV7ZV2YF8YeNITKHFGVIN-cCx-pA22dtROsBwwc/s400/refactoringprogress5.png)
The only major source code left to refactor is UnitDisplay.pas which, as the name suggests, is, contains the code that interfaces with the screen and the GUI-handling code. Its about 4000 lines of code. I'm on target to finish the refactor within the week or so.
Its a messy unit, full of code like this:
I'm not coding C, so there's no virtue in conciseness. The refactor turns that code into this (note that some of the indenting may not display properly, but the final code is indented properly):Procedure TFormDisplay.ListViewMonstersCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
begin
if ListViewMonsters.Items.Count = 0 then Compare := 0
else
begin
if (StrToInt(Item1.SubItems[6])) > (StrToInt(Item1.SubItems[6])) then Compare := 1
else if (StrToInt(Item1.SubItems[6])) = (StrToInt(Item1.SubItems[6])) then Compare := 0
else Compare := -1;
end;
end;
{ Sort Routine to sort entries in the Visible Monsters display - compares two
TListItems and returns a comparison based upon TMonster.Level }
Procedure TFormDisplay.ListViewMonstersCompare(Sender: TObject; Item1,Item2: TListItem; Data: Integer; var Compare: Integer);
var
FirstItemLevel: Integer;
SecondItemLevel: Integer;
begin
{ Logging }
hLog.Add('{now} {lNum} TFormDisplay.ListViewMonstersCompare()');
{ Default result which is that both items are equal}
Result := 0;
try
{ Make sure there are items to compare }
if ListViewMonsters.Items.Count > 0 then
begin
{ Get the monster levels from the Listview Items }
FirstItemLevel := StrToIntDef(Item1.SubItems[MONSTER_LEVEL], 0);
SecondItemLevel := StrToIntDef(Item2.SubItems[MONSTER_LEVEL], 0);
{ Compare the Monster Levels of each items }
{ First > Second }
if FirstItemLevel > SecondItemLevel then
Compare := 1
{ First <>
else if FirstItemLevel < style="font-weight: bold; color: rgb(0, 0, 102);">) then
Compare := -1;
end;
except
{ in case of error, log the Exception }
on E: Exception do hLog.AddException(E);
end;
end;
No comments:
Post a Comment