Ineffective Code Writing (Using Long Structures)

Article number: KB000006

General Information

Related blocks:

Description

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(1101128).Style.BorderStyle(Tabborder.EdgeBottom) := TabBorderStyle.Continuous;
    Report.ActiveSheet.Table.Cells(1101128).Style.BorderStyle(Tabborder.EdgeTop) := TabBorderStyle.Continuous;
    Report.ActiveSheet.Table.Cells(1101128).Style.BorderStyle(Tabborder.EdgeRight) := TabBorderStyle.Continuous;
    Report.ActiveSheet.Table.Cells(1101128).Style.BorderStyle(Tabborder.EdgeLeft) := TabBorderStyle.Continuous;
    Report.ActiveSheet.Table.Cells(1101128).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(1101128).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:

Developers Knowledge Base