unit TaggedCoBo;
interface
uses
Windows, Messages, SysUtils, Consts, Classes, Controls, StdCtrls;
type
TTaggedComboBox =
class(TComboBox)
private
{ Private declarations }
protected
{ Protected declarations }
function GetItemsClass: TCustomComboBoxStringsClass;
override;
public
{ Public declarations }
published
{ Published declarations }
end;
TTaggedComboBoxStrings =
class (TCustomComboBoxStrings)
public
function Addnew(
const S:
string; tag: integer): Integer;
//Insert ist noch nicht berücksichtigt....
procedure Insert(
Index: Integer;
const S:
string);
override;
function GetTag (idx: integer): integer;
private
TagArray:
array of integer;
function Add(
const S:
string): Integer;
override;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
MyComponents', [TTaggedComboBox]);
end;
function TTaggedComboBox.GetItemsClass: TCustomComboBoxStringsClass;
begin
//Hier die Modifizierte Stringklasse zurückgeben
Result := TTaggedComboBoxStrings;
//inherited;
end;
function TTaggedComboBoxStrings.Addnew(
const S:
string; tag: integer): Integer;
begin
//Den Tag verwalten
//String in das Array an der letzten Position einfügen
SetLength(TagArray, high(TagArray)+1);
TagArray[high(TagArray)];
//Das eigentliche Add aufrufen
Result:=Add(S);
end;
function TTaggedComboBoxStrings.GetTag (idx: integer): integer;
begin
if idx <= high(TagArray)
then
Result:=TagArray[idx];
end;
function TTaggedComboBoxStrings.Add(
const S:
string): Integer;
begin
Result := SendMessage(ComboBox.Handle, CB_ADDSTRING, 0, Longint(PChar(S)));
if Result < 0
then
raise EOutOfResources.Create(SInsertLineError);
end;
procedure TTaggedComboBoxStrings.Insert(
Index: Integer;
const S:
string);
begin
if SendMessage(ComboBox.Handle, CB_INSERTSTRING,
Index,
Longint(PChar(S))) < 0
then
raise EOutOfResources.Create(SInsertLineError);
end;
end.