Advertisement
Guest User

Untitled

a guest
Jul 8th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.75 KB | None | 0 0
  1. type
  2.   TCEItem= class
  3.   public
  4.     RowName: String;
  5.     Name: String;
  6.     MaxStackSize: FixedUInt;
  7.     CompatableAmmunitions: array of FixedUInt;
  8.     KnockbackResponseWeapon: Boolean;
  9.     EncumbranceWeight: Single;
  10.     ...
  11.   end;
  12.  
  13. procedure TForm1.Button3Click(Sender: TObject);
  14. var
  15.   CEItemList: TList<TCEItem>;
  16.   CEItem: TCEItem;
  17.   JMain: TJSONArray;
  18.   JItem: TJSONValue;
  19.   Index: Integer;
  20. ...
  21. begin
  22. ...
  23.   CEItemList:= TList<TCEItem>.Create();
  24.   try
  25.     // Add 2 objects to the list for testing purpouse
  26.     CEItem:= TCEItem.Create;
  27.     CEItem.RowName:= 'RowName 0';
  28.     CEItem.Name:= 'Name 0';
  29.     CEItem.MaxStackSize:= 6543;
  30.     CEItem.KnockbackResponseWeapon:= True;
  31.     CEItem.EncumbranceWeight:= 23.46;
  32.     SetLength(CEItem.CompatableAmmunitions, 3);
  33.     CEItem.CompatableAmmunitions[0]:= 50;
  34.     CEItem.CompatableAmmunitions[1]:= 60;
  35.     CEItem.CompatableAmmunitions[2]:= 70;
  36.     CEItemList.Add(CEItem);
  37.  
  38.     CEItem:= TCEItem.Create;
  39.     CEItem.RowName:= 'RowName 1';
  40.     CEItem.Name:= 'Name 1';
  41.     CEItem.MaxStackSize:= 3456;
  42.     CEItem.KnockbackResponseWeapon:= False;
  43.     CEItem.EncumbranceWeight:= 10.46;
  44.     SetLength(CEItem.CompatableAmmunitions, 3);
  45.     CEItem.CompatableAmmunitions[0]:= 10;
  46.     CEItem.CompatableAmmunitions[1]:= 20;
  47.     CEItem.CompatableAmmunitions[2]:= 30;
  48.     CEItemList.Add(CEItem);
  49.  
  50.     // Create the main array
  51.     JMain:= TJSONArray.Create;
  52.     try
  53.       // Add items objects to the main array
  54.       for Index := 0 to CEItemList.Count-1 do
  55.       begin
  56.         JMain.Add(TJson.ObjectToJsonString(CEItemList.Items[Index]));
  57.       end;
  58.  
  59.       formJSON.Lines.Text := JMain.ToJSON; // convert to a JSON string
  60.  
  61.     finally
  62.       JMain.Free;
  63.     end;
  64.  
  65.   finally
  66.     CEItemList.Free;
  67.   end;
  68. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement