multithreading - Refactoring slow functions in delphi -


i refactoring old application make bit more responsive , have form using devexpress components , creates custom grid using callbackcustomdrawpreviewcell, problem function slow takes 0.09s per call call 30 60 times each time form open form can take 2.8s 5.6s open. program c# , object-c/swift can dispatch block process in background, far research go don't have nothing similar in delphi, seems in delphi new thread has whole new , independent piece of code. assumptions correct?

if best type of solution improve speed in kind of situation? (i using delphi xe)

(in case helps: bought aqtime try me figure out how improve had no luck far it, still need dig manuals little more. did me find problem in speed in particular callback)

thanks in advance.

the function is:

procedure ttvdavaoutagemanagementform.callbackcustomdrawpreviewcell(sender: tcxcustomtreelist; acanvas: tcxcanvas;   aviewinfo: tcxtreelisteditcellviewinfo; var adone: boolean); const   alignflag = dt_left or dt_wordbreak or dt_expandtabs or dt_noprefix or dt_end_ellipsis;   cnfontcolor = clblue; var   afaultid: variant;   afault: ttvdfault;   alocalities, afaultlocalities: tstringlist;   i: integer;   alocality: string;   rect: trect;   size: tsize;   atext: string; begin   { colour preview text blue }   acanvas.font.color := cnfontcolor;   atext := aviewinfo.displayvalue;   alocalities := tstringlist.create;   afaultlocalities := tstringlist.create;   try     afaultid := aviewinfo.node.values[ftvdtree.getcolumnbyfieldname('faultid').itemindex];     if (not varisnull(afaultid))     begin       acanvas.brush.color := color_fault;        afault := ftvdfaults.tvdgetfault(afaultid);       if assigned(afault)       begin         acanvas.brush.color := afault.tvdfaultcolor;          acanvas.brush.color := afault.tvdfaultcolor;         acanvas.fillrect(aviewinfo.boundsrect);         copyrect(rect, aviewinfo.boundsrect);         inflaterect(rect, -1, -1);         inc(rect.left, ftvdtree.optionsview.indicatorwidth);         acanvas.font.color := cnfontcolor;          { if localities in fault bold preview text,           else need manually (i.e. bold localities           in fault }         if afault.tvdalllocalities         begin           acanvas.font.style := [fsbold];           acanvas.drawtext(atext, aviewinfo.boundsrect, alignflag);         end         else         begin           copyrect(rect, aviewinfo.boundsrect);            alocalities.text := stringreplace(atext, ', ', #13#10, [rfreplaceall]);           afaultlocalities.text := stringreplace(afault.tvdlocalities, ', ', #13#10, [rfreplaceall]);           := 0 alocalities.count - 1           begin             acanvas.font.style := [];             { draw comma if not first locality }             if > 0             begin               size := acanvas.textextent(',');               drawtext(acanvas.handle, ',', 1, rect, dt_left or dt_noprefix);               inc(rect.left, size.cx);             end;              alocality := alocalities[i];             if afaultlocalities.indexof(alocality) >= 0             begin               acanvas.font.style := [fsbold];             end;              size := acanvas.textextent(alocality);             if (rect.left + size.cx) > rect.right             begin               rect.left := aviewinfo.boundsrect.left;               inc(rect.top, size.cy);             end;              { draw text item }             drawtext(acanvas.handle, pchar(alocality), length(alocality), rect, dt_left or dt_noprefix);             inc(rect.left, size.cx);           end;         end;          adone := true;       end;     end;        alocalities.free;     afaultlocalities.free;   end; end; 

if sum comments should more or less this.

try @ let know how worked out you. since don't have working example might not 100% correct.

procedure ttvdavaoutagemanagementform.callbackcustomdrawpreviewcell(sender: tcxcustomtreelist; acanvas: tcxcanvas;   aviewinfo: tcxtreelisteditcellviewinfo; var adone: boolean); const   alignflag = dt_left or dt_wordbreak or dt_expandtabs or dt_noprefix or dt_end_ellipsis;   cnfontcolor = clblue; var   afaultid: variant;   afault: ttvdfault;   alocalities, afaultlocalities: tstringlist;   i: integer;   alocality: string;   rect: trect;   size: tsize;   atext: string; begin   { colour preview text blue }   acanvas.font.color := cnfontcolor;   atext := aviewinfo.displayvalue;   alocalities := tstringlist.create;   afaultlocalities := tstringlist.create;   try     afaultid := aviewinfo.node.values[faultidcolumn.itemindex];     if not varisnull(afaultid)     begin       acanvas.brush.color := color_fault;           afault := ftvdfaults.tvdgetfault(afaultid);        if assigned(afault)       begin         acanvas.brush.color := afault.tvdfaultcolor;          acanvas.brush.color := afault.tvdfaultcolor;         acanvas.fillrect(aviewinfo.boundsrect);         copyrect(rect, aviewinfo.boundsrect);         inflaterect(rect, -1, -1);         inc(rect.left, ftvdtree.optionsview.indicatorwidth);         acanvas.font.color := cnfontcolor;          { if localities in fault bold preview text,           else need manually (i.e. bold localities           in fault }          if afault.tvdalllocalities         begin           acanvas.font.style := [fsbold];           acanvas.drawtext(atext, aviewinfo.boundsrect, alignflag);         end         else         begin           copyrect(rect, aviewinfo.boundsrect);            alocalities.commatext:= atext;            afaultlocalities.commatext := afault.tvdlocalities;           afaultlocalities.sorted := true;            := 0 alocalities.count - 1           begin             acanvas.font.style := [];             { draw comma if not first locality }             if > 0             begin               size := acanvas.textextent(',');               drawtext(acanvas.handle, ', ', 1, rect, dt_left or dt_noprefix);               inc(rect.left, size.cx);             end;              alocality := alocalities[i];             if afaultlocalities.indexof(alocality) >= 0             begin               acanvas.font.style := [fsbold];             end;              size := acanvas.textextent(alocality);             if (rect.left + size.cx) > rect.right             begin               rect.left := aviewinfo.boundsrect.left;               inc(rect.top, size.cy);             end;              { draw text item }             drawtext(acanvas.handle, pchar(alocality), length(alocality), rect, dt_left or dt_noprefix);             inc(rect.left, size.cx);           end;         end;          adone := true;       end;     end;        alocalities.free;     afaultlocalities.free;   end; end; 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -