Classe non trouvée dans un composant

Résolu
Utilisateur anonyme - 10 juin 2009 à 13:24
 Utilisateur anonyme - 12 juin 2009 à 20:40
Salut à tous ,

J'ai un ptit soucis avec un composant de mon cru. Ce dernier fonctionne très bien quant je l'utilise : il n'y a pas de beugs apparents. Cependant quant je souhaite écrire ou ouvrir ce dernier dans un flux, j'ai droit à un magnifique plantage avec comme alerte "Classe TBrowserTitle non trouvée".

Fonctions utilisées pour l'écriture et la lecture

{>>Procédure pour sauvegarder un projet}
procedure Save_Project(DestFile:String;Components:Array Of TComponent);
Var
  FS:TFileStream;
  IndexElmt:Integer;
Begin
  //On crée FS en mode création
  FS:=TFileStream.Create(DestFile,fmCreate);
  //On essaye
  Try
    //Pour tout les éléments du tableau
    For IndexElmt:=Low(Components) To High(Components) Do
    //D'enregistrer le composant correspondant
    FS.WriteComponent(Components[IndexElmt]);
  //Finalement
  Finally
    //On libere FS
    FS.Free;
  End;
End;

{>>Procédure pour ouvrir un projet}
procedure Open_Project(SourceFile:String;Components:Array Of TComponent);
Var
  FS:TFileStream;
  IndexElmt:Integer;
Begin
  //On crée FS en mode lecture
  FS:=TFileStream.Create(SourceFile,fmOpenRead);
  //On essaye
  Try
    //Pour tout les éléments du tableau
    For IndexElmt:=Low(Components) To High(Components) Do
    //De lire le flux dans le composant correspondant
    FS.ReadComponent(Components[IndexElmt]);
  //Finalement
  Finally
    //On libere FS
    FS.Free;
  End;
End;

Structure du composant :

Type

  {>>TITLE}
  TBrowserTitle = class(TCustomControl)
  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;

{>>TSoundFont}
 TSoundFont = class(TCollectionItem)
  private
    fFileName: string;
    fName: string;   
    fBank:     integer;
    fOnChange: TNotifyEvent;
  protected
    procedure AssignTo(Dest : TPersistent); override;
    procedure Change; virtual;
  public
    constructor Create(ACollection: TCollection); override;
    destructor Destroy; override;
    procedure Assign(Source : TPersistent); override;
  published
    Property Bank:Integer Read fBank Write fBank;
    Property FileName:String Read fFileName Write fFileName;
    Property Name:String Read fName Write fName;
    property OnChange    :TNotifyEvent read fOnChange write fOnChange;
  end;

{>>TSoundFontCnt}
  TSoundFontCnt = class(TOwnedCollection)
  protected
    function GetItem(Index: integer): TSoundFont;
    procedure SetItem(Index: integer; Value: TSoundFont);
  public
    constructor Create(AOwner: TPersistent);
    function Add: TSoundFont;
    property Items[Index: integer]: TSoundFont Read GetItem Write SetItem;
  end;
 
  TSndFntClick_Event=TNotifyEvent;
  TInstrClick_Event=TNotifyEvent; 

