Sayfayı Yazdır | Pencereyi Kapat

Json yapısında Getitem kullanımı

Nereden Yazdırıldığı: Clomosy | Forum
Kategori: Genel Programlama
Forum Adı: Clomosy ile değişken kullanımı
Forum Tanımlaması: TRObject dili ile değişken tanımlaması ve ekranda gösterme
URL: https://forum.clomosy.com.tr/forum_posts.asp?TID=1241
Tarih: 09 Aralık 2025 Saat 18:56
Program Versiyonu: Web Wiz Forums 12.07 - https://www.webwizforums.com


Konu: Json yapısında Getitem kullanımı
Mesajı Yazan: M-Guney
Konu: Json yapısında Getitem kullanımı
Mesaj Tarihi: 09 Aralık 2025 Saat 13:59
Get item ile aldığım item üzerinde değişiklik yapmak istiyorum fakat yapamıyorum

var
  MainForm: TclForm;

void TestUpdateJsonValue;
var
  OrderListArrRef: TCLJSONArray;
  ExistingItem: TCLJSONObject;
  J, TargetItemID, NewAmount, FoundIndex: Integer;
{
  try
    // 1. Setup: Create a sample JSON Array
    OrderListArrRef = TCLJSONArray.CreateFromJSON('[{"item_id": 27, "amount": 4}, {"item_id": 13, "amount": 1}]');
    
    // 2. Define Test Data
    TargetItemID = 27;  // We want to change item 27
    NewAmount = 99;     // We want to change amount from 4 to 99
    FoundIndex = -1;

    ShowMessage('Before Update: ' + OrderListArrRef.ToJSONString);

    // 3. Logic: Loop to find and update
    for (J = 0 to OrderListArrRef.Count - 1)
    {
      ExistingItem = OrderListArrRef.GetItem(J);
      
      // Check if IDs match
      if (ExistingItem.GetValueByPath('item_id').AsInteger == TargetItemID )
      {
        // --- First Remove After AddPair ---
        ShowMessage('ExistingItem before changing amount: '+ExistingItem.ToString)
        //ExistingItem.RemovePair('amount');                  // Remove old value
        //ExistingItem.AddPair('amount', TCLJSONValue.Int(NewAmount)); // Add new value
        // ---------------------
        // SetValue Clause
        //ShowMessage(ExistingItem.ToJsonString)
        ExistingItem.SetValue('amount', TCLJSONValue.Int(NewAmount)); // Add new value
        ShowMessage('ExistingItem: '+ExistingItem.ToString)
        
        FoundIndex = J;
        Break; // Optimization: Stop once found
      }
    }

    // 4. Verification
    if (FoundIndex > -1 )
      ShowMessage('After Update:  ' + OrderListArrRef.ToJSONString)
    else
      ShowMessage('Error: Item ID ' + IntToStr(TargetItemID) + ' not found.');

  except
    ShowMessage('Exception: ' + LastExceptionMessage);
  }
}

{
  MainForm = TclForm.Create(Self);
  TestUpdateJsonValue; // Run the test
  MainForm.Run;
}
https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">



Cevaplar:
Mesajı Yazan: M-Guney
Mesaj Tarihi: 09 Aralık 2025 Saat 14:05
Benden kaynaklı mı yoksa Bir güncellem nedeniyle mi bozuldu bilmiyorum fakat doğru hatırlıyorsam dün setvalue işlemim çalışıyordu şuanda ise herhangi bir değişiklik yapmıyor.
  https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">
Herhangi bir değişiklik yapmak istesem getItem ile alınmış obje üzerinde herhangi bir değişiklik yapamıyorum.


Mesajı Yazan: Emr.Erkmn
Mesaj Tarihi: 09 Aralık 2025 Saat 15:25
Merhaba Güney, 
Kodu çalıştırdığın zaman ShowMessage'larından dışında herhangi bir hata mesajı alıyor musun https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">


Mesajı Yazan: M-Guney
Mesaj Tarihi: 09 Aralık 2025 Saat 15:27
Hayır hata mesajı gelmiyor fakat herhangi bir değişiklikte yapamıyorum https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">



Mesajı Yazan: Emr.Erkmn
Mesaj Tarihi: 09 Aralık 2025 Saat 15:28
Kendim bir kaç deneme yaptığım da 
ShowMessage('Error: Item ID ' + IntToStr(TargetItemID) + ' not found.'); 

hata mesajını alıyorum 



https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">


Mesajı Yazan: M-Guney
Mesaj Tarihi: 09 Aralık 2025 Saat 15:33
nasıl olabilir anlayamadım tam olarak çünkü TargetItemID ye göre bir kıyaslama yapıyorum ve benim hem pc de hem de mobilde yani hata vermeden çalışıyor https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">




Sayfayı Yazdır | Pencereyi Kapat

Forum Software by Web Wiz Forums® version 12.07 - https://www.webwizforums.com
Copyright ©2001-2024 Web Wiz Ltd. - https://www.webwiz.net