Napisałem sobie komponent, ale nie chce działać. Niby wszystko dobrze ale wywala Access Violation...
...przy próbie odwołania się do wartości która jest w klasie, która to klasa z kolei jest w tej pierwszej klasie. To ma być komponent do takiej mini gierki. Jak wszystko bylo na formie, a TShape robił za playera, wszystko działało. Aż w końcu zapragnąłem mieć 2 palyerów, i napisałem komponent który teraz nie działa.
Błąd, jak już wyżej napisałem pojawia się tylko wtedy gdy próbuję zmienić jedną z poniższych wartości:
FKey.Up, FKey.Down, FKey.Left, FKey.Right, FKey.Gas, FKey.Nitro,
FKeyL.Up, FKeyL.Down, FKeyL.Left, FKeyL.Right, FKeyL.Gas, FKeyL.Nitro,
unit player;
interface
uses
SysUtils, Classes, Controls;
type
TKeyPushed = class(TPersistent)
private
FUp, FDown, FLeft, FRight, FGas, FNitro : Boolean;
published
property Up : Boolean read FUp write FUp stored False;
property Down : Boolean read FDown write FDown stored False;
property Left : Boolean read FLeft write FLeft stored False;
property Right : Boolean read FRight write FRight stored False;
property Gas : Boolean read FGas write FGas stored False;
property Nitro : Boolean read FNitro write FNitro stored False;
end;
type
TPlayer = class(TCustomControl)
private
FSpeed : Extended;
FForce : Extended;
FMSpeed : Extended;
FKey : TKeyPushed;
FKeyL : TKeyPushed;
protected
{ Protected declarations }
public
constructor Create(AOwner : TComponent);
destructor Destroy(); override;
published
property Key : TKeyPushed read FKey write FKey;
property KeyL : TKeyPushed read FKeyL write FKeyL;
property Speed : Extended read FSpeed write FSpeed;
property Force : Extended read FForce write FForce;
property MaxSpeed : Extended read FMSpeed write FMSpeed;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TPlayer]);
end;
constructor TPlayer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FKey := TKeyPushed.Create;
FKeyL := TKeyPushed.Create;
end;
destructor TPlayer.Destroy();
begin
FKey.Free; // zwolnienie
FKeyL.Free;
inherited;
end;
end.