Sayfayı Yazdır | Pencereyi Kapat

SQLite veri çekme

Nereden Yazdırıldığı: Clomosy | Forum
Kategori: Genel Programlama
Forum Adı: Genel İşlemler
Forum Tanımlaması: TRObject dili ile programlama yaparken karşılaşılan genel işlemler
URL: https://forum.clomosy.com.tr/forum_posts.asp?TID=1148
Tarih: 30 Temmuz 2025 Saat 06:07
Program Versiyonu: Web Wiz Forums 12.07 - https://www.webwizforums.com


Konu: SQLite veri çekme
Mesajı Yazan: goksuselvi
Konu: SQLite veri çekme
Mesaj Tarihi: 29 Temmuz 2025 Saat 10:19

İLK SAYFA KODUM/////////////////////////////////////////////////////////////////////////7
var   
  MyForm: TclForm;
  MainPnl, habit1pnl, ustPanel,baslik1pnl,secimPanel,mypanel: TclProPanel;
  butonlar: array[0..31] of TClProButton;
  i, j: Integer;
  baslik1btn:TClProButton;
  gunSayisi, ilkGun, haftalikIndex: Integer;
  hedefSatir: TclProPanel;
  gunler: array[0..6] of String;
  gunEtiketleri: array[0..6] of TclProLabel;
  vScroll: TClVertScrollBox;
  aylar: array[0..11] of String;
  ayLabel: TClProLabel;
  satir1Label, satir1, satir2, satir3, satir4, satir5, satir6: TclProPanel;
  yilbaslik:tclprolabel;
  elimage:tclproimage;
  secimaliskanlikbtn1,secimaliskanlikbtn2,secimaliskanlikbtn3,secimaliskanlikbtn4:TClProButton;
  Imagecircle,Imagecircle2,Imagecircle3,Imagecircle4:tclproimage;
  secimkapatbtn:TClProButton;
  mybuton1,mybuton2,mybuton3,mybuton4:TClProButton;
  gunIndex, satirIndex: Integer;
  bosLabel: TclProLabel;
  habitbaslik:tclprolabel;
  habitQuery: TClSQLiteQuery;
  gelenHabitAdi: String;
  habitId: Integer
  
   void mybuton3click
  {
    Clomosy.RunUnit('mybuton3');
  }


   void mybuton4click
  {
    Clomosy.RunUnit('mybuton4');
  }

  
  
 void HabitNameGetir
{
  try {
    Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBHabits.db3', '');

    habitQuery = Clomosy.DBSQLiteQueryWith(
      'SELECT habitName FROM Habits WHERE habitId = ' + IntToStr(habitId)
    );
    habitQuery.OpenOrExecute;
    ShowMessage('Seçilen habitId: ' + IntToStr(habitId));
    if (habitQuery.Found) {
      gelenHabitAdi = habitQuery.FieldByName('habitName').AsString;
      ShowMessage('Alınan Alışkanlık Adı: ' + gelenHabitAdi);
    }
    else {
      ShowMessage('Alışkanlık bulunamadı.');
    }
  }
  except {
    ShowMessage('Veri alınırken hata: ' + LastExceptionMessage);
  }
}  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  void aliskanlikclick
  
  {
    secimpanel.Visible = not secimpanel.Visible;
  }
  
  
    function GunSayisi(ay: Integer; yil: Integer): Integer
  {
    if ((ay == 1) || (ay == 3) || (ay == 5) || (ay == 7) || (ay == 8) || (ay == 10) || (ay == 12))
      Result = 31
    else if ((ay == 4) || (ay == 6) || (ay == 9) || (ay == 11))
      Result = 30
    else if (ay == 2)
    {
      if ((yil mod 4 == 0) && ((yil mod 100 <> 0) || (yil mod 400 == 0)))
        Result = 29
      else
        Result = 28
    }
    else
      Result = 0 // Hatalı ay için
  }
  
  function AyIlkGunuHaftaninKaci(ay: Integer; yil: Integer): Integer
    var 
    d, m, y, k, j, h,gun: Integer
{

  d = 1
  if ay < 3
  {
    ay = ay + 12
    yil = yil - 1
  }

  m = ay
  y = yil mod 100
  j = yil div 100

  h = (d + (13*(m + 1)) div 5 + y + (y div 4) + (j div 4) + 5*j) mod 7
  // Zeller algoritmasında 0=Cumartesi, 1=Pazar, 2=Pazartesi, ...
  // Bizim dizimizde 0=Pazartesi, 6=Pazar. Uyum için aşağıdaki dönüşü kullanıyoruz:
  gun = (h + 5) mod 7 // 0=Pazartesi, 6=Pazar olacak şekilde
  Result = gun
}

