Jesus Reyes wrote:
 --- bobby <[EMAIL PROTECTED]> escribió:

  
I need a class that will be compatible with StringGrid in the
meaning of 
content (Rows, Columns, Cells properties).
The problem is that I don't know how to write a class, and I would
ask 
if someone can point me to some good reading.

Why?
I have a program that I would like to optimize a bit. The problem
is 
that the program writes a lot of data to StringGrid cells in a
loop.
The idea is to have a non-visual grid (I hope it will be faster
than 
StrinGrid), and to copy its content to StringGrid after finishing
the loop.

Regards
Boban Spasic

    

Don't know if in your case it helps but you can do:
grid.BeginUpdate;
[fill the grid}
grid.EndUpdate;

also if you are constantly adding rows, one by one,
grid.rowcount:=grid.rowcount+1
add better some amount grid.rowcount:=grid.rowcount+20 or so.

Jesus Reyes A.
  
Here is one of the parsers from my program (LogAnalyzer on www.mc-antivirus-tet.com) for you to see how dirty job is parsing some kinds of log files.
At the moment all the parsers are in the main unit, and I don't see a way to get them sorted like one parser = one unit, or eventually to get them in the future to one parser = one dll.
The problem is a bit behind my knowledge.
The parser per-se is not slow, it parse 70mb file in less than 20 seconds. The problem is that I want it out of main unit. Thats why I had a request of simple class that can mimic StringGrid.

procedure TfrmMain.parKAV45Parser(FileName: string; dlmt: string);
var
  Lista: TStringList;
  i: integer;
  Row: integer;
  sLine: string;
  sField: string;
  posComma: integer;
  posComma2: integer;
  posComma3: integer;
  flagValid: boolean;
  filePath: string;
  lastFile: string;
  filePos: extended;
begin
    Lista:= TStringList.Create;
    Lista.LoadFromFile(FileName);
    StringGrid1.RowCount := Lista.Count +1; //enough space for sure, the unused space is deleted at the end of this code
    Row := 0;
    lastFile := 'there is no chance to have file-name like this string'; //any string that is almost impossible to have as filepath/name
    filePos := 0;
    for i:= 0 to Lista.Count-1 do
    begin // pocni citanje iz liste
      sLine:= Lista[i];
      filePos:= (i/Lista.Count*100);
      updateProgress(filePos);
      if cancelOp = true then break;
      flagValid := false;
      if (AnsiContainsText(sLine, #9 + 'Infected')) or (AnsiContainsText(sLine, #9 + 'Warning')) or (AnsiContainsText(sLine, #9 + 'Suspicious')) then flagValid := true;
      if AnsiStartsText('OK', sLine) then flagValid := false;
      // first field in the line is a filename/path of the file scanned
      posComma := pos(dlmt, sLine);
      posComma3 := pos ('/', sLine); // if there is a '/' it means that the rest of the path is inside an archive (ZIP, RAR...)
      if flagValid then
      begin
        if posComma > 0 then
        begin
          if PosComma3 > 0 then
            filePath := copy(sLine, 1, posComma3 - 1)
          else
            filePath := copy(sLine, 1, posComma - 1);
          if (AnsiContainsStr(ExtractFilePath(filePath), ExtractFileName(lastFile)) = false)
            and (AnsiCompareStr(lastFile,filePath) <> 0) then
          // now begins the part of code that can be done just with using grid or grid-alike component
          begin
            Row := Row + 1; // it may happen that more than one line is describing the same file, put all the info into one row
                                       // also, if the files are inside the archive, just one row is used with the path to archive, not the files inside
            lastFile := filePath; // remember the file for the next cycle in the loop
            StringGrid1.Cells[0, Row] := filePath;
          end;
          Delete(sLine, 1, PosComma); // delete the filename/path from the line
          repeat // read the rest of the line and parse to rest of the row
            PosComma := Pos(dlmt, sLine);
            PosComma := PosEx(dlmt, sLine, PosComma +1);
            if PosComma > 0 then
              sField := Copy(sLine, 1, PosComma - 1)
            else
              sField := sLine;
            if AnsiContainsText(sField, 'Infected') then
            begin
              repeat
                posComma2 := pos(dlmt, sField);
                if posComma2 > 0 then Delete(sField, 1, PosComma2);
              until posComma2 = 0;
              if (StringGrid1.Cells[3, Row] = '') or (AnsiContainsStr(sField, StringGrid1.Cells[3, Row]))
                or (AnsiContainsStr(StringGrid1.Cells[3, Row], sField)) then
                StringGrid1.Cells[3, Row] := sField
              else
              begin
                StringGrid1.Cells[3, Row] := 'Multiple malware_' + Hash_file(StringGrid1.Cells[0, Row], ComboBox4.ItemIndex);
              end;
            end;
            if AnsiContainsText(sField, 'Warning') then
            begin
              repeat
                posComma2 := pos(dlmt, sField);
                if posComma2 > 0 then Delete(sField, 1, PosComma2);
              until posComma2 = 0;
              if (StringGrid1.Cells[3, Row] = '') or (AnsiContainsStr(sField, StringGrid1.Cells[3, Row]))
                or (AnsiContainsStr(StringGrid1.Cells[3, Row], sField)) then
                StringGrid1.Cells[3, Row] := sField
              else
              begin
                StringGrid1.Cells[3, Row] := 'Multiple malware_' + Hash_file(StringGrid1.Cells[0, Row], ComboBox4.ItemIndex);
              end;
            end;
            if AnsiContainsText(sField, 'Suspicious') then
            begin
              repeat
                posComma2 := pos(dlmt, sField);
                if posComma2 > 0 then Delete(sField, 1, PosComma2);
              until posComma2 = 0;
              if (StringGrid1.Cells[3, Row] = '') or (AnsiContainsStr(sField, StringGrid1.Cells[3, Row]))
                or (AnsiContainsStr(StringGrid1.Cells[3, Row], sField)) then
                StringGrid1.Cells[3, Row] := sField
              else
              begin
                StringGrid1.Cells[3, Row] := 'Multiple malware_' + Hash_file(StringGrid1.Cells[0, Row], ComboBox4.ItemIndex);
              end;
            end;
            if PosComma > 0 then
            begin
              Delete(sLine, 1, PosComma);
            end;
          until posComma = 0; // end of the line in log
        end;
      end;
    end;
    Lista.Free;
    //the rest of the code will delete unused rows from the StringGrid, as we have them more then we need
    i := 1;
    while i <> StringGrid1.RowCount do
    begin
      if StringGrid1.Cells[0,i] = '' then
      begin
        StringGrid1.RowCount := i;
      end
      else
        i := i + 1;
    end;
end;

_________________________________________________________________ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to