Ahora mismo he conseguido crear el componente y que autoseleccione pero la parte de que por defecto ponerle ciertas propiedades y que se cree con ellas no lo consigo. Tengo esto que no surte ningun efecto en el tema de las propiedades:
Código PHP:
//---------------------------------------------------------------------------
#ifndef ListBoxAutoSelectH
#define ListBoxAutoSelectH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
//---------------------------------------------------------------------------
class PACKAGE TListBoxAutoSelect : public TListBox
{
private:
int _index;
TWndMethod _oldWndProc;
TNotifyEvent _vScroll;
protected:
virtual void __fastcall WndProc(TMessage &msg);
public:
__property TNotifyEvent OnVerticalScroll = {read = _vScroll, write = _vScroll};
__property int CurrentIndex = {read = _index};
__fastcall TListBoxAutoSelect(TComponent* Owner);
__fastcall ~TListBoxAutoSelect();
__published:
};
//---------------------------------------------------------------------------
#endif
Código PHP:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ListBoxAutoSelect.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TListBoxAutoSelect *)
{
new TListBoxAutoSelect(NULL);
}
//---------------------------------------------------------------------------
__fastcall TListBoxAutoSelect::TListBoxAutoSelect(TComponent* Owner)
: TListBox(Owner)
{
this->Height = this->ItemHeight;
this->Style = lbOwnerDrawFixed;
_oldWndProc = this->WindowProc;
}
//---------------------------------------------------------------------------
__fastcall TListBoxAutoSelect::~TListBoxAutoSelect() {
this->WindowProc = _oldWndProc;
}
//---------------------------------------------------------------------------
virtual void __fastcall TListBoxAutoSelect::WndProc(TMessage &msg) {
if (msg.Msg == WM_VSCROLL) {
_index = GetScrollPos(this->Handle, SB_VERT);
this->Selected[_index] = true;
}
TListBox::WndProc(msg);
}
//---------------------------------------------------------------------------
namespace Listboxautoselect
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TListBoxAutoSelect)};
RegisterComponents("Mis Componentes", classes, 0);
}
}
//---------------------------------------------------------------------------
La idea es que al añadir el componente al TForm ya aparezca con esas propiedades como yo las quiero. Por lo demas funciona perfecto.