{>>TBrowserMidi}
  TBrowserMidi = class(TCustomControl)
  private
    fSoundFont:TSoundFontCnt;
    fBrowserTitle:TBrowserTitle;
    fColorCategories:TColor;
    fColorSndFont:TColor;
    fColorInstrType:TColor;
    fColorInstr:TColor;
    fColorSelected:TColor;
    SndFontShowed:Boolean;
    InstrShowed:Integer;
    fOnInstrClick_Event:TInstrClick_Event;
    fOnSndFntClick_Event:TSndFntClick_Event;   
    Procedure Set_ColorCategories(Value:TColor);
    Procedure Set_ColorSndFont(Value:TColor);
    Procedure Set_ColorInstrType(Value:TColor);
    Procedure Set_ColorInstr(Value:TColor);
    Procedure Set_ColorSelected(Value:TColor);
    Procedure Draw_Panel(Caption:String; ATop:Integer;AColor:TColor);
  protected
    procedure Paint; override;
    procedure Resize;  override; 
    procedure MouseDown(Button: TMouseButton;Shift: TShiftState; X, Y: Integer); override;
  public
    SoundFontSelected:Integer;
    InstrumentSelected:Integer;
    Function InstrToString(Instrument:Byte):String;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    Property Color;
    Property ColorCategories:TColor Read fColorCategories Write Set_ColorCategories;
    Property ColorSndFont:TColor Read fColorSndFont Write Set_ColorSndFont;
    Property ColorInstr:TColor Read fColorInstr Write Set_ColorInstr;
    Property ColorInstrType:TColor Read fColorInstrType Write Set_ColorInstrType;
    Property ColorSelected:TColor Read fColorSelected Write Set_ColorSelected;
    Property SoundFont:TSoundFontCnt Read fSoundFont Write fSoundFont;
    Property BrowserTitle:TBrowserTitle Read fBrowserTitle Write fBrowserTitle;
    property OnSndFntClick_Event:TSndFntClick_Event Read fOnSndFntClick_Event Write fOnSndFntClick_Event;
    Property OnInstrClick_Event:TInstrClick_Event Read fOnInstrClick_Event Write fOnInstrClick_Event;
    property OnClick;
    property OnDblClick;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;   
  end;

Oncreate du composant

{>>TBrowserMidi}
constructor TBrowserMidi.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  DoubleBuffered:=True;
  fSoundFont:=TSoundFontCnt.Create(Self);
  fBrowserTitle:=TBrowserTitle.Create(Self);
  With fBrowserTitle Do
    Begin
     Name:='BrowserTitle';
     SetSubComponent(True);
     Parent:=Self;
     Top:=0;
     Left:=0;
     Height:=49;
    End;
  InstrShowed:=-1;
  SoundFontSelected:=-1;
  InstrumentSelected:=-1;
  SndFontShowed:=False;
  Color:=$00757575;
  fColorCategories:=$00A3A3A3;
  fColorSndFont:=$00CCCCD7;
  fColorInstr:=$00CCCCD7;
  fColorInstrType:=$00A3A3B6;
  fColorSelected:=$00CAEBF9;
end;

Les procédures d'écriture/lecture fonctionnent sans problèmes avec d'autres composants. Le problème vient donc du composant mais j'ai beau chercher ce qui ne va pas, je sèche sur le problème (Je pense que c'est un truc tout con mais parfois on passe devant l'évidence ). J'en appelle donc à votre aide .

Merci d'avance

10 réponses

Guillemouze Messages postés 991 Date d'inscription samedi 25 octobre 2003 Statut Membre Dernière intervention 29 août 2013 6
10 juin 2009 à 14:00
essaye RegisterClass (unité classes)
3
Utilisateur anonyme
10 juin 2009 à 14:34
Salut Guillemouze : je connaissais RegisterClass et cela fonctionne. Ceci dit, j'aimerai comprendre le pourquoi : en effet ici, cela devrait fonctionner sans.
0
Guillemouze Messages postés 991 Date d'inscription samedi 25 octobre 2003 Statut Membre Dernière intervention 29 août 2013 6
10 juin 2009 à 17:38
peut etre a cause de ca :

{>>TSoundFontCnt}
  TSoundFontCnt = class(TOwnedCollection)
  protected
    function GetItem(Index: integer): TSoundFont;
    procedure SetItem(Index: integer; Value: TSoundFont);
  public
    constructor Create(AOwner: TPersistent); override;
    function Add: TSoundFont;
    property Items[Index: integer]: TSoundFont Read GetItem Write SetItem;
  end;
0
Utilisateur anonyme
10 juin 2009 à 19:48
Si je rajoute la directive  override dans le constructeur, je surcharge une méthode statique ce qui provoque une erreur. Merci à toi en tout cas
0

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

Posez votre question
cs_cantador Messages postés 4720 Date d'inscription dimanche 26 février 2006 Statut Modérateur Dernière intervention 31 juillet 2021 13
11 juin 2009 à 10:02
salut Francky23012301,

un petit coup d'oeil là dessus pourrait peut-être résoudre ton problème :http://www.informit.com/articles/article.aspx?p=28278&seqNum=5

cantador
0
Utilisateur anonyme
11 juin 2009 à 12:43
Merci Cantador
0
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
11 juin 2009 à 12:50
rhaaaa franky, je t'ai deja montré comment ne pas ajouter 36 milles Setters ou Getters dans une classe !!!!

type
  TClasstafiore = class
  private
    fA, fB, fC : integer;
    fABC : array[0..2] of integer;
    function GetABC(index: integer): integer;
    procedure SetABC(index: integer; const Value: integer);
    function GetArABC(index: integer): integer;
    procedure SetArABC(index: integer; const Value: integer);
  public
    property A : integer index 0 read GetABC write SetABC;
    property B : integer index 1 read GetABC write SetABC;
    property C : integer index 2 read GetABC write SetABC;
    property ABC[index: integer] : integer read GetABC write SetABC;

    property ArA : integer index 0 read GetArABC write SetArABC;
    property ArB : integer index 1 read GetArABC write SetArABC;
    property ArC : integer index 2 read GetArABC write SetArABC;
    property ArABC[index: integer] : integer read GetArABC write SetArABC;

  end;

{ TClasstafiore }

function TClasstafiore.GetABC(index: integer): integer;
begin
  case index of
    0 : result := fA;
    1 : result := fB;
    2 : result := fC;
  end;
end;

function TClasstafiore.GetArABC(index: integer): integer;
begin
  result := fABC[index];
end;

procedure TClasstafiore.SetABC(index: integer; const Value: integer);
var ptr : integer;
begin
  case index of
    0 : ptr := @fA;
    1 : ptr := @fB;
    2 : ptr := @fC;
  end;

  if ptr^ <> Value then
    ptr^ := Value;
end;

procedure TClasstafiore.SetArABC(index: integer; const Value: integer);
begin
  if fABC[index] <> Value then
    fABC[index] := Value;
end;

0
Utilisateur anonyme
11 juin 2009 à 23:18
Salut f0xi : tu parles pour les TColor ? Oui je sais mais je suis tétu comme une mule . Plus sérieusement il est difficile de perdre de mauvaises habitudes. Peut etre aussi que pour une question de lisibilité/compréhension,  pour ce genre de chose je préfère cette technique : aussi bien codé qu'il soit un code peut vite devenir difficile à comprendre avec ce type d'imbrication : Maintenant effectivement en terme de perf, rendement de travail ta proposition est meilleure. En tout cas merci pour ta remarque
0
Guillemouze Messages postés 991 Date d'inscription samedi 25 octobre 2003 Statut Membre Dernière intervention 29 août 2013 6
11 juin 2009 à 23:41
petite info supplementaire par rapport au code de foxi, tu peux aussi le faire avec un enum, ce qui est plus clair qu'un integer:

type
   TBMcolor = (sfcCategories, sfcSndFont, sfcInstr, sfcInstrType, sfcSelected);

const
  DefaultColors: array[TBMcolor] of TColor = ($00A3A3A3, $00CCCCD7, $00CCCCD7, $00A3A3B6, $00CAEBF9);

type
   TBrowserMidi = class(TCustomControl)
  private
    fColors : array[TBMcolor] of TColor;
    function GetColor(index: TBMcolor): TColor;
    procedure SetColor(index: TBMcolor; const Value: TColor);
  public
    property ColorCategories : TColor index sfcCategories read GetColor write SetColor;
    ...

 
0
Utilisateur anonyme
12 juin 2009 à 20:40
Merci à vous : je vais regarder tout cela
0
Rejoignez-nous