[Edit] Dieser Fehler ist Gelöst wenn ich den Teil mit der Combobox nach oben verschiebe (habe es im Code unten geändert)... ist eigentlich auch logisch, denn die Combobox muss ja zuerst erstellt sein bevor die SelectCell Funktion drauf zugreifen kann... (Delphi scheint das egal oder ändert das automatisch ?)
Jedoch funktioniert das mit den Ereignisroutinen zuweisen nicht... Weiß jemand warum ?
Code: Alles auswählen
unit GridCombo;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Variants, Grids, Forms, Dialogs, Controls,
StdCtrls, Windows, Messages, Graphics, ComCtrls;
type
TGridCombo = class(TStringGrid)
private
FInGridCombo: TComboBox;
protected
function SelectCell(ACol: Integer; ARow: Integer): Boolean; override;
public
constructor Create(AOwner: TComponent); override;
procedure Nachricht(Sender: TObject); //OnChange von FInGridCombo: TComboBox;
procedure WennExit(Sender: TObject); //OnExit von TGridCombo
end;
implementation
//TGridCombo Methoden
constructor TGridCombo.Create(AOwner: TComponent);
begin
FInGridCombo := TComboBox.Create(AOwner); //Zuerst, sonst absturz
with FInGridCombo do
begin
Parent := AOwner as TWinControl;
Visible:= False;
//OnChange := Nachricht; //Ereignisroutine zuweisen //geht nicht
end;
inherited Create(AOwner);
Parent := AOwner as TWinControl; //Typumwandlung
Left := 10;
Top := 50;
DefaultColWidth := 100;
DefaultRowHeight := 23;
FixedCols := 0;
FixedRows := 0;
ColCount := 4;
RowCount := 5;
GridLineWidth := 1;
Width := 500;
Height := 200;
//OnExit:= WennExit; //Ereignisroutine zuweisen //geht nicht Parameter ?
//Selection:= TGridRect(Rect(-1, -1, -1, -1)); //geht nicht
end;
function TGridCombo.SelectCell(ACol: Integer; ARow: Integer): Boolean;
var
CRect:TRect;
begin
if(ACol=1)then
begin
CRect:= CellRect(ACol, ARow);
inc(CRect.Left, Left+2);
inc(CRect.Right, Left+2);
inc(CRect.Top, Top+2);
inc(CRect.Bottom, Top+2);
FInGridCombo.BoundsRect:=CRect;
FInGridCombo.Visible:=true;
FInGridCombo.ItemIndex:=integer(Objects[ACol, ARow])-1;
end
else FInGridCombo.Visible:= false;
Result:=true;
end;
//OnChange Ereignis von TComboBox
procedure TGridCombo.Nachricht(Sender: TObject);
begin
end;
//OnExit von TGridCombo
procedure TGridCombo.WennExit(Sender: TObject);
begin
//if not(AOwner.ActiveControl=FInGridCombo)then
//begin
FInGridCombo.Visible:=false;
//Selection:= TGridRect(Rect(-1, -1, -1, -1));
// end;
end;
Code: Alles auswählen
procedure TForm1.FormCreate(Sender: TObject);
begin
GridCombo1 := TGridCombo.Create(Form1);
end;