Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Di 18.12.12 23:18 
Ich erstelle in einer Schleife mehrere Panels und Labels af ein Form. Nur leider dauert das doch ca 3s für 200 Elemente auf meinem PC. Die Anwendung wird auf einem deutlich langsameren PC laufen.
Wie kann man das also beschleunigen?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
  for i := 0 to Codes.Count - 1 do begin
    tmpPnl := TPanel.Create(nil);
    tmpPnl.Parent := Self;
    tmpPnl.AutoSize := true;
    tmpPnl.BorderStyle := bsSingle;
    tmpPnl.ShowCaption := false;
    tmpLbl := TLabel.Create(tmpPnl);
    tmpLbl.Parent := tmpPnl;
    tmpLbl.Caption := Codes[i].Code;
    tmpLbl.Hint:='HINT!';
    tmpLbl.ShowHint:=true;
    if (cx + tmpPnl.Width > Width-25then begin
      cx := 0;
      Inc(cy, tmpPnl.Height + 2);
    end;
    tmpPnl.Top := cy;
    tmpPnl.Left := cx;
    Inc(cx, tmpPnl.Width + 3);
  end;
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Di 18.12.12 23:37 
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
procedure TForm6.Button1Click(Sender: TObject);
var
 i,cx,cy:Integer;
 tmpPnl:TPanel;
 tmpLbl:TLabel;
 tc:Cardinal;
begin
  cx := 0;
  cy := 0;
  tc := GetTickCount;
  LockWindowUpdate(handle);  // bringt ca 50% Zeitersparnis
  for i := 0 to 500 do begin
    tmpPnl := TPanel.Create(nil);
    //tmpPnl.Parent := Self; später setzen bringt beim testen ca. 40%
    tmpPnl.AutoSize := true;
    tmpPnl.BorderStyle := bsSingle;
    tmpPnl.ShowCaption := false;
    tmpLbl := TLabel.Create(tmpPnl);
    tmpLbl.Parent := tmpPnl;
    tmpLbl.Caption := IntToStr(i);
    tmpLbl.Hint:='HINT!';
    tmpLbl.ShowHint:=true;
    tmpPnl.Parent := Self; // erst hier setzen
    if (cx + tmpPnl.Width > Width-25then begin
      cx := 0;
      Inc(cy, tmpPnl.Height + 2);
    end;
    tmpPnl.Top := cy;
    tmpPnl.Left := cx;

    Inc(cx, tmpPnl.Width + 3);
  end;
  LockWindowUpdate(0); // nicht vergessen

  Showmessage(IntToStr(GetTickCount-tc));
end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mi 19.12.12 00:43 
Danke für den Tipp.
Das spätere Setzen des Parents bringt 40%. Das LockWindow leider gar nichts. Aber 40% sind erst mal echt gut!
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 19.12.12 00:58 
Hast Du das richtige handle erwischt? Form oder Parent der Panels, ich nehme an das war nur eine Demoauszug.

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mi 19.12.12 08:10 
@Bummi: Kannst Du mir erklären, warum das spätere Setzen des Parents eine Zeitersparnis bringt? Das würde mich interessieren.

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 19.12.12 08:29 
Weil (fast) jede Propertyänderung ein "Neuzeichnen" bewirkt, wenn der Parent nicht gesetzt ist entfällt dieses.

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Mi 19.12.12 08:47 
Eine Möglichkeit wäre auch auf das Formular ein großes Panel und dieses als Parent für die neuen Panels zu verwenden. Dieses kann man dann vor dem Erzeugen der vielen Panels unsichtbar und danach wieder sichtbar machen.

Beste Grüße
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 19.12.12 10:06 
user profile iconFlamefire hat folgendes geschrieben Zum zitierten Posting springen:
Ich erstelle in einer Schleife mehrere Panels und Labels af ein Form. Nur leider dauert das doch ca 3s für 200 Elemente auf meinem PC. Die Anwendung wird auf einem deutlich langsameren PC laufen.
Dann hast du dort aber auch generell mit vielen Komponenten vielleicht ein Performanceproblem. Zumindest, wenn dann noch gescrollt wird z.B.

Bist du wirklich sicher, dass sich das nicht anders lösen lässt? So viele Komponenten sehen für mich erst einmal wie das Problem und nicht wie die Lösung aus. :gruebel:

// EDIT:
Als Beispiel nenne ich wieder einmal mein Periodensystem, dass selbst auf älteren PCs noch performant läuft:
www.entwickler-ecke....rder=asc&start=0

Für diesen Beitrag haben gedankt: bummi
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Do 20.12.12 00:53 
Ja habe ich auch schon überlegt ein Canvas oder wenigstens DrawGrid zu nehmen. Aber war mir dann zu aufwändig... Mal sehn ob ich das noch mache ;)