Changeset 285 for trunk/UNation.pas


Ignore:
Timestamp:
Mar 10, 2019, 11:57:03 PM (6 years ago)
Author:
chronos
Message:
  • Modified: More work on item class with defined form fields.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UNation.pas

    r284 r285  
    66
    77uses
    8   Classes, SysUtils, fgl, DOM, UXMLUtils, Graphics, UItemList;
     8  Classes, SysUtils, DOM, UXMLUtils, Graphics, UItemList;
    99
    1010type
     
    1717    procedure GetValue(Index: Integer; out Value); override;
    1818    procedure SetValue(Index: Integer; var Value); override;
    19     procedure Assign(Source: TItem); override;
    20     procedure LoadFromNode(Node: TDOMNode); override;
    21     procedure SaveToNode(Node: TDOMNode); override;
     19    class function GetClassSysName: string; override;
    2220  end;
    2321
     
    2523
    2624  TNations = class(TItemList)
    27     function GetItemClass: TItemClass; override;
    28     procedure LoadFromNode(Node: TDOMNode);
    29     procedure SaveToNode(Node: TDOMNode);
    30     constructor Create(FreeObjects: Boolean = True);
     25    class function GetItemClass: TItemClass; override;
    3126  end;
    3227
     
    4439function TNation.GetFields: TItemFields;
    4540begin
    46   inherited;
    47   Result.AddField('Name');
    48   Result.AddField('Color');
     41  Result := inherited;
     42  Result.AddField(2, 'Color', 'Color', dtColor);
    4943end;
    5044
    5145procedure TNation.GetValue(Index: Integer; out Value);
    5246begin
    53   if Index = 0 then string(Value) := Name
    54   else if Index = 1 then TColor(Value) := Color
     47  if Index = 1 then string(Value) := Name
     48  else if Index = 2 then TColor(Value) := Color
    5549  else raise Exception.Create('Unsupported value index ' + IntToStr(Index));
    5650end;
     
    5852procedure TNation.SetValue(Index: Integer; var Value);
    5953begin
    60   if Index = 0 then Name := string(Value)
    61   else if Index = 1 then Color := TColor(Value)
     54  if Index = 1 then Name := string(Value)
     55  else if Index = 2 then Color := TColor(Value)
    6256  else raise Exception.Create('Unsupported value index ' + IntToStr(Index));
    6357end;
    6458
    65 procedure TNation.Assign(Source: TItem);
     59class function TNation.GetClassSysName: string;
    6660begin
    67   inherited;
    68   Color := TNation(Source).Color;
    69 end;
    70 
    71 procedure TNation.LoadFromNode(Node: TDOMNode);
    72 begin
    73   inherited;
    74   Color := ReadInteger(Node, 'Color', 0);
    75 end;
    76 
    77 procedure TNation.SaveToNode(Node: TDOMNode);
    78 begin
    79   inherited;
    80   WriteInteger(Node, 'Color', Color);
     61  Result := 'Nation';
    8162end;
    8263
    8364{ TNations }
    8465
    85 function TNations.GetItemClass: TItemClass;
     66class function TNations.GetItemClass: TItemClass;
    8667begin
    8768  Result := TNation;
    8869end;
    8970
    90 procedure TNations.LoadFromNode(Node: TDOMNode);
    91 var
    92   Node2: TDOMNode;
    93   NewItem: TNation;
    94 begin
    95   Count := 0;
    96   Node2 := Node.FirstChild;
    97   while Assigned(Node2) and (Node2.NodeName = 'Nation') do begin
    98     NewItem := TNation.Create;
    99     NewItem.LoadFromNode(Node2);
    100     Add(NewItem);
    101     Node2 := Node2.NextSibling;
    102   end;
    103 end;
    104 
    105 procedure TNations.SaveToNode(Node: TDOMNode);
    106 var
    107   I: Integer;
    108   NewNode2: TDOMNode;
    109 begin
    110   for I := 0 to Count - 1 do
    111   with Items[I] do begin
    112     NewNode2 := Node.OwnerDocument.CreateElement('Nation');
    113     Node.AppendChild(NewNode2);
    114     SaveToNode(NewNode2);
    115   end;
    116 end;
    117 
    118 constructor TNations.Create(FreeObjects: Boolean);
    119 begin
    120   inherited;
    121 end;
    122 
    12371end.
    12472
Note: See TracChangeset for help on using the changeset viewer.