Fehler TListBox OnDrawItem

Rund um die LCL und andere Komponenten
Antworten
AlterMann
Beiträge: 233
Registriert: So 13. Dez 2009, 09:43
OS, Lazarus, FPC: Lazarus 3.0 (rev lazarus_3_0) FPC 3.2.2 i386-win32-win32/win64
CPU-Target: x86 64Bit
Wohnort: Niederösterreich

Fehler TListBox OnDrawItem

Beitrag von AlterMann »

Guten Morgen

Ich versuche gerade mir eine ListBox zu basteln der ich die Schriftfarbe jedes Eintrags mitgeben kann.

Doch komischerweise bekomme ich einen Fehler "Wrong number of Parameters" und (anscheinend als Folgefehler) "Found declaration" (siehe Quellcode)

Auf welcher Leitung stehe ich gerade wieder?

Bitte um Hilfe
Chris

Code: Alles auswählen

unit uFarbListBox;

{$mode ObjFPC}{$H+}

interface

uses
  Classes, SysUtils, Controls, StdCtrls, Graphics;

type


 TFarbListBox = class(TListBox)
  constructor create(AOwner: TComponent);override;
  function Add(const s:string; farbe : TColor):integer;
  procedure OwnDrawItem(Control: TWinControl; Index: Integer;ARect: TRect;State: TOwnerDrawState);
 public
  farben : array of TColor;
 end;

implementation

 procedure TFarbListBox.OwnDrawItem(Control: TWinControl; Index: Integer;ARect: TRect;State: TOwnerDrawState); //-- Error: Found declaration: OwnDrawItem(TWinControl;LongInt;TRect;TOwnerDrawState);
 
 var
   ListBox: TListBox;
   Canvass: TCanvas;
   S: string;
 begin
   ListBox := Control as TListBox;
   Canvass := ListBox.Canvas;
   Canvass.Font.Color := TColor(ListBox.Items.Objects[Index]);
   S := ListBox.Items[Index];
 end;

 function TFarbListBox.Add(const s:string; farbe : TColor):integer;

  var i : integer;

  begin
   i := Items.Add(s);
   setlength(farben,Items.Count);
   farben[i] := farbe;
  end;

 constructor TFarbListBox.create(AOwner: TComponent);

  begin
   inherited create(AOwner);
   Style := lbOwnerDrawFixed;
   setlength(farben,0);
   OnDrawItem := TFarbListBox.OwnDrawItem;   //<-- Error: Wrong number of parameters specified for call to "OwnDrawItem"
  end;


end. 
Früher war alles besser. Und aus Holz!

Benutzeravatar
fliegermichl
Lazarusforum e. V.
Beiträge: 1436
Registriert: Do 9. Jun 2011, 09:42
OS, Lazarus, FPC: Lazarus Fixes FPC Stable
CPU-Target: 32/64Bit
Wohnort: Echzell

Re: Fehler TListBox OnDrawItem

Beitrag von fliegermichl »

OndrawItem := @OwnDrawItem;

AlterMann
Beiträge: 233
Registriert: So 13. Dez 2009, 09:43
OS, Lazarus, FPC: Lazarus 3.0 (rev lazarus_3_0) FPC 3.2.2 i386-win32-win32/win64
CPU-Target: x86 64Bit
Wohnort: Niederösterreich

Re: Fehler TListBox OnDrawItem

Beitrag von AlterMann »

Danke.
Versuch ich gleich

Edit:
Wunderbar. Ich hatte zunächst @FarbListBox.OwnDrawItem.
Aber da kam:
ufarblistbox.pas(51,18) Error: Incompatible types: got "<address of procedure(TWinControl;LongInt;TRect;TOwnerDrawState) of object;Register>" expected "<procedure variable type of procedure(TWinControl;LongInt;TRect;TOwnerDrawState) of object;Register>"

Danke Dir!
Früher war alles besser. Und aus Holz!

Antworten