Autor Beitrag
DelphMan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: So 08.10.06 20:52 
Hallo,


auf einem Form werden per Knopfdruck bis zu 500 Würfel in Form von kleinen TPanels erzeugt.
Das Anlegen dauert doch etwas (man sieht, wie sie schleppend erzeugt werden). Gibt es eine
Möglichkeit, das zu beschleunigen? Ich denke da an sowas wie:
redraw:=off
Erzeuge 500 Panels
redraw:=on

Gibts da eine Beschleunigungs-Möglichkeit?


Vielen Dank!


DelphMan
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 08.10.06 21:19 
Moin!

user profile iconDelphMan hat folgendes geschrieben:
auf einem Form werden per Knopfdruck bis zu 500 Würfel in Form von kleinen TPanels erzeugt. Das Anlegen dauert doch etwas (man sieht, wie sie schleppend erzeugt werden). Gibt es eine
Möglichkeit, das zu beschleunigen?

Ja, keine Panels nehmen. ;)

Nein, im Ernst, Panels sind als Ressourcenfresser verschrien. Warum nimmst du keine Images?

user profile iconDelphMan hat folgendes geschrieben:
Ich denke da an sowas wie:

IMHO geht das nicht. :|

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 09.10.06 00:10 
user profile iconNarses hat folgendes geschrieben:
Moin!

user profile iconDelphMan hat folgendes geschrieben:
auf einem Form werden per Knopfdruck bis zu 500 Würfel in Form von kleinen TPanels erzeugt. Das Anlegen dauert doch etwas (man sieht, wie sie schleppend erzeugt werden). Gibt es eine
Möglichkeit, das zu beschleunigen?

Ja, keine Panels nehmen. ;)

Nein, im Ernst, Panels sind als Ressourcenfresser verschrien. Warum nimmst du keine Images?

Erstens das und zweitens: Warum überhaupt Komponenten nehmen und nicht selber zeichnen? Komponenten, auch TImages brauchen immer etwas bis sie erzeugt oder gezeichnet werden.
(Klar ist die Frage auch etwas ironisch gemeint. Ich weiß, dass es einfacher ist, einfach ein paar Komponenten auf das Formular zu schmeißen...)

Beispiel für selbst zeichnen:
(ich weiß, dass es nicht so toll aussieht, aber an die Stelle kann man auch Bilder zeichnen lassen mit Canvas.Draw oder man kann einen 3D-Look simulieren...)
ausblenden 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:
procedure TForm1.FormPaint(Sender: TObject);
var
  i, j, DiceWidth, DiceHeight: Integer;
  WuerfelRect: TRect;
begin
  DiceWidth := ClientWidth div 21;
  DiceHeight := ClientHeight div 21;
  for i := 0 to 10 do
    for j := 0 to 10 do
    begin
      WuerfelRect.Left := (i * 2 + 1) * DiceWidth;
      WuerfelRect.Top := (j * 2 + 1) * DiceHeight;
      WuerfelRect.Right := (i * 2 + 2) * DiceWidth;
      WuerfelRect.Bottom := (j * 2 + 2) * DiceHeight;
      Canvas.Rectangle(WuerfelRect);
      Canvas.Ellipse(WuerfelRect.Left + DiceWidth div 6, WuerfelRect.Top + DiceHeight div 6,
        WuerfelRect.Left + 2 * DiceWidth div 6, WuerfelRect.Top + 2 * DiceHeight div 6);
    end;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  Invalidate;
end;

Auch wenn das beim Form resizen flackert, es funktioniert aber und ist auf jede Fall recht schnell...
Du musst OnPaint und OnResize wie hier angegeben füllen.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 09.10.06 00:15 
Moin!

user profile iconjaenicke hat folgendes geschrieben:
Auch wenn das beim Form resizen flackert,

Also bei dem Ansatz frage ich mich dann schon, warum ich nicht gleich ein großes Image auf die Form lege und in dessen Bitmap zeichne. Ist noch schneller und flackert nicht beim Resizen. :D

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 09.10.06 02:29 
Klar, ich würde auch eine eigene Komponente vorziehen (im Moment erstelle ich gerade ein paar Gradient Components, die echt super aussehen in meinem Programm. Und da benutze ich einen Background Buffer, der dann inklusive allem gezeichnet wird um Flackern zu vermeiden. Aber erstmal wollte ich mal hören, was denn auf den Vorschlag es selbst zu zeichnen für eine Antwort kommt. Du weißt was ich meine... ;-)
DelphMan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: Mo 09.10.06 10:58 
Hallo,

danke für den Tipp. Ich brauche jeden einzelnen Würfel
als "Objekt". Es soll pro Doppelklick auf dem jeweiligen
Würfel ein und dieselbe Funktion ausgelöst werden mit einem
Parameter id, der die gedrückte Würfelnummer angibt.



Gruß


DelphMan
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 09.10.06 11:02 
Moin!

Das ist doch kein Problem. ;) Dafür brauchst du aber kein Objekt, die Information, welcher Würfel angeklickt wurde, kannst du auch den Klick-Koordinaten errechnen.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 09.10.06 11:58 
Weißt du was, ich schreib dir einfach mal ein ganz einfaches Beispiel für eine eigene Komponente, die auf Klicks an bestimmten Stellen reagiert. Da siehst du wie das geht und kannst dann das für deine Zwecke weiterschreiben.
Dauert ein paar Minuten, mach ich gleich...
// EDIT:
Naja, hatte doch keine Zeit, aber kommt noch...


Zuletzt bearbeitet von jaenicke am Di 10.10.06 20:17, insgesamt 1-mal bearbeitet
DelphMan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: Mo 09.10.06 12:37 
Ja, an die Sache mit den Koordinaten hatte ich nicht gedacht.

@jaenicke: Ui, das ist aber nett.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 17.10.06 20:34 
Tut mit leid, dass es so lange gedauert hat. Naja: Gut Ding will Weile haben...

Hier die Komponente mit sehr vielen Kommentaren. Wie aus den Kommentaren am Anfang auch klar wird, werde ich dazu noch ein Tutorial schreiben und veröffentlichen.
www.buchmanager-berl...ce_compo_example.zip