Sayfayı Yazdır | Pencereyi Kapat

TclSqlQuery Outputunu işleyemedim

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=1258
Tarih: 15 Nisan 2026 Saat 02:38
Program Versiyonu: Web Wiz Forums 12.07 - https://www.webwizforums.com


Konu: TclSqlQuery Outputunu işleyemedim
Mesajı Yazan: M-Guney
Konu: TclSqlQuery Outputunu işleyemedim
Mesaj Tarihi: 02 Şubat 2026 Saat 14:59
var
  MainForm      : TCLForm;
  ProGridCari   : TCLProGrid;
  mainVertSB    : TclVertScrollBox;
  ScaledLayout  : TCLScaledLayout;
  ReportQuery   : TclSqlQuery;
  CariFields    : TClStringList;

function MakeTitleFromField(AField : String) : String;
var
  p : Integer;
{
  Result = AField;
  p = Pos('_', Result);
  while (p > 0)
  {
    Delete(Result, p, 1);
    Insert(' ', Result, p);
    p = Pos('_', Result);
  }
  Result = AnsiUpperCase(Result);
}

void SetupCariGrid;
var
  c : Integer;
{
  if (ProGridCari == nil)
  {
    ProGridCari = MainForm.AddNewProGrid(mainVertSB, 'ProGridCari');
    ProGridCari.Align = alClient;
  }

  ProGridCari.RowCount = 0; 
  ProGridCari.ColumnCount = CariFields.Count;   
  ProGridCari.RowCount    = 2;   
  ProGridCari.FixedRows   = 1;
  ProGridCari.Options.Editing.Enabled = False;

  for (c = 0 to (CariFields.Count - 1))
  {
    ProGridCari.Cells[c, 0] = MakeTitleFromField(CariFields.Strings[c]);
  }
}

void ExtractMetadataFromQuery;
var
  i : Integer;
{
  if (ReportQuery == nil) { exit; }
  
  CariFields.Clear;

  for (i = 0 to (ReportQuery.FieldCount - 1))
  {
    //CariFields.Add(ReportQuery.FieldName(i));
    // Tam burada SQL den dönmüş olan verideki field alanlarını sütun ismi olarak //ayarlamak istiyorum ama sorgunun textine ulaşamadım
  }
}



Cevaplar:
Mesajı Yazan: M-Guney
Mesaj Tarihi: 02 Şubat 2026 Saat 15:01
LSourceQuery = Clomosy.DBSQLServerQueryWith(AQuery);
    Result = LSourceQuery;

çıktı olarak buradan aldığımı ReportQuery olarak kullanı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: 02 Şubat 2026 Saat 16:38
Merhaba Güney, 
var
  MainForm      : TCLForm;
  ProGridCari   : TCLProGrid;
  mainVertSB    : TclVertScrollBox;
  ReportQuery   : TclSqlQuery;
  CariFields    : TClStringList; 
  HamBaslik     : String;

function MakeTitleFromField(AField : String) : String;
var
  p : Integer;
{
  Result = AField;
  p = Pos('_', Result);
  while (p > 0)
  {
    Delete(Result, p, 1);
    Insert(' ', Result, p);
    p = Pos('_', Result);
  }
  Result = AnsiUpperCase(Result);
}

void GridDoldur;
var
  col, Satir : Integer;
  FieldName : String;
{
  if (ReportQuery == nil) { exit; }
  if (not ReportQuery.Active) ReportQuery.Open;

  if (ProGridCari == nil)
  {
    ProGridCari = MainForm.AddNewProGrid(mainVertSB, 'ProGridCari');
    ProGridCari.Align = alClient;
    ProGridCari.Options.Editing.Enabled = False;
  }

  ProGridCari.ColumnCount = CariFields.Count;
  
  // 1. BAŞLIKLARI YAZ
  for (col = 0 to CariFields.Count - 1)
  {
    HamBaslik = CariFields.Strings[col]; 
    ProGridCari.Cells[col, 0] = MakeTitleFromField(HamBaslik); 
  }

  // 2.  DÖNGÜYLE DOLDUR
  ProGridCari.RowCount = 1; 
  
  if (ReportQuery.Found)
  {
    ReportQuery.First;
    Satir = 1; 
    
    while (not ReportQuery.Eof)
    {
      for (col = 0 to CariFields.Count - 1)
      {
        FieldName = CariFields.Strings[col];
        ProGridCari.Cells[col, Satir] = ReportQuery.FieldByName(FieldName).AsString;
      }
      
      Satir = Satir + 1;
      ReportQuery.Next;
    }
  }
  
  ProGridCari.AutoSizeColumns(True, 100);
}

