There is a program that creates a log file.
This is an example of the log file it creates:
This program loads this log file into a TStringGrid. The log file is t开发者_开发技巧ab delimited. A cell can has a space " ".
How can I use TStringGrid or an alternative to load such a log file into it like this program?
Thanks!
This procedure loads the log into a string list. For each line in the log, it assigns the CommaText property of the corresponding row in the grid control. That property automatically splits comma- and space-separated tokens in a string. If you have a newer Delphi version, you can use the DelimitedText property instead, which will be more appropriate if the log might ever contain unquoted commas.
procedure LoadLogFile(const FileName: TFileName; Grid: TStringGrid);
var
LogFile: TStrings;
i: Integer;
begin
LogFile := TStringList.Create;
try
LogFile.LoadFromFile(FileName);
Grid.RowCount := LogFile.Count;
for i := 0 to Pred(LogFile.Count) do
Grid.Rows[i].CommaText := LogFile[i];
finally
LogFile.Free;
end;
end;
精彩评论