Autor Beitrag
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 21.02.08 18:33 
Hallo,

ich habe folgenden Code um die Hintergrundfarbe eines ListItems zu verändern:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
  ListBrush: TBrush;
  R: TRect;
begin
  with LinkBox do
  begin
    ListBrush := TBrush.Create;
    ListBrush.Style := bsSolid;
    ListBrush.Color := clRed;

    Perform(LB_GETITEMRECT, 0, Longint(@R));
    Windows.FillRect(Handle, R, ListBrush.Handle);  // Rechteck ausmalen
    Brush.Style := bsClear;
    TextOut(R.Left, R.Top, Items[0]);  // Text schreiben
    ListBrush.Free;
  end;
end;


LinkBox ist eine TListBox. Der Compiler meckert bei der Zeile mit TextOut: Inkompatible Typen: 'Integer' und 'string'
Aber es ist doch alles richtig, Items[0] ist doch ein string. Was mach ich falsch?


Moderiert von user profile iconNarses: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Do 21.02.2008 um 19:08
LorenzS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

MS-DOS, WIN 7, WIN 10
BP7.0, D3, D5
BeitragVerfasst: Do 21.02.08 19:09 
verscuhe mal
ausblenden Delphi-Quelltext
1:
TextOut(R.Left, R.Top, Items.Strings[0]);  // Text schreiben					
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 21.02.08 19:11 
Moin!

Wo hast du den Code her und in welchem Ereignis steckt er drin? :gruebel:

Warum nicht so (wie in dem anderen Thread): :nixweiss:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);  
begin  
  with Control as TListBox do begin  
    Canvas.Brush.Color := clRed;
    Canvas.FillRect(Rect);  
    Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]);  
  end;  
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Popov
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1655
Erhaltene Danke: 13

WinXP Prof.
Bei Kleinigkeiten D3Pro, bei größeren Sachen D6Pro oder D7
BeitragVerfasst: Do 21.02.08 19:13 
Fehlt da nicht Canvas?

_________________
Popov
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 21.02.08 19:15 
Ich hab rausgefunden, dass TextOut neuerdings mehrere Parameter hat. Jetzt geht es.
ausblenden Delphi-Quelltext
1:
function TextOut(DC: HDC; X, Y: Integer; Str: PChar; Count: Integer): BOOL;					


O_o, stimmt ich hab das Canvas. vergessen, so will es das TextOut in "Windows" aufrufen.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Do 21.02.08 19:19 
user profile iconLorenzS hat folgendes geschrieben:
verscuhe mal TextOut(R.Left, R.Top, Items.Strings[0]);

Das braucht man nicht - Strings ist die Standardeigenschaft von Items

user profile iconHendi48 hat folgendes geschrieben:
Jetzt geht es.  function TextOut(DC: HDC; X, Y: Integer; Str: PChar; Count: Integer): BOOL;

Das stimmt wohl. Aber besonders elegant ist es nicht ;)

user profile iconPopov hat folgendes geschrieben:
Fehlt da nicht Canvas?

Jop, da fehlt Canvas. Und deshalb auch:

user profile iconHendi48 hat folgendes geschrieben:
Ich hab rausgefunden, dass TextOut neuerdings mehrere Parameter hat.

TextOut hat nicht neuderdings mehrere Parameter. Du hast einfach nach der falschen Funktion gesucht :D

Das nur, um ein bisschen Ordnung reinzubringen.

Edit: Ich sehe gerade, du hast deinen Fehler schon gefunden :zustimm: