Newsgroup: it.comp.lang.delphi
Titolo: derivare un componente visuale

Ciao a tutti,
sto provando a derivare un componente grid inserendo alcuni metodi a me 
necessari. Ho creato il mio package e l'ho installato nella component 
palette, ma quando vado a posizionare il componente nella form non vedo 
nessuna cella...
 
qualche dritta???
-------------------------------------------------
 
Type
   TEliveFMXSongGrid = class(TTMSFMXGrid)
   private
 
     fBrowserCursor: TBrowserCursor;
     fArchivesPath: string;
     fArchiveName: string;
     fGroupName: string;
     fSongExtensions: String;
     fSongArchive: TSongArchive;
 
     procedure Empty;
     procedure PopulateGrid;
     procedure SetArchivesPath(const Value: string);
     procedure FillWithMarkedSongs;
     procedure FillWithArchives(aList: TStringList);
     procedure FillWithArchiveStructure;
     procedure FillWithGroups(aList: TStringList);
 
   protected
 
   public
 
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
     Property ArchivesPath: string read fArchivesPath write SetArchivesPath;
   published
 
   end;

 nessuna cella...
 
Generalmente, quando sviluppi un qualsiasi tipo di componente, per testarlo è meglio istanziarlo a runtime in un progetto di test; in caso contrario, se il codice contiene errori, rischi di rendere inservibile l'IDE di Delphi, dato che è quello il "consumatore" della tua logica quando usi il componente a designtime.
 
Detto questo, dovresti verificare quali sono le dimensioni predefinite del controllo che crei e se i metodi che inizializzano la griglia come vuoi tu vengono richiamati, ma andando in debugging a runtime e creando dinamicamente un'istanza del componente dovresti scroprirlo senza problemi, mettendo i relativi breakpoint e analizzando i valori delle proprietà del controllo.
 
Ciao!
  Marco.
 
-- 
MARCO BREVEGLIERI
#Home: 
http://www.marco.breveglieri.name
 
#Blog: 
http://www.compilaquindiva.net
 

 qualche dritta???
 
Posta il codice COMPLETO.
 
 
A.


eccolo...
ho anche provato a creare un nuovo componente derivato da TTMSFMXGrid
senza fare l'override di alcun metodo e quando lo posiziono sulla form o 
lo instalzio a runtime non mi visualizza le colonne...
 
derivando lo stesso componente da TGrid funziona bene... quindi credo il 
problema sia sulla classe genitrice ma non riesco a capire come fare...
 
-----------------------------------------------------
 
 
unit eLive_FMXSongGrid;
 
interface
 
uses
   System.SysUtils, System.Classes, System.Math, UITypes, Types,
   Data.Bind.Components, Data.Bind.Grid,
   Data.Bind.DBScope, Data.DB, Data.Bind.Consts,
   Generics.Collections,
 
   FMX.Dialogs,
   FMX.TMSCustomGrid,
   FMX.TMSGridOptions,
   FMX.TMSGridData,
   FMX.TMSBaseControl,
   FMX.Types,
   FMX.Edit,
   FMX.TMSGridCell,
 
   elive_Utils, elive_regexpr, eLive_SongArchive,
 
   FMX.Controls, FMX.TMSGrid;
 
const
 
   SONG_GRID_TEXT_COL = 0;
   SONG_GRID_TYPE_COL = 1;
   SONG_GRID_FILE_COL = 2;
   SONG_GRID_ARCHIVE_TEXT = '-ARCHIVE-';
   SONG_GRID_ALL_SONGS_TEXT = '-ALL_SONGS-';
   SONG_GRID_AUDIO_SONGS_TEXT = '-AUDIO_SONGS-';
   SONG_GRID_MIDI_SONGS_TEXT = '-MIDI_SONGS-';
   SONG_GRID_GROUPS_TEXT = '-GROUPS-';
   SONG_GRID_GROUP_TEXT = '-GROUP-';
   SONG_GRID_SONG_TEXT = '-SONG-';
   SONG_GRID_FONT_TEXT = '-FONT-';
 
   ALL_SONGS_EXTENSIONS = 'MP3,WAV,MID,KAR,RMI';
   AUDIO_SONGS_EXTENSIONS = 'MP3,WAV';
   MIDI_SONGS_EXTENSIONS = 'MID,KAR,RMI';
 
type
 
   TBrowserCursor = (cuArchives, cuArchive, cuAllSongs, cuAudioSongs, 
cuMidiSongs, cuGroups, cuGroup);
 
   TEliveFMXSongGrid = class(TTMSFMXGrid)
   private
 
     fBrowserCursor: TBrowserCursor;
     fArchivesPath: string;
     fArchiveName: string;
     fGroupName: string;
     fSongExtensions: String; // comma repared es: 'MP3,MID,OGG'
     fSongArchive: TSongArchive;
 
     procedure Empty;
     procedure PopulateGrid;
     procedure SetArchivesPath(const Value: string);
     procedure FillWithMarkedSongs;
     procedure FillWithArchives(aList: TStringList);
     procedure FillWithArchiveStructure;
     procedure FillWithGroups(aList: TStringList);
 
   protected
     { Protected declarations }
   public
     { Public declarations }
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
     Property ArchivesPath: string read fArchivesPath write SetArchivesPath;
   published
     { Published declarations }
   end;
 
procedure Register;
 
implementation
 
procedure Register;
begin
   RegisterComponents('eLive', [TEliveFMXSongGrid]);
end;
 
{ EliveFMXSongGrid }
 
constructor TEliveFMXSongGrid.Create(AOwner: TComponent);
begin
   inherited;
   fBrowserCursor := cuArchives;
   fArchivesPath := '';
   fArchiveName := '';
   fGroupName := '';
   fSongExtensions := '';
   fSongArchive := TSongArchive.Create();
end;
 
destructor TEliveFMXSongGrid.Destroy;
begin
   fSongArchive.Free;
   inherited;
end;
 
procedure TEliveFMXSongGrid.Empty;
begin
   RowCount := 0;
   Cells[SONG_GRID_TEXT_COL, 0] := '';
   Cells[SONG_GRID_TYPE_COL, 0] := '';
   Cells[SONG_GRID_FILE_COL, 0] := '';
end;
 
procedure TEliveFMXSongGrid.FillWithArchives(aList: TStringList);
var
   i: Integer;
begin
   RowCount := aList.Count;
   for i := 0 to aList.Count - 1 do
   begin
     Cells[SONG_GRID_TEXT_COL, i] := aList[i];
     Cells[SONG_GRID_TYPE_COL, i] := SONG_GRID_ARCHIVE_TEXT;
     Cells[SONG_GRID_FILE_COL, i] := '';
   end;
end;
 
procedure TEliveFMXSongGrid.FillWithArchiveStructure;
begin
   RowCount := 4;
 
   Cells[SONG_GRID_TEXT_COL, 0] := 'ALL SONGS';
   Cells[SONG_GRID_TEXT_COL, 1] := 'AUDIO SONGS';
   Cells[SONG_GRID_TEXT_COL, 2] := 'MIDI SONGS';
   Cells[SONG_GRID_TEXT_COL, 3] := 'GROUPS';
 
   Cells[SONG_GRID_TYPE_COL, 0] := SONG_GRID_ALL_SONGS_TEXT;
   Cells[SONG_GRID_TYPE_COL, 1] := SONG_GRID_AUDIO_SONGS_TEXT;
   Cells[SONG_GRID_TYPE_COL, 2] := SONG_GRID_MIDI_SONGS_TEXT;
   Cells[SONG_GRID_TYPE_COL, 3] := SONG_GRID_GROUPS_TEXT;
 
   Cells[SONG_GRID_FILE_COL, 0] := '';
   Cells[SONG_GRID_FILE_COL, 1] := '';
   Cells[SONG_GRID_FILE_COL, 2] := '';
   Cells[SONG_GRID_FILE_COL, 3] := '';
end;
 
procedure TEliveFMXSongGrid.FillWithGroups(aList: TStringList);
var
   i: Integer;
