Problemi bu şekilde çözdüm artık herhangi bir problem bulunmamaktadır.
function MakeTitleFromField(AField: String): String;
while (p > 0) { Delete(Result, p, 1); Insert(' ', Result, p); p = Pos('_', 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;
}
.