 
			
				30.04.2014, 21:03
			
			
			
		  
	 | 
	
		
		
		
			
			| 
			
				
				
				 Прохожий 
				
				
			 | 
			  | 
			
				
				
					Регистрация: 30.04.2014 
					
					
					Сообщения: 3
 
				Версия Delphi: Delphi XE5 
					Репутация: 10 
					    
				 
				
			 | 
		 
		 
		
	 | 
	
	
	
		
			
			
				 
				Stringgrid и файлы
			 
			 
			
		
		
		
		Столкнулся с проблемой сохранения в файл информации из Stringgrid`а . Уже пробовал и через двумерный массив, и через TStringList. Все равно ничего не выходит 
Вот код записи через TStringList.
 
	Код: 
	procedure TForm1.N2Click(Sender: TObject);
var i,j: integer;
List: TStringList;
Table: TStringGrid;
begin
Assignfile(f,Combobox2.Text);
rewrite(f);
List:=TStringList.Create;
with Table do
for i:=0 to StringGrid1.RowCount-1 do
for j:=0 to StringGrid1.ColCount-1 do
List.Add(Cells[j, i]);
List.SaveToFile(Combobox2.Text);
end;  
 
С двумерным массивом просто не смог разобраться...при чтении из файла происходят чудеса...
 
Вот запись:
 
	Код: 
	procedure TForm1.N2Click(Sender: TObject);
var i,j: integer;
begin
Assignfile(f,Combobox2.Text+'$'+Combobox1.Text);
rewrite(f);
for i := 2 to Stringgrid1.ColCount-1 do
p[0].ocenki:=p[0].ocenki+Stringgrid1.Cells[i,0];
for i:=1 to Stringgrid1.RowCount-1 do
for j:=2 to Stringgrid1.ColCount-1 do
p[i].ocenki:=p[i].ocenki+Stringgrid1.Cells[j,i];
p[1].col:=Stringgrid1.ColCount;
p[1].row:=Stringgrid1.RowCount;
for i:=0 to Stringgrid1.RowCount-1 do
write(f,p[i]);
CloseFile(f);
AssignFile(f2,ComboBox2.Text);
Rewrite(f2);
for i:=1 to Stringgrid1.RowCount-1 do begin
p[i].number:=Stringgrid1.Cells[0,i];
p[i].fam:=Stringgrid1.Cells[1,i];
end;
p[1].col:=Stringgrid1.ColCount;
p[1].row:=Stringgrid1.RowCount;
for i:=1 to Stringgrid1.RowCount-1 do
write(f2,p[i]);
CloseFile(f2);
end;  
 
Вот чтение:
 
	Код: 
	procedure TForm1.ComboBox1Change(Sender: TObject);
var i,j,col,row,l,c,papa,k: integer;
s: string;
koko: array[1..35] of Integer;
begin
i:=0;
if Combobox2.Text<>'' then begin
if FileExists(Combobox2.Text+'$'+Combobox1.Text) then begin
Assignfile(f,Combobox2.Text+'$'+Combobox1.Text);
reset(f);
while not Eof(f) do begin
read(f,p[i]);
i:=i+1;
end;
col:=p[1].col;
row:=p[1].row;
Stringgrid1.ColCount:=col;
Stringgrid1.RowCount:=row;
for i := 2 to Stringgrid1.ColCount-1 do
Stringgrid1.ColWidths[i]:=39;
s:=p[0].ocenki;
for i := 2 to Stringgrid1.ColCount-1 do
for j := 1 to 5 do begin
StringGrid1.Cells[i,0]:=Stringgrid1.Cells[i,0]+s[1];
Delete(s,1,1);
end;
for i:=1 to row-1 do begin
for j:=2 to col-1 do begin
s:=p[i].ocenki;
l:=length(p[i].ocenki);
for c:=1 to l do begin
Stringgrid1.Cells[j,i]:=s[1];
delete(s,1,1);
end;
end;
end;
CloseFile(f);
end;
end;
end;  
 
MAD: используем теги!  
		
	
		
		
		
		
		
	
		
			
			
			
			
				 
			
			
			
			
		 
		
	
	
	 |