obj= clRest.Response kodu çalışmaz çünkü response bir string bu yüzden JSON parse etmek gerekiyor.
GetShiftTypes da API'ye get isteğini gönderdik (async ile)
GetShiftTypesCompleted ile response geldiğin de çağırdık ve
Json response pars ettik
array içinde ki her eleman için shift_name değerini alıp comboboxa ekledik.
Kendi basuURL API'ni değiştirip dener misin?
var
MainForm: TClForm;
clRest: TclRest;
Combo1: TCLComboBox;
GetShiftBtn: TClProButton;
void GetShiftTypesCompleted
var
jsonResponse: String;
shiftName: String;
shiftId: String;
i: Integer;
{
Try
jsonResponse = clRest.Response;
// ComboBox'ı temizle
Combo1.Items.Clear;
// Array içindeki her eleman için shift_name'i al ve ComboBox'a ekle
i = 0;
while (True)
{
// Array elemanlarına erişim: "0.shift_name", "1.shift_name", vb.
shiftName = Clomosy.CLParseJSON(jsonResponse, IntToStr(i) + '.shift_name');
if (shiftName == '')
{
break;
}
// shift_id'yi de al (isteğe bağlı)
shiftId = Clomosy.CLParseJSON(jsonResponse, IntToStr(i) + '.shift_id');
// ComboBox'a shift_name'i ekle
Combo1.Items.Add(shiftName);
i = i + 1;
}
if (i > 0)
{
ShowMessage(IntToStr(i) + ' vardiya tipi başarıyla yüklendi.');
}
else
{
ShowMessage('Vardiya tipi bulunamadı veya JSON formatı hatalı.');
}
except
ShowMessage('Hata: ' + LastExceptionClassName + ' - ' + LastExceptionMessage);
}
}
void GetShiftTypes
{
clRest.BaseURL = 'http://BENIM_UZANTIM/shifttypes';
clRest.Accept = 'application/json';
clRest.Method = rmGET;
clRest.OnCompleted = 'GetShiftTypesCompleted';
clRest.ExecuteAsync;
}
{
MainForm = TClForm.Create(Self);
Combo1 = MainForm.AddNewComboBox(MainForm, 'Combo1');
Combo1.Align = alTop;
Combo1.Height = 50;
Combo1.Margins.Top = 20;
Combo1.Margins.Left = 20;
Combo1.Margins.Right = 20;
GetShiftBtn = MainForm.AddNewProButton(MainForm, 'GetShiftBtn', 'Vardiya Tiplerini Yükle');
GetShiftBtn.Align = alTop;
GetShiftBtn.Height = 50;
GetShiftBtn.Margins.Top = 10;
GetShiftBtn.Margins.Left = 20;
GetShiftBtn.Margins.Right = 20;
GetShiftBtn.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#3498DB');
GetShiftBtn.clProSettings.FontColor = clAlphaColor.clHexToColor('#FFFFFF');
GetShiftBtn.clProSettings.FontSize = 16;
GetShiftBtn.clProSettings.FontVertAlign = palcenter;
GetShiftBtn.clProSettings.FontHorzAlign = palcenter;
GetShiftBtn.clProSettings.RoundHeight = 8;
GetShiftBtn.clProSettings.RoundWidth = 8;
GetShiftBtn.SetclProSettings(GetShiftBtn.clProSettings);
MainForm.AddNewEvent(GetShiftBtn, tbeOnClick, 'GetShiftTypes');
clRest = TclRest.Create;
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">
< defer="" ="https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28on72PdrCzSjY4U6VaAw1EQ==" -cf-beacon=""version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"_timing":"name":"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true,"location_startswith":null" crossorigin="anonymous">