Changeset 290 for trunk/GameServer.pas


Ignore:
Timestamp:
Feb 26, 2021, 11:56:48 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Use FreeAndNil instead of Free as defensive measure.
  • Modified: Use ihnerited without same method name specification.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GameServer.pas

    r288 r290  
    77
    88uses
    9   Protocol, Database, dynlibs, Platform, dateutils, fgl, LazFileUtils, Graphics;
     9  Protocol, Database, dynlibs, Platform, dateutils, fgl, LazFileUtils,
     10  Graphics;
    1011
    1112const
     
    289290        FreeLibrary(hm);
    290291    end;
    291   PlayersBrain.Free;
    292   bix.Free;
    293   Brains.Free;
     292  FreeAndNil(PlayersBrain);
     293  FreeAndNil(bix);
     294  FreeAndNil(Brains);
    294295end;
    295296
     
    561562  MapFile := TFileStream.Create(GetMapsDir + DirectorySeparator + FileName,
    562563    fmCreate or fmShareExclusive);
    563   MapFile.Position := 0;
    564   s := 'cEvoMap'#0;
    565   MapFile.write(s[1], 8); { file id }
    566   i := 0;
    567   MapFile.write(i, 4); { format id }
    568   MapFile.write(MaxTurn, 4);
    569   MapFile.write(lx, 4);
    570   MapFile.write(ly, 4);
    571   MapFile.write(RealMap, MapSize * 4);
    572   MapFile.Free;
     564  try
     565    MapFile.Position := 0;
     566    s := 'cEvoMap'#0;
     567    MapFile.write(s[1], 8); { file id }
     568    i := 0;
     569    MapFile.write(i, 4); { format id }
     570    MapFile.write(MaxTurn, 4);
     571    MapFile.write(lx, 4);
     572    MapFile.write(ly, 4);
     573    MapFile.write(RealMap, MapSize * 4);
     574  finally
     575    FreeAndNil(MapFile);
     576  end;
    573577end;
    574578
     
    613617      result := true;
    614618    end;
    615     MapFile.Free;
     619    FreeAndNil(MapFile);
    616620  except
    617621    if MapFile <> nil then
    618       MapFile.Free;
     622      FreeAndNil(MapFile);
    619623  end;
    620624end;
     
    694698  else
    695699    CL.SaveToFile(LogFile);
    696   LogFile.Free;
     700  FreeAndNil(LogFile);
    697701  if auto then
    698702  begin
     
    721725        Brains.GetByKind(btAI, AIBrains);
    722726        bix[p1] := AIBrains[DelphiRandom(AIBrains.Count)];
    723         AIBrains.Free;
     727        FreeAndNil(AIBrains);
    724728      end
    725729    else
     
    992996  CityProcessing.ReleaseGame;
    993997  Database.ReleaseGame;
    994   CL.Free;
     998  FreeAndNil(CL);
    995999end;
    9961000
     
    11901194    CL.LoadFromFile(LogFile);
    11911195  end;
    1192   LogFile.Free;
     1196  FreeAndNil(LogFile);
    11931197  if not result then
    11941198    Exit;
     
    46044608begin
    46054609  FreeAndNil(Picture);
    4606   inherited Destroy;
     4610  inherited;
    46074611end;
    46084612
Note: See TracChangeset for help on using the changeset viewer.