PDA

Prikaži potpunu verziju : primena ParseRecord procedure na 5 CSV faljova - da li je moguće


gutaiii
14.7.2012, 15:26
Imam jedan neobičan zahtev / problem:
- otvoriti 5 csv fajlova,
- izračunati srednju vrednost za svaku ćeliju,
- sačuvati 1 csv fajl sa novim vrednostima, koji ima istu strukturu kao 5 selektovanih.
Da li je moguće računati srednju vrednost matrice, tj. svake ćelije zasebno u Borland Delphi 7 ?


procedure TForm1.ParseRecord(sRecord: string; Row: integer);
var
sField, subRecord :string;
Col, PosComma, PosQ : integer;
begin
Col := 0;

repeat
if Pos('"', sRecord)=1 then
begin
subRecord:=Copy(sRecord,2,Length(sRecord)-1);
PosQ := Pos('"', subRecord);
sField:= Copy (sRecord, 2, PosQ-1);
// PosQ is position of double quotes in subRecord, which is one character
//shorter than sRecord
// Plus two is added due to the fact that there is a comma behind double quotes
Delete (sRecord,1,PosQ+2);
end
else
begin
PosComma := Pos(',', sRecord);
if PosComma >0 then
begin
sField := Copy(sRecord, 1, PosComma-1);
Delete(sRecord,1,PosComma);
end
else
sField := sRecord;
end;
StringGrid1.Cells[Col,Row] := sField;
Col := Col + 1;
until PosComma = 0;

// Set column number
StringGrid1.ColCount := Col;
end;