mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-20 01:08:22 +02:00
TCustomStringGrid.LoadfromCSVFile: use StrictDelimiter. Fixes issue #22054
git-svn-id: trunk@37318 -
This commit is contained in:
parent
98e6ec0f7e
commit
692d98a01c
@ -10229,7 +10229,8 @@ procedure TCustomStringGrid.LoadFromCSVFile(AFilename: string;
|
|||||||
ADelimiter:Char=','; WithHeader:boolean=true);
|
ADelimiter:Char=','; WithHeader:boolean=true);
|
||||||
var
|
var
|
||||||
L,SubL: TStringList;
|
L,SubL: TStringList;
|
||||||
i,j,StartRow: Integer;
|
i,j,x,StartRow: Integer;
|
||||||
|
S: String;
|
||||||
begin
|
begin
|
||||||
L := TStringList.Create;
|
L := TStringList.Create;
|
||||||
SubL := TStringList.Create;
|
SubL := TStringList.Create;
|
||||||
@ -10245,7 +10246,17 @@ begin
|
|||||||
if L.Count>0 then begin
|
if L.Count>0 then begin
|
||||||
|
|
||||||
SubL.Delimiter:=ADelimiter;
|
SubL.Delimiter:=ADelimiter;
|
||||||
|
//do not allow #32 as separator in csv files
|
||||||
|
SubL.StrictDelimiter := True;
|
||||||
SubL.DelimitedText:=L[0];
|
SubL.DelimitedText:=L[0];
|
||||||
|
//using StrictDelimiter means we have to handle quoted strings ourselfs
|
||||||
|
for x := 0 to SubL.Count - 1 do
|
||||||
|
begin
|
||||||
|
S := SubL.Strings[x];
|
||||||
|
if (Length(S) > 1) and (S[1] = '"')
|
||||||
|
and (S[Length(S)] = '"') then
|
||||||
|
SubL.Strings[x] := AnsiDeQuotedStr(S,'"');
|
||||||
|
end;
|
||||||
|
|
||||||
if Columns.Enabled then begin
|
if Columns.Enabled then begin
|
||||||
while Columns.VisibleCount<>SubL.Count do
|
while Columns.VisibleCount<>SubL.Count do
|
||||||
@ -10277,7 +10288,17 @@ begin
|
|||||||
|
|
||||||
for i:=StartRow to RowCount-1 do begin
|
for i:=StartRow to RowCount-1 do begin
|
||||||
Rows[i].Delimiter := ADelimiter;
|
Rows[i].Delimiter := ADelimiter;
|
||||||
|
//do not allow #32 as separator in csv files
|
||||||
|
Rows[i].StrictDelimiter := True;
|
||||||
Rows[i].DelimitedText:=L[i-StartRow+j];
|
Rows[i].DelimitedText:=L[i-StartRow+j];
|
||||||
|
//using StrictDelimiter means we have to handle quoted strings ourselfs
|
||||||
|
for x := 0 to Rows[i].Count - 1 do
|
||||||
|
begin
|
||||||
|
S := Rows[i].Strings[x];
|
||||||
|
if (Length(S) > 1) and (S[1] = '"')
|
||||||
|
and (S[Length(S)] = '"') then
|
||||||
|
Rows[i].Strings[x] := AnsiDeQuotedStr(S,'"');
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
|
Loading…
Reference in New Issue
Block a user