Rajouter un TreeNode dans un TreeView

Utilisateur anonyme - 11 oct. 2008 à 22:36
 Utilisateur anonyme - 13 oct. 2008 à 09:47
Salut à tous,

Je suis entrain de réaliser un composant dont voici le code :

unit BrowserEffects;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, ComCtrls, Graphics, TracksGrid, StrUtils, Dialogs;

type

  TBrowserEffects=Class;

  {>>TITLE}
  TBrowserTitle = class(TGraphicControl)
  private
    fColorTitle:TColor;
    fColorSubTitle:TColor;
    fColorRectTitle:TColor;
    fTitle:String;
    fSubTitle:String;
    Procedure setColorTitle(Value:TColor);
    Procedure setColorSubTitle(Value:TColor);
    Procedure setColorRectTitle(Value:TColor);
    Procedure SetTitle(Value:String);
    Procedure SetSubTitle(Value:String);
  protected
    procedure Paint; override;
    procedure Resize; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    Property ColorTitle:TColor Read fColorTitle Write SetColorTitle;
    Property ColorSubTitle:TColor Read fColorSubTitle Write SetColorSubTitle;
    Property ColorRectTitle:TColor Read fColorRectTitle Write SetColorRectTitle;
    Property Title:String Read fTitle Write SetTitle;
    Property SubTitle:String Read fSubTitle Write SetSubTitle;
  end;

  {>>TBrowserButton}
  TBrowserButton = class(TGraphicControl)
  private
    fColorLine:TColor;
    fColorTop:TColor;
    fColorBottom:TColor;
    fClicked:Boolean;
    fCaption:String;
    Procedure SetColorLine(Value:TColor);
    Procedure SetColorTop(Value:TColor);
    Procedure SetColorBottom(Value:TColor);
    Procedure SetCaption(Value:String);
    Procedure DrawBorder;
  protected
    procedure Paint; override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    Property ColorLine:TColor Read fColorLine Write SetColorLine;
    Property ColorTop:TColor Read fColorTop Write SetColorTop;
    Property ColorBottom:TColor Read fColorBottom Write SetColorBottom;
    Property Tag;
    Property Enabled;
    Property OnMouseDown;
    Property OnMouseMove;
    Property OnMouseUp;
    Property OnClick;
    Property OnDblClick;
    Property Caption : String Read fCaption Write SetCaption;
    Property Font;
  end;

  {>>TEffect}
  TEffect=class(TCollectionItem)
  protected
    fName:String;
    fFileName:String;
    Procedure SetName(Value:String);
  public
    constructor Create(ACollection: TCollection); override;
    destructor Destroy; override;
  Published
    Property FileName:String Read fFileName Write fFileName;
    Property Name:String Read fName Write SetName;
  end;

  {>>TEffectCnt}
  TEffectCnt = class(TOwnedCollection)
  protected
    DestNode:TTreeNode;
    BrowserEffects:TBrowserEffects;
    function GetItem(Index: integer): TEffect;
    procedure SetItem(Index: integer; Value: TEffect);
  public
    constructor Create(AOwner: TComponent);
    function Add: TEffect;
    property Items[Index: integer]: TEffect Read GetItem Write SetItem;
  end;

  {>>TGaugeBar}
  TGaugeBar = class(TCustomControl)
  private
    fMin:Integer;
    fMax:Integer;
    fPos:Integer;
    fStickColor:TColor;
    fBackGroundColor:TColor;
    fFullColor:TColor;
    fText:String;
    Procedure SetStickColor(Value:TColor);
    Procedure SetBackGroundColor(Value:TColor);
    Procedure SetFullColor(Value:TColor);
    Procedure SetMin(Value:Integer);
    Procedure SetMax(Value:Integer);
    Procedure SetPos(Value:Integer);
    Procedure SetText(Value:String);
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    Procedure Paint; override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;X, Y: integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: integer); override;
    Procedure Resize; override;
  published
    Property StickColor:TColor Read fStickColor Write SetStickColor;
    Property BackGroundColor:TColor Read fBackGroundColor Write SetBackGroundColor;
    Property FullColor:TColor Read fFullColor Write SetFullColor;
    Property Color;
    Property Min:Integer Read fMin Write SetMin;
    Property Max:Integer Read fMax Write SetMax;
    Property Pos:Integer Read fPos Write SetPos;
    Property Text:String Read fText Write SetText;
    Property OnMouseDown;
    Property OnMouseMove;
    Property OnMouseUp;
  end;

  {>>TParamsSound}
  TParamsSound = class(TCustomControl)
  private
    fVolGauge:TGaugeBar;
    fPanGauge:TGaugeBar;
    fFreqGauge:TGaugeBar;
    fTempoGauge:TGaugeBar;
    fPitchGauge:TGaugeBar;
  protected
    Procedure CreateGaugeBar(Var AGaugeBar:TGaugeBar;Index:Cardinal; AName, Title:String; MinVal, MaxVal:Integer);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    Procedure Paint; override;
  published
    Property VolGauge:TGaugeBar Read fVolGauge Write fVolGauge;
    Property PanGauge:TGaugeBar Read fPanGauge Write fPanGauge;
    Property FreqGauge:TGaugeBar Read fFreqGauge Write fFreqGauge;
    Property TempoGauge:TGaugeBar Read fTempoGauge Write fTempoGauge;
    Property PitchGauge:TGaugeBar Read fPitchGauge Write fPitchGauge;
    Property Color;
    Property OnMouseDown;
    Property OnMouseMove;
    Property OnMouseUp;
    Property OnClick;
  end;

  TBrowserEffects = class(TCustomControl)
  private
    fVSTICnt:TEffectCnt;
    fVSTECnt:TEffectCnt;
    fSoundFontCnt:TEffectCnt;
    fParamsSound:TParamsSound;
    fBrowserTitle : TBrowserTitle;
    fEffectsView:TTreeView;
    fTracksGrid:TTracksGrid;
    fAddButton:TBrowserButton;
    fLoadButton:TBrowserButton;
    Procedure SetTracksGrid(Value:TTracksGrid);
  protected
    Procedure Create_Constantes_Nodes;
    Procedure CreateButton(var Button:TBrowserButton;BtLeft,BtTop:Integer; AName, BtCaption:String);
  public
    SndFontNode:TTreeNode;
    VSTINode:TTreeNode;
    VSTENode:TTreeNode;
    DSPNode:TTreeNode;
    AutoWahNode:TTreeNode;
    ChorusNode:TTreeNode;
    PhaserNode:TTreeNode;
    DistortionNode:TTreeNode;
    CompressorNode:TTreeNode;
    AllPassFilterNode:TTreeNode;
    EchoNode:TTreeNode;
    Procedure Resize; override;
    Procedure Paint; override;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    Property Color;
    property BrowserTitle : TBrowserTitle Read FBrowserTitle Write FBrowserTitle;
    property AnVSTICnt:TEffectCnt Read fVSTICnt Write fVSTICnt;
    property AnVSTECnt:TEffectCnt Read fVSTECnt Write fVSTECnt;
    property AnSoundFontCnt:TEffectCnt Read fSoundFontCnt Write fSoundFontCnt;
    Property ParamsSound:TParamsSound Read fParamsSound Write fParamsSound;
    Property TracksGrid:TTracksGrid Read fTracksGrid Write SetTracksGrid;
    Property EffectsView:TTreeView Read fEffectsView Write fEffectsView;
    Property AddButton:TBrowserButton Read fAddButton Write fAddButton;
    Property LoadButton:TBrowserButton Read fLoadButton Write fLoadButton;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('MUSIC_PRO', [TBrowserEffects]);
end;

{>>TITLE}
constructor TBrowserTitle.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  fColorRectTitle:=ClSilver;
  Title:='Browser';
  fColorTitle:=$0012526D;
  SubTitle:='Sonorisation';
  fColorSubTitle:=$001A7297;
end;

destructor TBrowserTitle.Destroy;
begin
  inherited;
end;

Procedure TBrowserTitle.setColorTitle(Value:TColor);
Begin
  fColorTitle:=Value;
  Invalidate;
End;

Procedure TBrowserTitle.setColorSubTitle(Value:TColor);
Begin
  fColorSubTitle:=Value;
  Invalidate;
End;

Procedure TBrowserTitle.setColorRectTitle(Value:TColor);
Begin
  fColorRectTitle:=Value;
  Invalidate;
End;

Procedure TBrowserTitle.SetTitle(Value:String);
Begin
  fTitle:=Value;
  Invalidate;
End;

Procedure TBrowserTitle.SetSubTitle(Value:String);
Begin
  fSubTitle:=Value;
  Invalidate;
End;

procedure TBrowserTitle.Resize;
Begin
  Width:=163;
  If Height<49 Then
  Height:=49;
  Invalidate;
End;

procedure TBrowserTitle.Paint;
Var
  RectTitle:TRect;
  WidthString,HeightString,LeftString,TopString:Integer;
Begin
  InHerited;
  With 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:='ARIAL';
          Font.Size:=14;
          Font.Color:=fColorTitle;
          LeftString:=Round(0.05*Self.Width);
          TopString:=Pen.Width;
          TextOut(LeftString,TopString,fTitle);

          Font.Name:='Comic Sans MS';
          Font.Size:=11;
          Font.Color:=Self.fColorSubTitle;
          WidthString:=TextWidth(fSubTitle);
          HeightString:=TextHeight(fSubTitle);
          LeftString:=Self.Width-WidthString-5;
          TopString:=Bottom-Pen.Width-HeightString;
          TextOut(LeftString,TopString,fSubTitle);
        End;
    End
End;

{>>TBrowserButton}
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 TBrowserButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
Begin
  InHerited;
   Self.fClicked:= False;
   Self.Invalidate;
End;

{>>TEffect}
constructor TEffect.Create(ACollection: TCollection);
begin
  inherited Create(ACollection);
end;

destructor TEffect.Destroy;
begin
  inherited Destroy;
end;

Procedure TEffect.SetName(Value:String);
Begin
  fName:=UpperCase(Value);
End;

{>>TEffectCNT}
constructor TEffectCnt.Create(AOwner: TComponent);
begin
  inherited Create(AOwner,TEffect);
end;

function TEffectCnt.Add:TEffect;
begin
  Result := TEffect(inherited Add);
end;

function TEffectCnt.GetItem(Index: integer):TEffect;
begin
  Result := TEffect(inherited Items[Index]);
end;

procedure TEffectCnt.SetItem(Index: integer; Value:TEffect);
begin
  inherited SetItem(Index, Value);
end;

{>>TGaugeBar}
constructor TGaugeBar.Create(AOwner:TComponent);
begin
  inherited Create(AOwner);
  fMin:=0;
  fMax:=100;
  fPos:=fMin;
  Width:=100;
  fStickColor:=ClRed;
  Color:=$00A79AA0;
  BackGroundColor:=$00C8D7DD;
  FullColor:=$00400080;
  fText:='Value';
end;

destructor TGaugeBar.Destroy;
begin
  inherited;
end;

Procedure TGaugeBar.SetMin(Value:Integer);
Begin
  If (Value<=fMax) And (Value<=fPos)  Then
    Begin
      fMin:=Value;
      Self.Invalidate;
    End;
End;

Procedure TGaugeBar.SetMax(Value:Integer);
Begin
  If (Value>=fMin) And (Value>=fPos)  Then
    Begin
      fMax:=Value;
      Self.Invalidate;
    End;
End;

Procedure TGaugeBar.SetPos(Value:Integer);
Begin
  If (Value>=fMin) And (Value<=fMax)  Then
    Begin
      fPos:=Value;
      Self.Invalidate;
    End;   
End;

Procedure TGaugeBar.SetStickColor(Value:TColor);
Begin
  fStickColor:=Value;
  Self.Invalidate;
End;

Procedure TGaugeBar.SetBackGroundColor(Value:TColor);
Begin
  fBackGroundColor:=Value;
  Self.Invalidate;
End;

Procedure TGaugeBar.SetFullColor(Value:TColor);
Begin
  fFullColor:=Value;
  Self.Invalidate;
End;

Procedure TGaugeBar.SetText(Value:String);
Begin
  fText:=Value;
  Self.Invalidate;
End;

Procedure TGaugeBar.Resize;
begin
  inherited;
  Height:=25;
end;

Procedure TGaugeBar.Paint;
Var
  LeftRect,StickRect,BackGroundRect:TRect;
  WidthText:Integer;
  Str:String;
begin
  inherited;
  With Canvas Do
    Begin
      Font.Size:=8;
      Pen.Width:=2;
      Str:=fText+IntToStr(fPos);
      WidthText:=(Width-TextWidth(Str)) Div 2;
      Brush.Style:=BsClear;
      TextOut(WidthText,0,Str);
      With BackGroundRect Do
        Begin
          Left:=0;
          Right:=Width;
          Top:=15;
          Bottom:=23;
          Brush.Color:=fBackGroundColor;
          Rectangle(BackGroundRect);
        End;
      With LeftRect Do
        Begin
          Left:=0;
          Right:=Round(Width*(fPos-fMin) / (fMax-fMin));
          Top:=15;
          Bottom:=23;
          Brush.Color:=fFullColor;
          Rectangle(LeftRect);
        End;
      Brush.Color:=ClWhite;
      Pen.Color:=ClWhite;
      Pen.Width:=0;
      MoveTo(4,19);
      LineTo(Width-4,19);
      With StickRect Do
        Begin
          Left:=Round(Width*((fPos-fMin) / (fMax-fMin))-0.01*Width);
          Right:=Round(Width*((fPos-fMin) / (fMax-fMin))+0.01*Width);
          If Left<=0 Then
            Begin
              Left:=0;
              Right:=Round(0.02*Width);
            End;
          If Right>=Width Then
            Begin
              Left:=Round(Width*0.98);
              Right:=Width;
            End;
          Top:=13;
          Bottom:=25;
          Brush.Color:=fStickColor;
          Pen.Color:=ClBlack;
          Pen.Width:=2;
          Rectangle(StickRect);
        End;
    End;
End;

Procedure TGaugeBar.MouseDown(Button: TMouseButton; Shift: TShiftState;X, Y: integer);
Var
  BnMax,BnMin : Integer;
begin
  inherited;
  If (Shift=[SSLeft]) Then
    Begin
      BnMin:=Round(Width*((fPos-fMin) / (fMax-fMin))-0.01*Width);
      BnMax:=Round(Width*((fPos-fMin) / (fMax-fMin))+0.01*Width);
      If (Shift=[SSLeft]) And (X>=BnMin) And (X<=BnMax) Then
      fPos:=X*(fMax-fMin) Div Width+fMin;
      If fPos<fMin Then fPos:=fMin;
      If fPos>fMax Then fPos:=fMax;
      Self.Invalidate;
    End;
End;

procedure TGaugeBar.MouseMove(Shift: TShiftState; X, Y: integer);
begin
  inherited;
  If (Shift=[SSLeft]) Then
    Begin
      fPos:=X*(fMax-fMin) Div Width+fMin;
      If fPos<fMin Then fPos:=fMin;
      If fPos>fMax Then fPos:=fMax;
      Self.Invalidate;
    End;
End;

{>>TParamsSound}
constructor TParamsSound.Create(AOwner:TComponent);
begin
  inherited Create(AOwner);
  Width:=158;
  Height:=152;
  Color:=$00A79AA0;
  CreateGaugeBar(fVolGauge,0,'VolGaugeBar','VOL ',0,100);
  CreateGaugeBar(fPanGauge,1,'PanGaugeBar','PAN ',-100,100);
  CreateGaugeBar(fFreqGauge,2,'FreqGaugeBar','FREQ ',0,44100);
  CreateGaugeBar(fTempoGauge,3,'TempoGaugeBar','TEMPO ',0,220);
  CreateGaugeBar(fPitchGauge,4,'PitchGaugeBar','PITCH ',-60,60);
end;

Procedure TParamsSound.CreateGaugeBar(Var AGaugeBar:TGaugeBar;Index:Cardinal; AName, Title:String; MinVal, MaxVal:Integer);
Begin
  AGaugeBar:=TGaugeBar.Create(Self);
  With AGaugeBar Do
    Begin
      Parent:=Self;
      Name:=AName;
      SetSubComponent(TRUE);
      Width:=Self.Width-10;
      Left:=5;
      Min:=MinVal;
      Max:=MaxVal;
      Pos:=(Min+Max) Div 2;
      Top:=30*Index+2;
      Text:=Title;
    End;
End;

destructor TParamsSound.Destroy;
begin
  fVolGauge.Free;
  fPanGauge.Free;
  fFreqGauge.Free;
  fTempoGauge.Free;
  fPitchGauge.Free;
  inherited;
end;

Procedure TParamsSound.Paint;
begin
  inherited;
  Canvas.Pen.Width:=2;
  Canvas.Pen.Color:=ClWhite;
  Canvas.Brush.Color:=Color;
  Canvas.Rectangle(ClientRect);
end;

{>>BrowserEffects}
constructor TBrowserEffects.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Parent:=AOwner As TWinControl;
  Color:=ClBlack;
  fBrowserTitle:=TBrowserTitle.Create(Self);
  With fBrowserTitle Do
    Begin
     Parent:=Self;
     Top:=3;
     Left:=3;
    End;
  fParamsSound:=TParamsSound.Create(Self);
  With fParamsSound Do
    Begin
      Parent:=Self;
      Name:='ParamsSound';
      SetSubComponent(TRUE);
      Left:=5;
      Height:=152;
      Top:=fBrowserTitle.Top+fBrowserTitle.Height+3;
    End;
  CreateButton(fAddButton,37,fParamsSound.Top+fParamsSound.Height+3,'AddButton','A');
  CreateButton(fLoadButton,103,fParamsSound.Top+fParamsSound.Height+3,'LoaddButton','L');
  fEffectsView:=TTreeView.CreateParented(Self.Handle);
  With fEffectsView Do
    Begin
      Parent:=Self;
      Name:='EffectsView';
      SetSubComponent(TRUE);
      Left:=5;
      Height:=80;
      Width:=158;
      Top:=fParamsSound.Top+fParamsSound.Height+38;
      Create_Constantes_Nodes;
    End;
  fSoundFontCnt:=TEffectCnt.Create(Self);
  fSoundFontCnt.BrowserEffects:=Self;
  fSoundFontCnt.DestNode:=SndFontNode;
  fVSTICnt:=TEffectCnt.Create(Self);
  fVSTICnt.BrowserEffects:=Self;
  fVSTICnt.DestNode:=VSTINode;
  fVSTECnt:=TEffectCnt.Create(Self);
  fVSTECnt.BrowserEffects:=Self;
  fVSTECnt.DestNode:=VSTENode;
End;

destructor TBrowserEffects.Destroy;
begin
  fVSTICnt.Free;
  fVSTECnt.Free;
  fSoundFontCnt.Free;
  fParamsSound.Free;
  fBrowserTitle.Free;
  fEffectsView.Free;
  fAddButton.Free;
  fLoadButton.Free;
  inherited;
end;

Procedure TBrowserEffects.Resize;
Begin
  InHerited;
  Width:=168;
  Height:=329;
End;

Procedure TBrowserEffects.CreateButton(var Button:TBrowserButton;BtLeft,BtTop:Integer; AName, BtCaption:String);
Begin
  Button:=TBrowserButton.Create(Self);
  With Button Do
    Begin
      Parent:=Self;
      Name:=AName;
      SetSubComponent(TRUE);
      Width:=28;
      Height:=28;
      Left:=BtLeft;
      Top:=BtTop;
      Caption:=BtCaption;
      Font.Size:=14;
      Font.Style:=[FsBold];
      Button.ColorTop:=$00FFE6E1;
      Button.ColorBottom:=$00E8E8E8;
      Button.ColorLine:=$0041C9D3;
    End;
End;

Procedure TBrowserEffects.Create_Constantes_Nodes;
Begin
  With fEffectsView Do
    Begin
      SndFontNode:=Items.Add(NIL,'SOUNDFONTS');
      VSTINode:=Items.Add(NIL,'EFFETS VSTI');
      VSTENode:=Items.Add(NIL,'EFFETS VSTE');
      AutoWahNode:=Items.AddChild(NIL,'AUTOWAH');
      PhaserNode:=Items.AddChild(NIL,'PHASER');
      ChorusNode:=Items.AddChild(NIL,'CHORUS');
      DistortionNode:=Items.AddChild(NIL,'DISTORTION');
      CompressorNode:=Items.AddChild(NIL,'COMPRESSOR');
      AllPassFilterNode:=Items.AddChild(NIL,'ALL PASS FILTER');
      EchoNode:=Items.AddChild(NIL,'ECHO');
      DSPNode:=Items.Add(NIL,'EFFETS DSP');
    End;
End;

Procedure TBrowserEffects.SetTracksGrid(Value:TTracksGrid);
Begin
  fTracksGrid:=Value;
  Self.Invalidate;
End;

Procedure TBrowserEffects.Paint;
Begin
  InHerited;
  With fEffectsView Do
    Begin
      Font.Color:=$00400080;
      Font.Size:=6;
      Color:=ClSilver;
    End;
End;
end.

Je suis confronté à un problème : J'aimerai pouvoir rajouter un enfant à SndFontNode. Cependant si je fais : :fEffectsView.Items.Add(SndFontNode,'Test'); j'ai une magnifique exception qui apparait et je ne comprend pas pourquoi (Ca marche pas non plus avec AddChild). En fait l'idée est que quand je rajoute un TEffect via AnSoundFontCnt.Add, j'ai un noeud enfant qui est rajouté à SndFontNode et cela apparait dans le TreeView. Si quelqu'un comprend pourquoi ca serait cool .

Merci à tous

8 réponses

Bacterius Messages postés 3792 Date d'inscription samedi 22 décembre 2007 Statut Membre Dernière intervention 3 juin 2016 10
11 oct. 2008 à 22:52
Je n'ai pas encore trouvé la solution à ton problème ... mais si je puis me permettre :

Procedure TBrowserTitle.setColorTitle(Value:TColor);
Begin
fColorTitle:=Value;
Invalidate;
End;

Toutes les fonctions de ce style peuvent être avantageusement remplacées par :

Procedure TBrowserTitle.setColorTitle(Value:TColor);
Begin
if Value <> fColorTitle then
begin
fColorTitle:=Value;
Invalidate;
end;
End;

Ca permettra d'éviter une affectation de variable + un dessin, si la propriété est la même.

C'est pas grand-chose mais ça peut aider :)

Cordialement, Bacterius !
0
Utilisateur anonyme
11 oct. 2008 à 23:06
Salut Bacterius,

Je ne suis pas d'accord avec toi  : la procédure setColorTitle(Value:TColor) est appelé une fois en Runtime ou en Designtime lors de la "création" du composant. J'ai fais le choix de ne pas alourdir le code pour cette raison, dans un esprit d'optimisation.

Ce que tu dis est valable pour des valeurs Min,Max et Pos pour un TrackBar ou une ScrollBar
0
Bacterius Messages postés 3792 Date d'inscription samedi 22 décembre 2007 Statut Membre Dernière intervention 3 juin 2016 10
11 oct. 2008 à 23:08
Et les autres ? SetColorSubTitle ?

Si c'est pareil tu peux toutes les modifier et faire 1 seul Invalidate sur le dernier appelé ??

Cordialement, Bacterius !
0
Utilisateur anonyme
12 oct. 2008 à 00:25
SetSubTitle c'est la meme chose :

Procedure TBrowserTitle.SetSubTitle(Value:String);
Begin
  fSubTitle:=Value;
  Invalidate;
End;

Aucune raison de vérifier le sous-titre : une fois qu'il y est aucune raison de le changer .

"Si c'est pareil tu peux toutes les modifier et faire 1 seul Invalidate sur le dernier appelé ?? " : Ben non les procédures sont indépendantes Bacterius. SetSubTitle n'appelle pas setColorTitle par exemple donc je ne vois pas comment je pourrais avoir un seul Invalidate sauf créer une procedure spécifique mais qui faudra bien que j'appelle de toute facon. Donc Invalidate ou cette procédure ca ne change rien en terme d'optimisation.

Avant de parler d'optimisation, j'essaye déjà de résoudre mon probleme . Apres on en reparlera .
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Bacterius Messages postés 3792 Date d'inscription samedi 22 décembre 2007 Statut Membre Dernière intervention 3 juin 2016 10
12 oct. 2008 à 00:29
Mais tu dis que tu appelles en runtime ou en design ces fonctions au moins 1 fois chacune.
Donc, si tu les appelles au moins 1 fois chacune, c'est à dire chacune leur tour - on est toujours d'accord - alors tu n'as pas besoin de mettre Invalidate dans la première, ni dans les suivantes, uniquement dans la dernière - toujours d'accord - car la dernière appellera de toute façon Invalidate.

Chuis dans le brouillard là ... ^^

Cordialement, Bacterius !
0
Utilisateur anonyme
12 oct. 2008 à 01:19
Les couleurs sont justes là pour la décoration : une fois que tu as choisis ta couleur, tu n'y touche plus.
Par contre tu dois pouvoir modifier une couleur indépendamment des autres d'ou le Invalidate a chaque procedure. Ce que tu proposes fais que la changement ne serait valable quand RunTime pas en DesignTime, ce qui n'est pas bon.

De plus comme je viens de l'indiquer, tu dois pouvoir quand meme proposer ces paramétrages.

En résumé : ce que tu proposais allourdissais le code vu la nature meme de l'utilisation de ces fonctions. Une comparaison ne se fait sans contre partie : Dans 99% des cas ta comparaison n'aurait rien changé à l'appel du Invalidate : le seul cas de figure est de choisir deux fois la meme couleur et de facon successives (Du noir),ce qui est peu probable. Par contre dans tout les cas suivant cela induit une comparaison qui en définitif rend ton code lourd. Donc dans un but d'optimisation, j'évite de le faire .
0
Bacterius Messages postés 3792 Date d'inscription samedi 22 décembre 2007 Statut Membre Dernière intervention 3 juin 2016 10
12 oct. 2008 à 01:23
Ok ok ok je me rends tu as gagné ^^'

Sinon pour ton problème (venons-en ...) :

je n'arrive pas à trouver l'endroit qui ne va pas ... mais si mes souvenirs sont bons et que tu utilises TCustomTreeView, pour ajouter un noeud il faut d'abord créer une variable TTreeNode, l'initialiser et ensuite la passer en paramètre dans AddChild ou AddNode ...
Je ne sais pas si tu n'as fait, le code est tellement gros et ma molette est tellement mal foutue ...

Cordialement, Bacterius !
0
Utilisateur anonyme
13 oct. 2008 à 09:47
mes souvenirs sont bons et que tu utilises TCustomTreeView, pour ajouter un noeud il faut d'abord créer une variable TTreeNode, l'initialiser et ensuite la passer en paramètre dans AddChild ou AddNode : c'est ce que j'ai fais Bacterius .

Merci quand même
0
Rejoignez-nous