void TakvimCiz(ay,yil: Integer)
var
  gunSayisi, ilkGun, i, haftalikIndex: Integer;
  hedefSatir: TclProPanel;
  gunEtiketi: TclProLabel;
{
  gunSayisi = GunSayisi(ay, yil)
  ilkGun = AyIlkGunuHaftaninKaci(ay, yil)

  for i = 0 to gunSayisi - 1
  {
    haftalikIndex = i + ilkGun - 1

    if (haftalikIndex < 7)  
     hedefSatir = satir1
    else if (haftalikIndex < 14)  
    hedefSatir = satir2
    else if (haftalikIndex < 21)  
    hedefSatir = satir3
    else if (haftalikIndex < 28)  
    hedefSatir = satir4
    else 
    hedefSatir = satir5

    gunEtiketi = MyForm.AddNewProLabel(
      hedefSatir,
      'lblGun_' + IntToStr(ay) + '_' + IntToStr(i + 1),
      IntToStr(i + 1)
    )

    gunEtiketi.Align = alRight
    gunEtiketi.Margins.Right = 18
    gunEtiketi.Margins.Left = 3
    gunEtiketi.Width = 30
    gunEtiketi.clProSettings.FontSize = 14
    gunEtiketi.clProSettings.FontColor = clAlphaColor.clHexToColor('#000000')
    gunEtiketi.clProSettings.FontVertAlign = palLeading
    gunEtiketi.clProSettings.FontHorzAlign = palcenter
    gunEtiketi.SetclProSettings(gunEtiketi.clProSettings)
  }
}

  
{
  MyForm = TclForm.Create(Self);

  MainPnl = myForm.AddNewProPanel(myForm, 'MainPnl');
  MainPnl.Align = alClient;
  
  MainPnl.Align=alCenter;
  MainPnl.Height=630;
  MainPnl.Width=400;
  MainPnl.clProSettings.RoundHeight=40;
  MainPnl.clProSettings.Roundwidth=40;
  MainPnl.clProSettings.IsTransparent =False;
  MainPnl.SetclProSettings(MainPnl.clProSettings); 
  

  habit1pnl = MyForm.AddNewProPanel(MainPnl, 'habit1pnl');
  habit1pnl.Align = alClient;
  habit1pnl.SetclProSettings(habit1pnl.clProSettings);
   
  baslik1pnl = MyForm.AddNewProPanel(habit1pnl, 'baslik1pnl');
  baslik1pnl.Align = alTop;
  baslik1pnl.Margins.left=11;
  baslik1pnl.Height = 100;
  baslik1pnl.width = 200;
  baslik1pnl.clProSettings.BorderColor = clAlphaColor.clHexToColor('#cccccc');
  baslik1pnl.clProSettings.BorderWidth = 1;
  baslik1pnl.SetclProSettings(baslik1pnl.clProSettings);
   

  
  yilbaslik = myform.AddNewProLabel(baslik1pnl,'yilbaslik','YILLIK ALIŞKANLIK TAKİBİ');
  yilbaslik.Align = altop;
  yilbaslik.margins.left=60;
  yilbaslik.Width = 300;
  yilbaslik.Height = 30;
  yilbaslik.clProSettings.FontColor = clAlphaColor.clHexToColor('#000000');
  yilbaslik.clProSettings.FontSize = 20;
  yilbaslik.clProSettings.FontVertAlign = palcenter;
  yilbaslik.clProSettings.FontHorzAlign = palLeading;
  yilbaslik.clProSettings.TextSettings.Font.Style = [fsBold];
  yilbaslik.clProSettings.IsFill = True; 
  yilbaslik.clProSettings.IsRound = True;
 yilbaslik.SetclProSettings(yilbaslik.clProSettings);
  
  habitbaslik = myform.AddNewProLabel(baslik1pnl,'habitbaslik','ALIŞKANLIK:');
  habitbaslik.Align = alcenter;
  habitbaslik.margins.left=210;
  habitbaslik.margins.right=30;
  habitbaslik.Width = 300;
  habitbaslik.Height = 30;
  habitbaslik.clProSettings.FontColor = clAlphaColor.clHexToColor('#000000');
  habitbaslik.clProSettings.FontSize = 15;
  habitbaslik.clProSettings.FontVertAlign = palcenter;
  habitbaslik.clProSettings.FontHorzAlign = palLeading;
  habitbaslik.clProSettings.TextSettings.Font.Style = [fsBold];
  habitbaslik.clProSettings.IsFill = True; 
  habitbaslik.clProSettings.IsRound = True;
 habitbaslik.SetclProSettings(habitbaslik.clProSettings);
  
  
  
   
   
  baslik1btn = MyForm.AddNewProButton(baslik1pnl, 'baslik1btn', 'Alışkanlıklar');
  baslik1btn.Align = alcenter;
  baslik1btn.Width = 100;
  baslik1btn.Height = 50;
  baslik1btn.Margins.Right = 240;
  baslik1btn.clProSettings.IsRound = True;
  baslik1btn.clProSettings.FontSize = 14;
  baslik1btn.clProSettings.BorderColor = clAlphaColor.clHexToColor('#ea9eff');
  baslik1btn.clProSettings.BorderWidth = 2;
  baslik1btn.SetclProSettings(baslik1btn.clProSettings);
  MyForm.AddNewEvent(baslik1btn, tbeOnClick, 'aliskanlikclick');
 ////////////////////////////////////////////////////////////////////////////////
  secimPanel=MyForm.AddNewProPanel(MainPnl,'secimPanel');
  secimPanel.Align = AlCenter;
  secimpanel.margins.right=170;
  secimpanel.margins.bottom=200;
  secimPanel.Width = 200;
  secimPanel.Height =250;
  secimPanel.clProSettings.IsRound = True;
 secimPanel.visible=false;
 secimPanel.SetclProSettings(secimPanel.clProSettings);
 
 
  secimaliskanlikbtn1 = MyForm.AddNewProButton(secimPanel, 'secimaliskanlikbtn1', 'Alışkanlık1');
  secimaliskanlikbtn1.Align = altop;
  secimaliskanlikbtn1.margins.top=40;
  secimaliskanlikbtn1.Width = 100;
  secimaliskanlikbtn1.Height = 50;
  secimaliskanlikbtn1.clProSettings.IsRound = True;
  secimaliskanlikbtn1.clProSettings.FontSize = 14;
  secimaliskanlikbtn1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#ea9eff');
  secimaliskanlikbtn1.clProSettings.BorderWidth = 2;
  secimaliskanlikbtn1.SetclProSettings(secimaliskanlikbtn1.clProSettings);
 
 secimaliskanlikbtn2 = MyForm.AddNewProButton(secimPanel, 'secimaliskanlikbtn2', 'Alışkanlık2');
  secimaliskanlikbtn2.Align = altop;
  secimaliskanlikbtn2.margins.top=5;
  secimaliskanlikbtn2.Width = 100;
  secimaliskanlikbtn2.Height = 50;
  secimaliskanlikbtn2.clProSettings.IsRound = True;
  secimaliskanlikbtn2.clProSettings.FontSize = 14;
  secimaliskanlikbtn2.clProSettings.BorderColor = clAlphaColor.clHexToColor('#ea9eff');
  secimaliskanlikbtn2.clProSettings.BorderWidth = 2;
  secimaliskanlikbtn2.SetclProSettings(secimaliskanlikbtn2.clProSettings);
 
 secimaliskanlikbtn3 = MyForm.AddNewProButton(secimPanel, 'secimaliskanlikbtn3', 'Alışkanlık3');
  secimaliskanlikbtn3.Align = altop;
  secimaliskanlikbtn3.margins.top=5;
  secimaliskanlikbtn3.Width = 100;
  secimaliskanlikbtn3.Height = 50;
  secimaliskanlikbtn3.clProSettings.IsRound = True;
  secimaliskanlikbtn3.clProSettings.FontSize = 14;
  secimaliskanlikbtn3.clProSettings.BorderColor = clAlphaColor.clHexToColor('#ea9eff');
  secimaliskanlikbtn3.clProSettings.BorderWidth = 2;
  secimaliskanlikbtn3.SetclProSettings(secimaliskanlikbtn3.clProSettings);
 
 
 secimaliskanlikbtn4 = MyForm.AddNewProButton(secimPanel, 'secimaliskanlikbtn4', 'Alışkanlık4');
  secimaliskanlikbtn4.Align = altop;
  secimaliskanlikbtn4.margins.top=5;
  secimaliskanlikbtn4.Width = 100;
  secimaliskanlikbtn4.Height = 50;
  secimaliskanlikbtn4.clProSettings.IsRound = True;
  secimaliskanlikbtn4.clProSettings.FontSize = 14;
  secimaliskanlikbtn4.clProSettings.BorderColor = clAlphaColor.clHexToColor('#ea9eff');
  secimaliskanlikbtn4.clProSettings.BorderWidth = 2;
  secimaliskanlikbtn4.SetclProSettings(secimaliskanlikbtn4.clProSettings);
 
 Imagecircle = myForm.AddNewProImage(secimaliskanlikbtn1, 'Imagecircle');
 Imagecircle.Align = alcenter;
 Imagecircle.margins.right=100;
 Imagecircle.margins.top=5;
 Imagecircle.Width = 25;
 Imagecircle.Height = 24;
 myForm.SetImage(Imagecircle, 'https://i.imgur.com/c7vyHfU.png');
 
  Imagecircle2 = myForm.AddNewProImage(secimaliskanlikbtn2, 'Imagecircle2');
  Imagecircle2.Align = alcenter;
  Imagecircle2.margins.right=100;
  Imagecircle2.margins.top=5;
  Imagecircle2.Width = 25;
  Imagecircle2.Height = 24;
  myForm.SetImage(Imagecircle2, 'https://i.imgur.com/c7vyHfU.png'); 
  
  Imagecircle3= myForm.AddNewProImage(secimaliskanlikbtn3, 'Imagecircle3');
  Imagecircle3.Align = alcenter;
  Imagecircle3.margins.right=100;
  Imagecircle3.margins.top=5;
  Imagecircle3.Width = 25;
  Imagecircle3.Height = 24;
  myForm.SetImage(Imagecircle3, 'https://i.imgur.com/c7vyHfU.png'); 
  
 
 
  Imagecircle4 = myForm.AddNewProImage(secimaliskanlikbtn4, 'Imagecircle4');
  Imagecircle4.Align = alcenter;
  Imagecircle4.margins.right=100;
  Imagecircle4.margins.top=5;
  Imagecircle4.Width = 25;
  Imagecircle4.Height = 24;
  myForm.SetImage(Imagecircle4, 'https://i.imgur.com/c7vyHfU.png'); 
  
 ///////////////////////////////////////////////////////////////////////////////7
 
 
  elImage = myForm.AddNewProImage(baslik1pnl, 'elImage');
  elImage.Align = alcenter;
  elimage.margins.right=140;
  elImage.margins.top=25;
  elImage.Width = 22;
  elImage.Height = 24;
  myForm.SetImage(elImage, 'https://i.imgur.com/4bxFXAo.png');
  
 
   
 //////////////////////////////////////////////////////////////////////////////////////7
  vScroll = MyForm.AddNewVertScrollBox(habit1pnl, 'vScroll');
  vScroll.Align = alClient;

 
  aylar = ['Ocak','Şubat','Mart','Nisan','Mayıs','Haziran','Temmuz','Ağustos','Eylül','Ekim','Kasım','Aralık'];

  
  for (j = 0 to 11) {
    // döngü içinde var tanımı kaldırıldı
    ustPanel = MyForm.AddNewProPanel(vScroll, 'ustPanel' + IntToStr(j));
    ustPanel.Align = alTop;
    ustPanel.Width = vScroll.Width;
    ustPanel.Margins.Left = 0;
    ustPanel.Margins.Right = 0;
    ustPanel.Height = 400;
    ustPanel.Margins.Top = 10;
    ustPanel.clProSettings.RoundHeight = 10;
    ustPanel.clProSettings.RoundWidth = 10;
    ustPanel.clProSettings.BorderColor = clAlphaColor.clHexToColor('#cccccc');
    ustPanel.clProSettings.BorderWidth = 2;
    ustPanel.SetclProSettings(ustPanel.clProSettings);

    ayLabel = MyForm.AddNewProLabel(ustPanel, 'ayLabel' + IntToStr(j), aylar[j] + ', 2026');
    ayLabel.Align = alTop;
    aylabel.Margins.left=20;
    ayLabel.Height = 50;
    ayLabel.clProSettings.FontSize = 18;
    ayLabel.clProSettings.FontColor = clAlphaColor.clHexToColor('#000000');
    ayLabel.clProSettings.TextSettings.Font.Style = [fsBold];
    ayLabel.SetclProSettings(ayLabel.clProSettings);

    satir1Label = MyForm.AddNewProPanel(ustPanel, 'satir1Label' + IntToStr(j));
    satir1Label.Align = alTop;
    satir1Label.Height = 24;

    gunler = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
    for (i = 0 to 6) {
      gunEtiketleri = MyForm.AddNewProLabel(satir1Label, 'lblGun' + IntToStr(j) + '_' + IntToStr(i), gunler);
      gunEtiketleri.Align = alLeft;
      gunEtiketleri.Margins.left = 18;
      gunEtiketleri.Margins.right= 3;
      gunEtiketleri.Width = 30;
      gunEtiketleri.clProSettings.FontSize = 14;
      gunEtiketleri.clProSettings.FontColor = clAlphaColor.clHexToColor('#000000');
      gunEtiketleri.clProSettings.FontVertAlign = palLeading;
      gunEtiketleri.clProSettings.FontHorzAlign = palcenter;
      gunEtiketleri.SetclProSettings(gunEtiketleri.clProSettings);
    }

    // 6 satır paneli oluştur
    satir1 = MyForm.AddNewProPanel(ustPanel, 'satir1' + IntToStr(j)); satir1.Align = alTop; satir1.margins.left = 12; satir1.Height = 40;
    satir2 = MyForm.AddNewProPanel(ustPanel, 'satir2' + IntToStr(j)); satir2.Align = alTop; satir2.margins.left = 12; satir2.Height = 40;
    satir3 = MyForm.AddNewProPanel(ustPanel, 'satir3' + IntToStr(j)); satir3.Align = alTop; satir3.margins.left = 12; satir3.Height = 40;
    satir4 = MyForm.AddNewProPanel(ustPanel, 'satir4' + IntToStr(j)); satir4.Align = alTop; satir4.margins.left = 12; satir4.Height = 40;
    satir5 = MyForm.AddNewProPanel(ustPanel, 'satir5' + IntToStr(j)); satir5.Align = alTop; satir5.margins.left = 12; satir5.Height = 40;
    satir6 = MyForm.AddNewProPanel(ustPanel, 'satir6' + IntToStr(j)); satir6.Align = alTop; satir6.margins.left = 12; satir6.Height = 40;

    // Ayın gerçek gün sayısı ve ilk günü al
    gunSayisi = GunSayisi(j + 1, 2026);
    ilkGun = AyIlkGunuHaftaninKaci(j + 1, 2026); // 0: Pazartesi, 6: Pazar

    // İlk satırda, ilkGun kadar boş kutucuk ekle
    for (i = 0 to ilkGun - 1) {
      bosLabel = MyForm.AddNewProLabel(satir1, 'lblBos' + IntToStr(j) + '_' + IntToStr(i), '');
      bosLabel.Align = alLeft;
      bosLabel.Width = 45;
      bosLabel.Height = 32;
      bosLabel.Margins.Right = 2;
      bosLabel.Margins.Top = 4;
      bosLabel.Margins.Left = 4;
    }

    // Sonra günleri sırayla ekle
    for (i = 0 to gunSayisi - 1) {
      gunIndex = (i + ilkGun) mod 7; // 0: Pazartesi, 6: Pazar
      satirIndex = (i + ilkGun) div 7; // 0: ilk satır, 1: ikinci satır, ...

      if (satirIndex == 0) hedefSatir = satir1;
      else if (satirIndex == 1) hedefSatir = satir2;
      else if (satirIndex == 2) hedefSatir = satir3;
      else if (satirIndex == 3) hedefSatir = satir4;
      else if (satirIndex == 4) hedefSatir = satir5;
      else hedefSatir = satir6;

      butonlar = MyForm.AddNewProButton(hedefSatir, 'btn' + IntToStr(j) + '_' + IntToStr(i), IntToStr(i + 1));
      butonlar.Align = alLeft;
      butonlar.Margins.Right = 2;
      butonlar.Margins.Top = 4;
      butonlar.Margins.Left = 4;
      butonlar.Width = 45;
      butonlar.Height = 32;
      butonlar.clProSettings.PictureSource = 'https://i.imgur.com/exBB3ZA.png';
      butonlar.clProSettings.PictureAutoFit = true;
      butonlar.clProSettings.IsRound = true;
      butonlar.clProSettings.FontSize = 9;
      butonlar.clProSettings.FontColor = clAlphaColor.clHexToColor('#000000');
      butonlar.SetclProSettings(butonlar.clProSettings);
    }
  }
   
  mypanel=myForm.AddNewProPanel(MainPnl,'mypanel');
  mypanel.Align=alMostBottom;
  mypanel.Align=alHorizontal;
  mypanel.Height=200;
  mypanel.Width=300;
  mypanel.clProSettings.RoundHeight=20;
  mypanel.clProSettings.Roundwidth=20;
  mypanel.clProSettings.IsTransparent =False;
  mypanel.clProSettings.BorderColor = clAlphaColor.clHexToColor('#ffffff');
  mypanel.clProSettings.BorderWidth = 2;
  mypanel.SetclProSettings(mypanel.clProSettings); 
   
  mybuton1=myForm.AddNewProButton(mypanel, 'mybuton1', '');
  mybuton1.Align = alLeft;
  mybuton1.margins.left=50;
  mybuton1.margins.bottom=130;
  mybuton1.Width = 40;
  mybuton1.Height = 40;
  mybuton1.clProSettings.IsRound = True;
  mybuton1.clProSettings.RoundHeight = 10;
  mybuton1.clProSettings.RoundWidth = 10;
  mybuton1.SetclProSettings(mybuton1.clProSettings);
  myForm.SetImage(mybuton1,'https://i.imgur.com/KcmLm4h.png'); 
  
  mybuton2=myForm.AddNewProButton(mypanel, 'mybuton2', '');
  mybuton2.Align = alLeft;
  mybuton2.margins.left=45;
  mybuton2.margins.bottom=130;
  mybuton2.Width = 40;
  mybuton2.Height = 40;
  mybuton2.clProSettings.IsRound = True;
  mybuton2.clProSettings.RoundHeight = 10;
  mybuton2.clProSettings.RoundWidth = 10;
  mybuton2.SetclProSettings(mybuton2.clProSettings);
  myForm.SetImage(mybuton2,'https://i.imgur.com/mcpG1Ot.png'); 
  
  mybuton3=myForm.AddNewProButton(mypanel, 'mybuton3', '');
  mybuton3.Align = alLeft;
  mybuton3.margins.left=45;
  mybuton3.margins.bottom=130;
  mybuton3.Width = 40;
  mybuton3.Height = 40;
  mybuton3.clProSettings.IsRound = True;
  mybuton3.clProSettings.RoundHeight = 10;
  mybuton3.clProSettings.RoundWidth = 10;
  mybuton3.SetclProSettings(mybuton3.clProSettings);
  myForm.SetImage(mybuton3,'https://i.imgur.com/yOGrUe4.png'); 
  
    
  mybuton4=myForm.AddNewProButton(mypanel, 'mybuton4', '');
  mybuton4.Align = alMostRight;
  mybuton4.margins.right=50;
  mybuton4.margins.bottom=130;
  mybuton4.Width = 40;
  mybuton4.Height = 40;
  mybuton4.clProSettings.IsRound = True;
  mybuton4.clProSettings.RoundHeight = 10;
  mybuton4.clProSettings.RoundWidth = 10;
  mybuton4.SetclProSettings(mybuton4.clProSettings);
  myForm.SetImage(mybuton4,'https://i.imgur.com/dKnXBVF.png'); 
  
  
   
  myForm.AddNewEvent(mybuton3,tbeOnClick,'mybuton3click');
  MyForm.AddNewEvent(mybuton4,tbeOnClick,'mybuton4click');
  HabitNameGetir;
  MyForm.Run;
}

