【发布时间】:2020-09-22 08:42:51
【问题描述】:
伙计们!
我有这个 txt 文件,我想将内容加载到字符串网格中。这是我的代码:
procedure PopulateStringGrid(Grid: TStringGrid; const FileName: string);
var
TextFile, Line: TStringList;
Row, col: Integer;
begin
Grid.RowCount := 0;//clear any previous data
TextFile := TStringList.Create;
try
Line := TStringList.Create;
try
Line.Delimiter := ' ';
TextFile.LoadFromFile(FileName);
Grid.RowCount := TextFile.Count;
for Row := 0 to TextFile.Count-1 do
begin
Line.DelimitedText := TextFile[Row];
for Col := 0 to Grid.ColCount-1 do
if Col<Line.Count then
Grid.Cells[Col, Row] := Line[Col]
else
Grid.Cells[Col, Row] := '0';
end;
finally
Line.Free;
end;
finally
TextFile.Free;
end;
end;
procedure TForm5.sButton1Click(Sender: TObject);
var filename1:string;
begin
if opendialog1.Execute then
begin
sedit1.Text:=opendialog1.FileName;
filename1:=sedit1.Text;
PopulateStringGrid(StringGrid1, FileName1);
showmessage(filename1);
end
else showmessage('file failed to load');
end;
效果很好,但是数据太大,所以我想使用我需要的数据。我需要获取日期范围内的数据。 这是解释的图片:
我只想显示我在顶部的 dateedit 中选择的日期范围内的数据。知道怎么做吗? 先感谢您!我正在为此使用 delphi 7。
【问题讨论】:
标签: text-files delphi-7 tstringgrid