Autor Beitrag
FloFri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 97



BeitragVerfasst: Mi 22.01.03 01:09 
Hi!

Ich würde mir gerne eine kleine Grafikengine basteln, bleibe aber schon jetzt direkt am anfang bei der funktion zur initialisierung hängen.

Das ist der type befehl der Engine-Unit:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
type
        TEngine = class
                bmpmain: tbitmap;
                procedure Initialize(color, width, height: integer);
                procedure shutdown;
                procedure draw(Drawform: tform);

        end;


Und das die prozedur Initialize

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TEngine.Initialize(color, width, height: integer);
begin

bmpmain.Width := width;
bmpmain.Height := height;
bmpmain.Canvas.Brush.Style := bssolid;
bmpmain.Canvas.Brush.Color := color;
bmpmain.Canvas.Rectangle(0, 0, width, height);

end;


in meinem formular wird die prozedur hier aufgerufen:

ausblenden Quelltext
1:
2:
3:
4:
procedure TForm1.FormResize(Sender: TObject);
begin
Engine.Initialize(clblack, clientwidth, clientheight);
end;


Allerdings stürzt das Programm immer bei der ersten codezeile der initialisierungsprozedur ab. Auch ein bmpmain := tbitmap.create; hat da nichts gebracht, das programm ist dann nur halt bei dieser zeile abgestürzt.

Kann mir eventuel jemand einen Tip geben, was ich da falsch gemacht haben könnte?
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 22.01.03 10:09 
Hi,

hast Du deine Engine auch erstellt? Also so:
ausblenden Quelltext
1:
Engine := tEngine.Create;					

Außerdem solltest Du einen Constructor in die Klasse tEngine einbauen der die Variable bmpmain erstellt. Und einen Destructor der die Variable bmpmain wieder frei gibt.
ausblenden 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:
Type
  tEngine = Class
      Private
        bmpmain: tbitmap;
      Public
        Constructor Create;
        Destructor Destroy;  override;

        Procedure Initialize(color, width, height: integer);
        Procedure shutdown;
        Procedure draw(Drawform: tform);
    End;

{...}

Constructor tEngine.Create;
Begin
  bmpmain := tBitmap.Create (nil);
End;

Destructor tEngine.Destroy;
Begin
  bmpmain.Free;
  Inherited;
End;


Gruß
TINO
FloFri Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 97



BeitragVerfasst: Mi 22.01.03 14:54 
Danke für die Hilfe, werde mal schauen, obs funzt. Eine Frage noch, was macht der Befehl Inherited?
CenBells
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1547

Win 7
Delphi XE5 Pro
BeitragVerfasst: Mi 22.01.03 18:41 
mit inherited wird die entsprechende prozedur aus der basisklasse ausgeführt, also wenn du destroy aufrufst und dort inherited steht, wird auch mindestens der code von tobject.destroy; ausgeführt,

Such auch mal nach Vererbung und Klassenhierachie.

Gruß
Ken