Article number: KB000006
Related blocks:
When analyzing application code it was found that the code is inefficient and leads to increase in the volume of used memory and affects the speed of applications' work.
See below example of ineffective code containing long structures (trains):
Var Report: IPrxReport;
Begin
Report := UiReport1.Report;
Report.ActiveSheet.Table.Cells(11, 0, 11, 28).Style.BorderStyle(Tabborder.EdgeBottom) := TabBorderStyle.Continuous;
Report.ActiveSheet.Table.Cells(11, 0, 11, 28).Style.BorderStyle(Tabborder.EdgeTop) := TabBorderStyle.Continuous;
Report.ActiveSheet.Table.Cells(11, 0, 11, 28).Style.BorderStyle(Tabborder.EdgeRight) := TabBorderStyle.Continuous;
Report.ActiveSheet.Table.Cells(11, 0, 11, 28).Style.BorderStyle(Tabborder.EdgeLeft) := TabBorderStyle.Continuous;
Report.ActiveSheet.Table.Cells(11, 0, 11, 28).Style.BorderStyle(Tabborder.InsideHorizontal) := TabBorderStyle.Continuous;
End;
Inefficiency of this code is caused by creation of about four intermediary objects in each long string.
This code should be written as follows:
Var Report: IPrxReport;
TabCellStyle: ITabCellStyle;
Begin
Report := UiReport1.Report;
TabCellStyle := Report.ActiveSheet.Table.Cells(11, 0, 11, 28).Style;
TabCellStyle.BorderStyle(Tabborder.EdgeBottom) := TabBorderStyle.Continuous;
TabCellStyle.BorderStyle(Tabborder.EdgeTop) := TabBorderStyle.Continuous;
TabCellStyle.BorderStyle(Tabborder.EdgeRight) := TabBorderStyle.Continuous;
TabCellStyle.BorderStyle(Tabborder.EdgeLeft) := TabBorderStyle.Continuous;
TabCellStyle.BorderStyle(Tabborder.InsideHorizontal) := TabBorderStyle.Continuous;
End;
See also: