I have an application that works with some external data. This data is a kind of database that contains table structures. The application reads such a structure, gets the number of fields, their names, data type, mandatory filling and so on. On the basis of this data, fill fields are created dynamically (TEdit, TComboBox, etc.) and cast into the corresponding dynamic arrays. These objects are displayed on the panel (TPanel). Since there are many objects and all of them do not fit on the panel, I attached a scrollbar and change the Top property of these objects when scrolling.

Everything seems to be convenient, but when the total number of dynamic objects exceeds 150 pieces, they cannot be quickly redrawn, and unpleasant retarding visual effects occur when scrolling.

Can someone tell me a more efficient way to store objects, and their scrolls?

Ps. it is not necessary to suggest doing a stringgrid instead of visual objects, I leave it exactly from it.

    2 answers 2

    Set all Visible objects to false, process only those that are in scope at least partly, and include displaying, ignore the rest (do not change Top in the described case), if necessary, describe with an example, put in the comment A piece of code that you have responsible for the shift control.

    • let's say: z: = InternetObjHeigth div 100; for I: = 0 to Length (LabelArray) - 1 do LabelArray [i] .Top: = LabelArray [i] .Top - (Scrollpos z) + (LastVerticalScrollPos z); - teanYCH
    • Z - height of the displayed field X - height of the control C - Indent between controls A - scroll position in terms of pixels i.e. max scroll value = X + C * Length (LabelArray); V is a kind of temporary variable. for I: = 0 to Length (LabelArray) - 1 do With LabelArray [i] do Begin V: = A- (I * (X + C)); if ((V> 0) and (V <Z) then Begin Top: = V; Visible: = True; end else Visible: = False; end; - Vladimir Klykov
    • I figured here a bit, and I advise you to abandon this implementation (which you have now), if you need to specifically abandon stringgrid in favor of a variety of components, make a form on which the number of objects initially \ dynamically line up = a visible number of records, and In no case, not a sheet) load the data into them, for greater beauty, you can make the number of visible + 1 and move them in a circle, ala scrolling animation. The speed gain will be huge due to the lack of need to sort through the entire array of values. I can describe in more detail in Skype (ToRcH565). - Vladimir Klykov
    • Thank you, gave food for thought. However >> initially \ dynamically lined up the number of objects = apparently the number of records. If only one type of data entry component were to be used, this would be the best option, but I use different input fields for different table fields (TMemo, TEdit and TComboBox). You can try to store the numbers of the first and last component in some variables (they are numbered according to the order of the table fields), and create objects that are next to the panel and delete those that left it at scrolling. - teanYCH
    • You are poorly oriented in the language itself, just like you have such a construct. Type TMyDataType = record \ Class \ object Lable1: string; Memo1: StringList; Memo2: Array Of String; combo: record Text: string; list: array of string; end; Check: Boolean; ...... end; Var MyDataArr: array of TMyDataType; - Vladimir Klykov

    For such tasks, TScrollBox is usually used, inside which the panel is placed, and the components are on the panel, the panel can be of any size and it will scroll through the scrollbar.