İKİNCİ SAYFA KODUMDAKİ FONKSİYONLAR///////////////////////////////////////////

void SqLiteInsertData;
{
  try {
    Clomosy.DBSQLiteQuery.Sql.Text = 
      'INSERT INTO Habits (habitId, habitName) VALUES (1, ''İngilizce Çalışmak'');' +
      'INSERT INTO Habits (habitId, habitName) VALUES (2, ''Spor Yapmak'');' +
      'INSERT INTO Habits (habitId, habitName) VALUES (3, ''Meditasyon'');' +
      'INSERT INTO Habits (habitId, habitName) VALUES (4, ''Kitap Okumak'');';
    Clomosy.DBSQLiteQuery.OpenOrExecute;
    ShowMessage('Veriler başarıyla eklendi!');
  }
  except {
    ShowMessage('Hata: ' + LastExceptionMessage);
  }
}
}
void SqLiteConnectionCreateTable;
  var TableExists: Boolean;
{
  try {
    Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBHabits.db3', '');
    // Tablo var mı kontrol et
    Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="Habits";';
    Clomosy.DBSQLiteQuery.OpenOrExecute;
    TableExists = not Clomosy.DBSQLiteQuery.Eof;
    // Tablo yoksa oluştur
    if (not TableExists) {
      Clomosy.DBSQLiteQuery.Sql.Text = 
        'CREATE TABLE Habits(habitId INTEGER NOT NULL, habitName TEXT NOT NULL, PRIMARY KEY (habitId))';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
      ShowMessage('Tablo başarıyla oluşturuldu!');
      SqLiteInsertData;
    }
    else {
      ShowMessage('Habits tablosu zaten mevcut.');
    }
  }
  except {
    ShowMessage('Hata: ' + LastExceptionMessage);
  }
}
}
void GetData;
{
  try {
   Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBHabits.db3', '');
    Qry = Clomosy.DBSQLiteQueryWith('SELECT habitId as clRecord_GUID, habitName from Habits');
    Qry.OpenOrExecute;
    if (Qry.Found) {
      ListView1.clLoadProListViewDataFromDataset(Qry);
    }
  }
  except {
    ShowMessage('Veri yükleme hatası: ' + LastExceptionMessage);
  }
}
}

