constructor TTracks.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
Self.fParent:=ACollection.Owner As (TBrowserTracks);
Self.fBrowserTrack:=TBrowserTrack.Create(Self.fParent);
Self.fBrowserTrack.Parent:=Self.fParent;
If Assigned(Self.fBrowserTrack.fPlayBt) Then Self.fBrowserTrack.fPlayBt.OnClick:=Self.fParent.fOnPlay_Event;
end;
J'ai posté en rouge ce qui ne fonctionne pas : Dans la pratique l'évènement OnPlay_Event n'est jamais appelé quand on clique sur un "PlayBt".
Cirec
Messages postés3833Date d'inscriptionvendredi 23 juillet 2004StatutModérateurDernière intervention18 septembre 202250 28 mai 2008 à 14:00
Salut,
1° tout tes évènnements :
<<
TPlay_Event = procedure(Sender: TObject) of object;
TStop_Event = procedure(Sender: TObject) of object;
TMute_Event = procedure(Sender: TObject) of object;
TWrite_Event = procedure(Sender: TObject) of object;
TRead_Event = procedure(Sender: TObject) of object;
TParam_Event = procedure(Sender: TObject) of object;
TListBox_Event = procedure(Sender: TObject) of object;
>>
sont des TNotifyEvent
<<
{ Standard events }
TNotifyEvent = procedure(Sender: TObject) of object;
>>
Et l'erreur c'est la quelle ?
parce que la tu veux affecter un TPlay_Event à un TNotifyEvent
ce qui pourrait déjà ne pas plaire à Delphi
essaye déjà de changer tout tes évents en "TNotifyEvent"
et pour finir arrête de mettre des "Self" à tout va
begin
inherited Create(ACollection);
fParent := ACollection.Owner As (TBrowserTracks);
fBrowserTrack := TBrowserTrack.Create(fParent);
fBrowserTrack.Parent := fParent;
If Assigned(fBrowserTrack.fPlayBt) Then fBrowserTrack.fPlayBt.OnClick := fParent.fOnPlay_Event;
end;
destructor TBrowserTitle.Destroy;
begin
inherited;
end;
Procedure TBrowserTitle.setColorTitle(Value:TColor);
Begin
self.fColorTitle:=Value;
self.Invalidate;
End;
Procedure TBrowserTitle.setColorSubTitle(Value:TColor);
Begin
self.fColorSubTitle:=Value;
self.Invalidate;
End;
Procedure TBrowserTitle.setColorRectTitle(Value:TColor);
Begin
self.fColorRectTitle:=Value;
self.Invalidate;
End;
Procedure TBrowserTitle.SetTitle(Value:String);
Begin
self.fTitle:=Value;
self.Invalidate;
End;
Procedure TBrowserTitle.SetSubTitle(Value:String);
Begin
self.fSubTitle:=Value;
self.Invalidate;
End;
procedure TBrowserTitle.Resize;
Begin
self.Width:=209;
If Self.Height<49 Then
Self.Height:=49;
self.Invalidate;
End;
procedure TBrowserTitle.Paint;
Var
RectTitle:TRect;
WidthString,HeightString,LeftString,TopString:Integer;
Begin
InHerited;
With Self.Canvas Do
Begin
Brush.Style:=BsClear;
With RectTitle Do
Begin
Left:=0;
Right:=Self.Width;
Top:=0;
Bottom:=49;
Brush.Color:=Self.fColorRectTitle;
Pen.Color:=ClBlack;
Pen.Width:=4;
Rectangle(RectTitle);
Font.Name:='Comic Sans MS';
Font.Size:=13;
Font.Color:=Self.fColorSubTitle;
WidthString:=TextWidth(Self.fSubTitle);
HeightString:=TextHeight(Self.fSubTitle);
LeftString:=Self.Width-WidthString-10;
TopString:=Bottom-Pen.Width-HeightString;
TextOut(LeftString,TopString,Self.fSubTitle);
End;
End
End;
{>>BROWSERBUTTON}
constructor TBrowserButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fClicked:=False;
end;
destructor TBrowserButton.Destroy;
begin
inherited;
end;
Procedure TBrowserButton.SetColorLine(Value:TColor);
begin
Self.fColorLine:=Value;
Self.Invalidate;
end;
Procedure TBrowserButton.SetColorTop(Value:TColor);
begin
Self.fColorTop:=Value;
Self.Invalidate;
end;
Procedure TBrowserButton.SetColorBottom(Value:TColor);
begin
Self.fColorBottom:=Value;
Self.Invalidate;
end;
Procedure TBrowserButton.SetCaption(Value:String);
begin
Self.fCaption:=Value;
Self.Invalidate;
end;
procedure TBrowserButton.Paint;
Var
RectTop,RectBottom : TRect;
HeightCaption, WidthCaption:Integer;
Begin
InHerited;
DrawBorder;
With Self.Canvas Do
Begin
Font:=Self.Font;
With RectTop Do
Begin
Top:=6;
Bottom:=Self.Height Div 2 ;
Left:=6;
Right:=Self.Width-6;
Brush.Color:=Self.fColorTop;
Pen.Color:=Self.fColorTop;
Rectangle(RectTop);
End;
With RectBottom Do
Begin
Top:=Self.Height Div 2;
Bottom:=Self.Height-6;
Left:=6;
Right:=Self.Width-6;
Brush.Color:=Self.fColorBottom;
Pen.Color:=Self.fColorBottom;
Rectangle(RectBottom );
End;
Brush.Color:=Self.fColorLine;
Pen.Color:=Self.fColorLine;
Pen.Width:=2;
MoveTo(5,Self.Height Div 2);
LineTo(Self.Width-7,Self.Height Div 2);
HeightCaption:=Self.Canvas.TextHeight(Self.Caption);
WidthCaption:=Self.Canvas.TextWidth(Self.Caption);
Brush.Style:=BsClear;
TextOut((Self.Width - WidthCaption) Div 2,(Self.Height - HeightCaption) Div 2, Self.Caption);
End;
End;
Procedure TBrowserButton.DrawBorder;
Var
LeftColor, RightColor:TColor;
UpperCorner,LowerCorner:Array [0..2] Of TPoint;
Begin
If Not fClicked Then
Begin
LeftColor:=ClWhite;
RightColor:=$00657271;
End
Else
Begin
LeftColor:=$00657271;
RightColor:=ClWhite;
End;
With Self.Canvas Do
Begin
Pen.Width:=2;
UpperCorner[0]:=Point(Pen.Width,Self.Height-Pen.Width);
UpperCorner[1]:=Point(Pen.Width,Pen.Width);
UpperCorner[2]:=Point(Self.Width-Pen.Width,Pen.Width);
LowerCorner[0]:=Point(Pen.Width,Self.Height-Pen.Width);
LowerCorner[1]:=Point(Self.Width-Pen.Width,Self.Height-Pen.Width);
LowerCorner[2]:=Point(Self.Width-Pen.Width,Pen.Width);
Brush.Color:=LeftColor;
Pen.Color:=LeftColor;
Polyline(UpperCorner);
Brush.Color:=RightColor;
Pen.Color:=RightColor;
Polyline(LowerCorner);
End;
End;
procedure TBrowserButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
Begin
InHerited;
If Shift=[SSLeft] Then
Begin
Self.fClicked:= True;
Self.Invalidate;
End;
End;
procedure TBrowserTrack.Resize;
Begin
self.Width:=209;
Self.Height:=65;
self.Invalidate;
End;
Procedure TBrowserTrack.SetTypeTrack(Value:TTrackType);
Begin
fTypeTrack:=Value;
self.Invalidate;
End;
Procedure TBrowserTrack.SetTracks(Value:TStringList);
Begin
self.fTracks:=Value;
Self.fListBox.Items.Assign(Value);
self.Invalidate;
End;
Procedure TBrowserTrack.SetIndex(Value:Integer);
Begin
self.fIndex:=Value;
self.Invalidate;
End;
Procedure TBrowserTrack.SetActive(Value:Boolean);
Begin
self.fActive:=Value;
self.Invalidate;
End;
Procedure TBrowserTrack.DrawTypeArea;
Var
RectType:TRect;
Begin
With Self.Canvas Do
With RectType Do
Begin
Left:=0;
Right:=65;
Top:=0;
Bottom:=Self.Height;
Pen.Color:=ClBlack;
Pen.Width:=1;
If Self.fTypeTrack=TtMidi Then
Brush.Color:=$0096E1FA Else
Brush.Color:=$00ADAE93;
Rectangle(RectType);
End;
End;
Procedure TBrowserTrack.DrawCircle(X,Y,Width,Height:Integer);
Var
EllipseRect:TRect;
Begin
With self.Canvas Do
With EllipseRect Do
Begin
Pen.Width:=1;
Pen.Color:=ClBlack;
Pen.Width:=1;
Left:=X-Width Div 2;
Right:=X+Width Div 2;
Top:=Y-Height Div 2;
Bottom:=Y+Height Div 2;
Ellipse(EllipseRect);
End;
End;
Procedure TBrowserTrack.DrawTypeLogo;
Const
WavLogo='WAV';
Var
Index,LeftLetter,TopLetter:Cardinal;
Begin
With Self.Canvas Do
Begin
If Self.fTypeTrack=TtMidi Then
Begin
DrawCircle(23,23,35,35);
Brush.Color:=ClBlack;
DrawCircle(23,13,4,4);
DrawCircle(13,23,4,4);
DrawCircle(33,23,4,4);
DrawCircle(15,16,4,4);
DrawCircle(31,16,4,4);
End
Else
Begin
Brush.Style:=BsClear;
Font.Size:=14;
LeftLetter:=8;
TopLetter:=20;
For Index:=1 To 3 Do
Begin
LeftLetter:=LeftLetter+20*(Index-1);
If Index=3 Then LeftLetter:=LeftLetter-25;
TopLetter:=TopLetter-5*(Index-1);
If Index=3 Then TopLetter:=TopLetter+5;
TextOut(LeftLetter,TopLetter,WavLogo[index]);
End;
End;
If Self.fActive Then
Brush.Color:=ClLime
Else Brush.Color:=ClRed;
DrawCircle(23,55,10,10);
Brush.Style:=BsClear;
TextOut(60-TextWidth(IntToStr(Self.Index)),40-TextHeight(IntToStr(Self.Index)) Div 2,IntToStr(Self.Index));
End;
End;
procedure TBrowserTrack.Paint;
Var
Index:Cardinal;
Begin
With Self.Canvas Do
Begin
Pen.Color:=ClBlack;
Brush.Color:=$00C9CAB7;
Rectangle(Self.ClientRect);
DrawTypeArea;
Pen.Color:=ClWhite;
For Index:=1 To Self.Height Do
If Index Mod 5 = 0 Then
Begin
MoveTo(Pen.Width,Index);
LineTo(65-Pen.Width,Index);
MoveTo(65,Index);
LineTo(Self.Width-Pen.Width,Index);
End;
DrawTypeLogo;
End;
End;
{>>TRACKS}
constructor TTracks.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
Self.fParent:=ACollection.Owner As (TBrowserTracks);
Self.fBrowserTrack:=TBrowserTrack.Create(Self.fParent);
Self.fBrowserTrack.Parent:=Self.fParent;
If Assigned(fBrowserTrack.fPlayBt) Then fBrowserTrack.fPlayBt.OnClick:=fParent.fOnPlay_Event;
end;
destructor TTracks.Destroy;
begin
Self.fBrowserTrack.Free;
inherited Destroy;
end;
{>>TRACKSCNT}
constructor TTracksCnt.Create(AOwner: TBrowserTracks);
begin
inherited Create(AOwner,TTracks);
Self.fParent:=AOwner;
end;
function TTracksCnt.Add:TTracks;
begin
Result := TTracks(inherited Add);
end;
function TTracksCnt.GetItem(Index: integer):TTracks;
begin
Result := TTracks(inherited Items[Index]);
end;
procedure TTracksCnt.SetItem(Index: integer; Value:TTracks);
begin
inherited SetItem(Index, Value);
end;
{>>BROWSERTRACKS}
constructor TBrowserTracks.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fBrowserTitle:=TBrowserTitle.Create(Self);
With fBrowserTitle Do
Begin
Parent:=Self;
Top:=0;
Left:=0;
Width:=209;
Height:=49;
End;
fTracksCnt:=TTracksCnt.Create(Self);
fOnPlay_Event:=nil;
fOnStop_Event:=nil;
fOnMute_Event:=nil;
fOnWrite_Event:=nil;
fOnRead_Event:=nil;
fOnParam_Event:=nil;
fOnListBox_Event:=nil;
end;
destructor TBrowserTracks.Destroy;
begin
Self.fTracksCnt.Free;
fBrowserTitle.Free;
inherited;
end;
procedure TBrowserTracks.Resize;
begin
inherited;
Self.Width:=209;
If Self.fTracksCnt.Count<=0 Then
Self.Height:=49;
end;
procedure TBrowserTracks.Paint;
Var
IndexTracks:Integer;
begin
inherited;
If Self.fTracksCnt.Count>0 Then
Begin
For IndexTracks:=0 To Self.fTracksCnt.Count-1 Do
With Self.fTracksCnt.Items[IndexTracks].fBrowserTrack Do
Top:=49+IndexTracks*65;
Self.Height:=49+Self.fTracksCnt.Count*65;
End;
end;
-----
If Assigned(fBrowserTrack.fPlayBt) Then fBrowserTrack.fPlayBt.OnClick:=fParent.fOnPlay_Event;
-----
Si tu ne donnes pas une valeur autre que "nil" à fOnPlay_Event AVANT de créer des TTracks alors ça ne marchera pas.
Le fait de changer fOnPlay_Event APRES la création des TTracks n'influence pas la valeur du OnClick de tes boutons.
Alors... ça parait logique ou pas ?
Vous n’avez pas trouvé la réponse que vous recherchez ?
J'ai mis les Event à Nil car c'est spécifié ainsi dans le tuto de GrandVizir .
Logique oui mais si tu supprimes les fOnPlay_Event:=nil et compagnie ca résoud pas le blem quand meme.
florenth
Messages postés1023Date d'inscriptiondimanche 1 août 2004StatutMembreDernière intervention17 août 20083 28 mai 2008 à 18:44
Ok pour les self version Cari mais pour les "nil" c'est normal que ça ne change rien.
Il faudrait mettre fOnPlay_Event := MaProc avec MaProc qui est une procéure qui existe bel et bien et ce, AVANT de créer tes TTracks.
Sinon, lorsque tu fais "fBrowserTrack.fPlayBt.OnClick:=fParent.fOnPlay_Event;"
comme fParent.fOnPlay_Event nil, alors fBrowserTrack.fPlayBt.OnClick nil donc ça ne fait rien lors du clic sur le bouton !!!!
florenth
Messages postés1023Date d'inscriptiondimanche 1 août 2004StatutMembreDernière intervention17 août 20083 29 mai 2008 à 18:47
Je réponds ici à ton MP:
"Tu dis que je dois utiliser fOnPlay_Event := MaProc
Mais MaProc est une fonction que je ne peux pas définir à l'avance ;) et je me vois mal mettre une fonction qui sert à rien.
Concrètement je dois faire quoi ?"
Ah, c'est bien ce que je pensais !
Dans ce cas, il faudra, lorsque tu connaitras MaProc, dire à tous les boutons que c'est vers elle qu'il faut pointer leur OnClick.
Pour cela, tu peux faire une procédure qui parcours les boutons et qui renseigne leur évènement Onclick avec MaProc.
Une boucle quoi.
florenth
Messages postés1023Date d'inscriptiondimanche 1 août 2004StatutMembreDernière intervention17 août 20083 29 mai 2008 à 20:24
Bah, pas grave si c'est pas super propre, y'a f0xi qui nettoie derrière !!!
Sérieusement, tu peux aussi faire pointer OnClick vers une procédure qui se chargera de rediriger vers la "vraie" procédure une fois qu'elle sera connue.
Mais suivant les cas, ça risque d'être chaud à implementer.