begin
   RowCount := aList.Count;
   for i := 0 to aList.Count - 1 do
   begin
     Cells[SONG_GRID_TEXT_COL, i] := aList[i];
     Cells[SONG_GRID_TYPE_COL, i] := SONG_GRID_GROUP_TEXT;
     Cells[SONG_GRID_FILE_COL, i] := '';
   end;
end;
 
procedure TEliveFMXSongGrid.FillWithMarkedSongs;
var
   c, i: Integer;
   TargetRow: Integer;
begin
   c := 0;
   for i := 0 to fSongArchive.Count - 1 do
     if fSongArchive.song[i].isMarked then
     begin
       if fSongArchive.song[i].Position <> 0 then
         TargetRow := fSongArchive.song[i].Position - 1
       else
         TargetRow := c;
 
       Cells[SONG_GRID_TEXT_COL, TargetRow] := 
fSongArchive.song[i].FormattedSongName;
       Cells[SONG_GRID_FILE_COL, TargetRow] := 
fSongArchive.song[i].FullFileName;
       Cells[SONG_GRID_TYPE_COL, TargetRow] := SONG_GRID_SONG_TEXT;
       inc(c);
       RowCount := max(TargetRow + 1, RowCount);
     end;
end;
 
procedure TEliveFMXSongGrid.PopulateGrid;
var
   sl: TStringList;
begin
   BeginUpdate;
   Empty;
   sl := TStringList.Create;
   try
     case fBrowserCursor of
 
       cuArchives:
         begin
           getDirList(fArchivesPath, sl);
           sl.Sort;
           FillWithArchives(sl);
         end;
 
       cuArchive:
         begin
           fSongArchive.loadArchive(fArchiveName);
           FillWithArchiveStructure;
         end;
 
       cuAllSongs:
         begin
           fSongArchive.MarkSongsFromType(ALL_SONGS_EXTENSIONS);
           FillWithMarkedSongs;
         end;
 
       cuAudioSongs:
         begin
           fSongArchive.MarkSongsFromType(AUDIO_SONGS_EXTENSIONS);
           FillWithMarkedSongs;
         end;
 
       cuMidiSongs:
         begin
           fSongArchive.MarkSongsFromType(MIDI_SONGS_EXTENSIONS);
           FillWithMarkedSongs;
         end;
 
       cuGroups:
         begin
           FillWithGroups(fSongArchive.Groups);
         end;
 
       cuGroup:
         begin
           FillWithMarkedSongs;
         end;
     end;
 
   finally
     sl.Clear;
     sl.Free
   end;
 
   EndUpdate;
end;
 
procedure TEliveFMXSongGrid.SetArchivesPath(const Value: string);
begin
   fArchivesPath := Value;
   fBrowserCursor := cuArchives;
   PopulateGrid;
end;
 
end.

L'unica cosa che noto cosi su 2 natiche e' l'assenza di una assegnazione per colcount.
A parte cio', tu sei certo che fSongArchive.Count è maggiore di zero?
 
A.
 


 
si, � sempre maggiore di 0 ma questo non ha influenza sul problema...
...
facendo altre prove ho notato che, anche se derivo un componente visuale 
senza ridefinirne alcun metodo e senza creare altre propriet�, quando lo 
instanzio non mi visualizza le colonne...
 
---------------------------------------
 
unit eLive_FMXSongGrid;
 
interface
 
uses
   System.SysUtils, System.Classes, System.Math, UITypes, Types,
   Data.Bind.Components, Data.Bind.Grid,
   Data.Bind.DBScope, Data.DB, Data.Bind.Consts,
   Generics.Collections,
   FMX.Dialogs,
   FMX.TMSCustomGrid,
   FMX.TMSGridOptions,
   FMX.TMSGridData,
   FMX.TMSBaseControl,
   FMX.Types,
   FMX.Edit,
   FMX.TMSGridCell,
   FMX.Controls, FMX.TMSGrid;
 
type
 
   TEliveFMXSongGrid = class(TTMSFMXGrid)
   private
     { Private declarations }
   protected
     { Protected declarations }
   public
     { Public declarations }
   published
     { Published declarations }
   end;
 
implementation
 
 
end.

 instanzio non mi visualizza le colonne...
 
prova il suggerimento di Marco: crealo a runtime e fai un trace.
 
A.