{
  MainForm = TCLForm.Create(Self);
  mainVertSB = MainForm.AddNewVertScrollBox(MainForm, 'mainVertSB');
  mainVertSB.Align = alClient;
  
  CariFields = Clomosy.StringListNew;
  
  // Alanları Belirle
  CariFields.Add('OGRENCI_NO');
  CariFields.Add('AD_SOYAD');
  CariFields.Add('NOT_ORT');
  
  ReportQuery = Clomosy.DBSQLiteQueryWith('SELECT 101 as OGRENCI_NO, ''Ahmet Yilmaz'' as AD_SOYAD, 85 as NOT_ORT'); 
  ReportQuery.Open;

  GridDoldur;
  
  MainForm.Run;

Test edebilir misin?? 
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: 02 Şubat 2026 Saat 18:25
Aslında benim burada yapmak istediğim field alanını vermeden sorgudan almaktı 
  CariFields.Add('AD_SOYAD');
  CariFields.Add('NOT_ORT');

Yani sorgunun içerisindeki field alanındaki "_" leri " " ye çevirerek kullanmak istiyorum.
"AD_SOYAD" --> "AD SOYAD" şeklinde
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: 03 Şubat 2026 Saat 09:17
Merhaba Güney, 
Son gönderdiğim kodun mantığı da o aslında veritabanında ki AD_SOYAD field 
MakeTitleFromField prosedürü içerisinde başlıkları okunabilir hale getiriyor
yani AD SOYAD olarak çıkıyor daha sonra gridi dolduruyor. 
--------------------------
var
  MainForm      : TCLForm;
  ProGridCari   : TCLProGrid;
  mainVertSB    : TclVertScrollBox;
  ReportQuery   : TclSqlQuery;
  CariFields    : TClStringList; 
  HamBaslik     : String;

function MakeTitleFromField(AField : String) : String;
var
  p : Integer;
{
  Result = AField;
  p = Pos('_', Result);
  while (p > 0)
  {
    Delete(Result, p, 1);
    Insert(' ', Result, p);
    p = Pos('_', Result);
  }
  Result = AnsiUpperCase(Result);
}

void GridDoldur;
var
  col, Satir : Integer;
  FieldName : String;
{
  if (ReportQuery == nil) { exit; }
  
  if (not ReportQuery.Active) ReportQuery.Open;

  CariFields.Clear; 
  ReportQuery.GetFieldNames(CariFields); 
  
  // 2. Grid Yoksa Oluştur
  if (ProGridCari == nil)
  {
    ProGridCari = MainForm.AddNewProGrid(mainVertSB, 'ProGridCari');
    ProGridCari.Align = alClient;
    ProGridCari.Options.Editing.Enabled = False;
  }

  ProGridCari.ColumnCount = CariFields.Count;
  
  for (col = 0 to CariFields.Count - 1)
  {
    HamBaslik = CariFields.Strings[col]; 
    ProGridCari.Cells[col, 0] = MakeTitleFromField(HamBaslik); 
  }

  ProGridCari.RowCount = 1; 
  
  if (ReportQuery.Found)
  {
    ReportQuery.First;
    Satir = 1; 
    
    while (not ReportQuery.Eof)
    {
      for (col = 0 to CariFields.Count - 1)
      {
        FieldName = CariFields.Strings[col];
        
        ProGridCari.Cells[col, Satir] = ReportQuery.FieldByName(FieldName).AsString;
      }
      
      Satir = Satir + 1;
      ReportQuery.Next;
    }
  }
  
  ProGridCari.AutoSizeColumns(True, 100);
}

{
  MainForm = TCLForm.Create(Self);
  mainVertSB = MainForm.AddNewVertScrollBox(MainForm, 'mainVertSB');
  mainVertSB.Align = alClient;
  
  CariFields = Clomosy.StringListNew;
  
  
  ReportQuery = Clomosy.DBSQLiteQueryWith('SELECT 101 as OGRENCI_NO, ''Ahmet Yilmaz'' as AD_SOYAD, 85 as NOT_ORT'); 
  ReportQuery.Open;

  GridDoldur;
  
  MainForm.Run;
}
bir önce ki gönderdiğim de manuel olarak ekliyorduk.  
Son gönderdiğim de sütun isimlerini otomatik alıyor prosedürle düzeltiyor ve verileri dolduruyor. 

Deneyebilir misin?

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: 18 Mart 2026 Saat 10:46
Problemi bu şekilde çözdüm artık herhangi bir problem bulunmamaktadır.

function MakeTitleFromField(AField: String): String;
var p: Integer;
{
  Result = AField;
  p = Pos('_', Result);
  while (p > 0) { Delete(Result, p, 1); Insert(' ', Result, p); p = Pos('_', Result); }
  Result = AnsiUpperCase(Result);
}

void FillGrid
var 
  col, Satir, i, SampleCount: Integer; 
  FieldName, TitleMethod, RawValue, UpFieldName, C: String;
  InputPersonalTitles: TClStringList;
  IsNumberCol: Boolean;
{
  ReportQuery = uDataLib.GetReportQuery;
  TitleMethod = uDataLib.GetTitleMethod;
  InputPersonalTitles = uDataLib.GetPersonalTitles;

  if (ReportQuery == nil) Exit;
  if (not ReportQuery.Active) ReportQuery.Open;

  if (CariFields == nil) CariFields = Clomosy.StringListNew;
  CariFields.Clear;
  
  if (TitleMethod == 'Personalize')
  {
    if (InputPersonalTitles <> nil)
    {
      for (col = 0 to InputPersonalTitles.Count - 1)
      {
        FieldName = InputPersonalTitles.Names[col];
        if (ReportQuery.FindField(FieldName) <> nil) CariFields.Add(FieldName);
      }
    }
  }
  else
  {
    ReportQuery.GetFieldNames(CariFields);
    if (TitleMethod == 'Field')
    {
      InputPersonalTitles = Clomosy.StringListNew;
      for (col = 0 to CariFields.Count - 1)
      {
        FieldName = CariFields.Strings[col];
        InputPersonalTitles.Add(FieldName + '=' + MakeTitleFromField(FieldName));
      }
      uDataLib.SetPersonalTitles(InputPersonalTitles);
    }
  }

  ReportGrid.ColumnCount = CariFields.Count + 1; // Sıra No için Grid'e ekstra +1 kolon ekliyoruz ---
  ReportGrid.RowCount = ReportQuery.RecordCount + 1;

  // 1. BAŞLIKLARI YAZDIRMA
  ReportGrid.Cells[0, 0] = ''; // En sol üst köşeye sabit başlık('') / 'Sıra'

  for (col = 0 to CariFields.Count - 1)
  {
    if (TitleMethod == 'Personalize') 
      ReportGrid.Cells[col + 1, 0] = InputPersonalTitles.Values[CariFields.Strings[col]]; // Veriler col+1'e kaydırıldı
    else 
      ReportGrid.Cells[col + 1, 0] = MakeTitleFromField(CariFields.Strings[col]);
  }

  // 2. VERİLERİ YAZDIRMA
  if (ReportQuery.RecordCount > 0)
  {
    ReportQuery.First;
    Satir = 1;
    while (not ReportQuery.Eof)
    {
      ReportGrid.Cells[0, Satir] = IntToStr(Satir);
      ReportGrid.HorzAlignments[0, Satir] = 0; // Sıra No: Ortala (gtaCenter)
      
      for (col = 0 to CariFields.Count - 1)
      {
        FieldName = CariFields.Strings[col];
        RawValue = ReportQuery.FieldByName(FieldName).AsString;
        
        RawValue = TransformCellValue(FieldName, RawValue);
        RawValue = FormatIfNumeric(FieldName, RawValue);
        
        ReportGrid.Cells[col + 1, Satir] = RawValue;
      }
      Satir = Satir + 1;
      ReportQuery.Next;
    }
  }
  
  ReportGrid.AutoSizeColumns(True, 10);
  // 3. HÜCRE BAZLI HİZALAMA MOTORU (Data Sampling Yöntemi)
  
  for (col = 0 to CariFields.Count - 1)
  {
    UpFieldName = AnsiUpperCase(CariFields.Strings[col]);
    IsNumberCol = True; // Varsayılan olarak sayı kabul et, testte çürüt
    
    // KURAL 1: Kesin Metin Olanlar (Blacklist)
    if ((Pos('KOD',   UpFieldName) > 0) ||
        (Pos('_NO',   UpFieldName) > 0) ||
        (Pos('NO_',   UpFieldName) > 0) ||
        (Pos('TIP',   UpFieldName) > 0) ||
        (Pos('ADI',   UpFieldName) > 0) ||
        (Pos('MODUL', UpFieldName) > 0) ||
        (Pos('ACIKLAMA', UpFieldName) > 0) ||
        (Pos('VADE',  UpFieldName) > 0) ||
        (Pos('TARIH', UpFieldName) > 0))
    {
      IsNumberCol = False; // Metin
    }
    else
    {
      // KURAL 2: Şüpheli Kolonlar İçin Veri Örnekleme (Sampling)
      SampleCount = 0; 
      
      for (Satir = 1 to ReportGrid.RowCount - 1)
      {
        RawValue = Trim(ReportGrid.Cells[col + 1, Satir]);
        
        if (RawValue <> '')
        {
          for (i = 1 to Length(RawValue))
          {
            C = Copy(RawValue, i, 1);
            if (Pos(C, '0123456789.,-') == 0)
            {
              IsNumberCol = False; // Harf bulundu, sayı değil!
            }
          }
          SampleCount = SampleCount + 1;
        }
        
        // Karar verildiyse testleri bitir
        if ((IsNumberCol == False) || (SampleCount >= 3))
        {
          Break;
        }
      }
      
      if (SampleCount == 0) IsNumberCol = False;// Eğer tamamen boş bir kolonsa (SampleCount = 0) onu da sola at
    }
    
    // HÜCRELERİ FİZİKSEL OLARAK HİZALA (Satır Döngüsü)
    for (Satir = 1 to ReportGrid.RowCount - 1)
    {
      ReportGrid.HorzAlignments[0, Satir] = 0; // 0. Kolon (Sıra No) daima Ortada (gtaCenter = 0)
      
      if (IsNumberCol == True)
        ReportGrid.HorzAlignments[col + 1, Satir] = 2; // Sağa Yasla (gtaTrailing = 2)
      else
        ReportGrid.HorzAlignments[col + 1, Satir] = 1; // Sola Yasla (gtaLeading = 1)
    }
  }
  ApplyGridColors;
  CalculateTotals;
}




.
https://static.cloudflareinsights.com/beacon.min.js/v8c78df7c7c0f484497ecbca7046644da1771523124516" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/v8c78df7c7c0f484497ecbca7046644da1771523124516" integrity="sha512-8DS7rgIrAmghBFwoOTujcf6D9rXvH8xm8JQ1Ja01h9QX8EzXldiszufYa4IFfKdLUKTTrnSFXLDkUEOTrZQ8Qg==" 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