Sto lavorando ad una StringGrid con diverse colonne. Premesso che la StringGrid ha una colonna ed 1 Riga fixed,
in fase di disegno delle singole colonne ho impostato la proprietà "Tile.Caption" col titolo di ciascuna colonna. Non potendo impostare, nello stesso momento, la Caption della cella di vertice della Colonna e Riga Fixed, ho comandato l'impostazione da codice:
Form2.GridMovv.Cells[0,0]:= 'N.Pro';
.
Ora, in fase di Test del progetto ho voluto accertarmi del contenuto delle singole celle della griglia:
for j:= 0 to (totCol) do
begin
WriteLn('Form2.GridMovv.Cells[' + IntToStr(j) + ',' + IntToStr(0) + ']= "' + Form2.GridMovv.Cells[j, 0]);
end;
end;
Ecco la risposta:
Form2.GridMovv.Cells[0,0]= "N.Pro
Form2.GridMovv.Cells[1,0]= "
Form2.GridMovv.Cells[2,0]= "
Form2.GridMovv.Cells[3,0]= "
Form2.GridMovv.Cells[4,0]= "
Form2.GridMovv.Cells[5,0]= "
Form2.GridMovv.Cells[6,0]= "
Form2.GridMovv.Cells[7,0]= "
Form2.GridMovv.Cells[8,0]= "
Form2.GridMovv.Cells[9,0]= "
Form2.GridMovv.Cells[10,0]= "
Form2.GridMovv.Cells[11,0]= "
Form2.GridMovv.Cells[12,0]= "
Form2.GridMovv.Cells[13,0]= "
Form2.GridMovv.Cells[14,0]= "
Form2.GridMovv.Cells[15,0]= "
Form2.GridMovv.Cells[16,0]= "
Form2.GridMovv.Cells[17,0]= "
Form2.GridMovv.Cells[18,0]= "
Tranne la cella di vertice, tutte le altre risultano vuote.
Però, se io ripeto l'estrazione dello stesso contenuto con:
for j:= 0 to (totCol - 1) do
begin
WriteLn('Form2.GridMovv.Columns[' + IntToStr(j) + '] "' + Form2.GridMovv.Columns[j].Title.Caption);
end;
end;
ottengo:
Form2.GridMovv.Columns[0]Title.Caption= "VOCE contabile di CONTO e"
Form2.GridMovv.Columns[1]Title.Caption= "SOTTOCONTO"
Form2.GridMovv.Columns[2]Title.Caption= "CAUSALE del movimento"
Form2.GridMovv.Columns[3]Title.Caption= "ENTRATE "
Form2.GridMovv.Columns[4]Title.Caption= "USCITE "
Form2.GridMovv.Columns[5]Title.Caption= "£/€"
Form2.GridMovv.Columns[6]Title.Caption= "BENEFICIARIO o DEBITORE/CREDITORE"
Form2.GridMovv.Columns[7]Title.Caption= "Tipo di Contropartita ( N,S,P)"
Form2.GridMovv.Columns[8]Title.Caption= "formula dell'importo"
Form2.GridMovv.Columns[9]Title.Caption= "Codice Voce "movimgg""
Form2.GridMovv.Columns[10]Title.Caption= "Codice Voce di Contropartita"
Form2.GridMovv.Columns[11]Title.Caption= "STATUS Prestito"
Form2.GridMovv.Columns[12]Title.Caption= "Data Inizio Prestito"
Form2.GridMovv.Columns[13]Title.Caption= "Data Ultimo Movimento Prestito"
Form2.GridMovv.Columns[14]Title.Caption= "Data Solare "movimgg""
Form2.GridMovv.Columns[15]Title.Caption= "Ora Solare "movimgg""
Form2.GridMovv.Columns[16]Title.Caption= "ID di "movimgg""
Form2.GridMovv.Columns[17]Title.Caption= "ID di "partmovv" o "prestmom""
Come si notare, nonc'è più il contenuto della vella di vertice delle colonna e Riga Fixed,
mentre tutte le altre, contengono il titolo che ho impostato in fase di disegno.
Ciò indica, per es. che l'istruzione
WriteLn('Form2.GridMovv.Cells[' + IntToStr(j) + ',' + IntToStr(0) + ']= "' + Form2.GridMovv.Cells[j, 0]);
non agisce sulla proprietà Title.Caption, altrimenti avrei ottenuto lo stesso valore che ho ottenuto con l'istruzione
WriteLn('Form2.GridMovv.Columns[' + IntToStr(j) + '] "' + Form2.GridMovv.Columns[j].Title.Caption);
Sembrerebbe che l'istruzione riferita alla proprietà Cells[col,Row], agisce come se ci fosse una proprietà Text.
Ciò indica, per es. che l'istruzione
WriteLn('Form2.GridMovv.Cells[' + IntToStr(j) + ',' + IntToStr(0) + ']= "' + Form2.GridMovv.Cells[j, 0]);
non agisce sulla proprietà Title.Caption, altrimenti avrei ottenuto lo stesso valore che ho ottenuto con l'istruzione
WriteLn('Form2.GridMovv.Columns[' + IntToStr(j) + '] "' + Form2.GridMovv.Columns[j].Title.Caption);
Sembrerebbe che l'istruzione riferita alla proprietà Cells[col,Row], agisce come se ci fosse una proprietà Text.
Per semplicità diciamo di definire una sola colonna con il "Title" a design time, lasciando che le "fixedrows" e le "fixedcols" siano a 1 : le proprietà
Form2.GridMovv.Cells[1, 0]
e
Form2.GridMovv.Columns[0].Title.Caption
devono riportare esattamente la stessa cosa: il contenuto (string) della cella [1,0]
EDIT: sunto, il tuo codice è giusto e il comportamento indicato è giusto. La Cells[0,0] e la Colums[0] non puntano alla stessa cella (se hai la "fixedcols" impostata ad un valore diverso da zero).
Ciao
Forse non ci siamo capiti: CELLs[1,0] NON E' COLUMNS[1] ....... CORRISPONDE A COLUMNS[0]...... !!! (fermo restando quanto già detto nel mio post).
Se Corrisponde a Columns[0], allora l'istruzione
WriteLn('Form2.GridMovv.Cells[' + IntToStr(j) + ',' + IntToStr(0) + ']= "' + Form2.GridMovv.Cells[j, 0]);
avrebbe dovuto restituirmi:
Form2.GridMovv.Cells[1,0]= "VOCE contabile di CONTO e"
invece mi restisuisce "nil". Salvo che non mi si dimostri visivamente perchè il mio ragionamento è sbagliato, rimarrò fermo nella mia convinzione che Lazarus Free Pascal contiene una castroneria nella gestione delle righe e colonne fixed.
var
idx, rowIdx: integer;
begin
for idx := 0 to StringGrid1.ColCount - 1 do
for rowIdx := 0 to StringGrid1.RowCount - 1 do
begin
StringGrid1.Cells[idx, rowIdx] := Format('%d,%d', [idx, rowIdx]);
WriteLn('StringGrid1.Cells[', idx, ',', rowIdx, '] "', StringGrid1.Cells[idx, rowIdx], '"');
end;
for idx := 0 to StringGrid1.Columns.Count - 1 do
begin
WriteLn('StringGrid1.Columns[', idx, '] "', StringGrid1.Columns[idx].Title.Caption, '"');
end;
for idx := 0 to StringGrid1.ColCount - 1 do
begin
WriteLn('StringGrid1.Cell[', idx, ',0] "', StringGrid1.Cells[idx, 0], '"');
end;
end;
Stilgar
@Stilgar
Ti ringrazio per il tentativo d'aiuto, ma le tue istruzioni d'esempio sono sostanzialmente uguali alle prove postate da me sulla mia StringGrid e confermano quanto ho affermato sopra:
il risultato di
WriteLn('Form2.GridMovv.Cells[' + IntToStr(j) + ',' + IntToStr(0) + ']= "' + Form2.GridMovv.Cells[j, 0]);
è diverso da quello di:
WriteLn('Form2.GridMovv.Columns[' + IntToStr(j) + '] "' + Form2.GridMovv.Columns[j].Title.Caption);
@nomorelogic
Grazie per l'indirizzamento, ma quella guida l'ho letta e riletta, tuttavia non ho trovato alcuna indicazione sulla titolazione di una colonna in StringGrid.
Ho eseguito il seguente esempio:
//--------------------------------------- verifica contenuto GridMovv --------------------------------------------------------------------
for j:= 1 to totRgGridMovv do
begin
for i:= 2 to (totCol) do
begin
Form2.GridMovv.Cells[i, j]:= Format('%d,%d', [i, j]);
end;
end;
for j:= 0 to totRgGridMovv do
begin
for i:= 0 to (totCol) do
begin
WriteLn('Form2.GridMovv.Cells[' + IntToStr(i) + ',' + IntToStr(j) + ']= "' + Form2.GridMovv.Cells[i, j] + '"');
end;
end;
for j:= 0 to (totCol) do
begin
WriteLn('Form2.GridMovv.Columns[' + IntToStr(j) + ']Title.Caption= "' + Form2.GridMovv.Columns[j].Title.Caption + '"');
end;
WriteLn('-----');
for j:= 0 to (totCol - 1) do
begin
WriteLn('Form2.GridMovv.Cells[' + IntToStr(j) + ',' + IntToStr(0) + ']= "' + Form2.GridMovv.Cells[j, 0] + '"');
end;
//---------------------------------------------------------- FINE verifica --------------------------------------------------------------------
ottenendo, come risultato:
Form2.GridMovv.Cells[0,0]= "vertice"
Form2.GridMovv.Cells[1,0]= "col.1"
Form2.GridMovv.Cells[2,0]= ""
Form2.GridMovv.Cells[3,0]= ""
Form2.GridMovv.Cells[4,0]= ""
Form2.GridMovv.Cells[5,0]= ""
Form2.GridMovv.Cells[6,0]= ""
Form2.GridMovv.Cells[7,0]= ""
Form2.GridMovv.Cells[8,0]= ""
Form2.GridMovv.Cells[9,0]= ""
Form2.GridMovv.Cells[10,0]= ""
Form2.GridMovv.Cells[11,0]= ""
Form2.GridMovv.Cells[12,0]= ""
Form2.GridMovv.Cells[13,0]= ""
Form2.GridMovv.Cells[14,0]= ""
Form2.GridMovv.Cells[15,0]= ""
Form2.GridMovv.Cells[16,0]= ""
Form2.GridMovv.Cells[17,0]= ""
Form2.GridMovv.Cells[18,0]= ""
Form2.GridMovv.Cells[0,1]= ""
Form2.GridMovv.Cells[1,1]= ""
Form2.GridMovv.Cells[2,1]= "2,1"
. . .
Form2.GridMovv.Cells[16,49]= "16,49"
Form2.GridMovv.Cells[17,49]= "17,49"
Form2.GridMovv.Cells[18,49]= "18,49"
Form2.GridMovv.Columns[0]Title.Caption= "VOCE contabile di CONTO e"
Form2.GridMovv.Columns[1]Title.Caption= "SOTTOCONTO"
Form2.GridMovv.Columns[2]Title.Caption= "CAUSALE del movimento"
Form2.GridMovv.Columns[3]Title.Caption= "ENTRATE "
Form2.GridMovv.Columns[4]Title.Caption= "USCITE "
Form2.GridMovv.Columns[5]Title.Caption= "£/€"
Form2.GridMovv.Columns[6]Title.Caption= "BENEFICIARIO o DEBITORE/CREDITORE"
Form2.GridMovv.Columns[7]Title.Caption= "Tipo di Contropartita ( N,S,P)"
Form2.GridMovv.Columns[8]Title.Caption= "formula dell'importo"
Form2.GridMovv.Columns[9]Title.Caption= "Codice Voce "movimgg""
Form2.GridMovv.Columns[10]Title.Caption= "Codice Voce di Contropartita"
Form2.GridMovv.Columns[11]Title.Caption= "STATUS Prestito"
Form2.GridMovv.Columns[12]Title.Caption= "Data Inizio Prestito"
Form2.GridMovv.Columns[13]Title.Caption= "Data Ultimo Movimento Prestito"
Form2.GridMovv.Columns[14]Title.Caption= "Data Solare "movimgg""
Form2.GridMovv.Columns[15]Title.Caption= "Ora Solare "movimgg""
Form2.GridMovv.Columns[16]Title.Caption= "ID di "movimgg""
Form2.GridMovv.Columns[17]Title.Caption= "ID di "partmovv" o "prestmom""
Mi pare importante la differerenza di contenuto, ottenuta nella Form2.GridMovv.Cells[1,0]
Form2.GridMovv.Cells[1,0]= "col.1"
Form2.GridMovv.Columns[0]Title.Caption= "VOCE contabile di CONTO e"
Se puntare alla Cella[1.0] con Form2.GridMovv.Cells[1,0] fosse UGUALE a Form2.GridMovv.Columns[0]Title.Caption, avrei dovuto leggere sempre la stessa stringa, cioè "col.1", ultima inserita.
Anche l'immagine parziale sulla vista della StringGrid mostra, per la col.1 , il titolo impostato in fase di disegno.