void AddHabit;
{
  try {
    Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBHabits.db3', '');

    // Alışkanlığı ekle
    Clomosy.DBSQLiteQuery.Sql.Text = 
      'INSERT INTO Habits (habitName) VALUES (' + QuotedStr(Edit1.Text) + ')';
    Clomosy.DBSQLiteQuery.OpenOrExecute;

    // Aynı bağlantı üzerinden ID'yi al
    Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT last_insert_rowid() as habitId';
    Clomosy.DBSQLiteQuery.OpenOrExecute;

    if (Clomosy.DBSQLiteQuery.Found) {
      habitId = Clomosy.DBSQLiteQuery.FieldByName('habitId').AsInteger;
     // ShowMessage('Yeni habitId: ' + IntToStr(habitId));
    }

    Edit1.Text = '';
    GetData;
  }
  except {
    ShowMessage('Ekleme hatası: ' + LastExceptionMessage);
  }
}
}


merhaba,ilk sayfamda ikinci sayfamdaki habitnameleri id ile çekmeye çalıştım ama habitid=0 ve alışkanlık bulunamadı hatası çıktı sorunum nedir eğer isterseniz ikinci sayfanın tam kodunu atabilirim teşekkür ederim










  
< id="BFI_" style="width: 1px; height: 1px; display: none;">

-------------
göksu



Cevaplar:
Mesajı Yazan: Sudesigirci
Mesaj Tarihi: 29 Temmuz 2025 Saat 10:39
Merhaba Göksu,
habitidye bir değer atanmadığı için sürekli 0 verdiğini düşünüyorum habit id yi global değişkenle tutabilirsin yardımcı olması için aşağıya örnek bırakıyorum umarım faydası olur 

kullaniciEmail = Clomosy.GlobalVariableString;
UserID = Clomosy.GlobalVariableInteger;//bu şekilde tutabilirsin


    Clomosy.DBSQLiteQuery.SQL.Text =
      'INSERT INTO Talepler (kullanici_email, kullanici_id, baslik, aciklama, modul) VALUES (' +
      QuotedStr(kullaniciEmail) + ',' +
      IntToStr(UserID) + ',' +
      QuotedStr(bekleyenBaslik) + ',' +
      QuotedStr(bekleyenAciklama) + ',' +
      QuotedStr(modul) + ')';

    Clomosy.DBSQLiteQuery.OpenOrExecute;

    ShowMessage('Talep başarıyla eklendi. Tahmini modül: ' + modul);




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