Autor Beitrag
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Do 22.05.03 16:23 
Hallo,
wie kann ich jede vierte zeile einfähreben ?
ich habe es mit volgenden code versucht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
  i:Integer;
begin
  if item.index mod StrToInt(Edit2.Text) <> 0 then begin
    ListView1.Canvas.Font.Color:=clYellow;
    ListView1.Canvas.Brush.Color:=clRed;
    ListView1.Canvas.Font.Style:=[fsBold]
  end
  else begin
    ListView1.Canvas.Font.Color:=clBlue;
    ListView1.Canvas.Brush.Color:=clLime;
    ListView1.Canvas.Font.Style:=[fsBold]
  end;

aber das hat nicht funktioniert. Warum nicht ?

_________________
MFG
Michael Springwald, "kann kein englisch...."
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: Mi 28.05.03 12:55 
Wenn Du genau diesen Code als Behandlungsroutine für OnCustomDrawItem verwendest, sollte es eigentlich gehen...

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mi 28.05.03 14:08 
aber es geht nicht, so wie ich es haben wollte.
der macht jetzt: jede vierte zeile in einer anderen farhbe, was ich haben wollte ist:
die ersten vier zeilen solln z.b. rot angezeigt werden, die nächsten vier zeilen sollen grün angezeigt werden und so weiter.....

_________________
MFG
Michael Springwald, "kann kein englisch...."
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Mi 28.05.03 14:14 
Dann sag das doch auch ;)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
var 
  i:Integer; 
  x: Boolean;
begin 
  if item.index mod StrToInt(Edit2.Text) <> 0 then
    x:=not x;
  if x then begin
    ListView1.Canvas.Font.Color:=clYellow; 
    ListView1.Canvas.Brush.Color:=clRed; 
    ListView1.Canvas.Font.Style:=[fsBold] 
  end 
  else begin 
    ListView1.Canvas.Font.Color:=clBlue; 
    ListView1.Canvas.Brush.Color:=clLime; 
    ListView1.Canvas.Font.Style:=[fsBold] 
  end;


ungetestet, sollte aber gehen ;)

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mi 28.05.03 14:32 
ist genau wie vorher, erzeichnet nur die erste vierte zeile in eine ander farhbe, aber das will ich nicht :(
z.b:
sollen rot sein(die items)
1
2
3
4
sollen grün sein
5
6
7
8

_________________
MFG
Michael Springwald, "kann kein englisch...."
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Mi 28.05.03 14:43 
Hi,

ja ok.. wie gesagt, ungetestet *g*
Das sollte nun aber gehen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  if item.index mod 4 = 0 then
    x:=not x;
  if x then begin
    ListView1.Canvas.Font.Color:=clYellow;
    ListView1.Canvas.Brush.Color:=clRed;
    ListView1.Canvas.Font.Style:=[fsBold]
  end else begin
    ListView1.Canvas.Font.Color:=clBlue;
    ListView1.Canvas.Brush.Color:=clLime;
    ListView1.Canvas.Font.Style:=[fsBold]
  end;


x muß eine Globale Variable sein! (Wieder ungetestet)

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mi 28.05.03 17:39 
Es geht, aber leider nur bis er bei 8 items ist, dann gehts nicht mehr :(
also die ersten 8 zeilen macht er richtig, die zeilen die da nach kommen, macht er falsch. und wnen ich zu den ersten hinscrolle zeichnet er die auch in der falschen farhbe :(
ich glaube ich kenne auch den grund:

Item.index mod 4 bei 8 zeilen würde das funktionieren :)

_________________
MFG
Michael Springwald, "kann kein englisch...."
superchatti
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 296

Win XP, Red Hat Linux 7.3
Delphi 6 PE
BeitragVerfasst: Mi 28.05.03 18:16 
Das Tehma...
Da hätte ich auch eine Frage!!

Wie geht es das die 2.,4.,6.,8. ... zum Beispiel Gelb ist??

Natürlich jede 2. Zeile wie oben angegeben!!

_________________
mfG Superchatti
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Mi 28.05.03 18:27 
Hi,

@Mimi: Also bei mir geht das auch über 8 Zeilen hinaus... liegt an deinem restlichen Code :)

@superchatti: Genauso wie bei Mimi, nur mit "item.Index mod 2".

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
superchatti
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 296

Win XP, Red Hat Linux 7.3
Delphi 6 PE
BeitragVerfasst: Mi 28.05.03 18:49 
Danke!!!

_________________
mfG Superchatti
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mi 28.05.03 19:03 
nein, ich habe deinen code so übernommen wie du ihn geschrieben hast.
und jetzt macht er folgendes:
bei den 1. 8 macht er es richtig(also 4 Grün und die Weiteren 4 Blau z.b.)
und dann macht er alles in einer farbe der grund:
teile mal 4 durch 4 was kommt rauß ?
1
und jetzt teile mal 8 durch 4 was kommt rauß ?
4 und jetzt teile mal 9 durch 4, was kommt rauß ????
ich dachte auch es sei so einfach :)

_________________
MFG
Michael Springwald, "kann kein englisch...."
superchatti
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 296

Win XP, Red Hat Linux 7.3
Delphi 6 PE
BeitragVerfasst: Mi 28.05.03 19:11 
Öhm!
Mimi??
8 geteilt durch 4 ist nicht 4!!

_________________
mfG Superchatti
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Mi 28.05.03 19:15 
Hi,

Mimi... sicherlich ist 8/4 = 2 und nicht 1.. aber das ist ziemlich absolut egal ;)

8 mod 4 = 0
4 mod 4 = 0
12 mod 4 = 0
9 mod 4 = 1
10 mod 4 = 2

poste dochmal deinen Kompletten Code.. der Fehler ist 100%ig woanders, denn bei mir klappt es einwandfrei.

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
superchatti
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 296

Win XP, Red Hat Linux 7.3
Delphi 6 PE
BeitragVerfasst: Mi 28.05.03 19:17 
Irgendwie funktioniert der ganze code bei mir nicht!
lol

_________________
mfG Superchatti
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mi 28.05.03 19:22 
habes gelöst, habe einfach eine pratkische sache bei meinem Programm genutzt.
aber mein weg, geht auch nur in meinem Programm denn könnte man nicht übernehmen für andere.
der code vom Programm:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons;

type
  TForm1 = class(TForm)
    Edit1: TLabeledEdit;
    Edit2: TLabeledEdit;
    Bevel1: TBevel;
    ListView1: TListView;
    Label1: TLabel;
    Bevel2: TBevel;
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure ListView1CustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  rArray:array of Integer;
  is_e:String = '';
  x:Bool;
implementation

uses Tools;

{$R *.dfm}

function GetExeDir:String;
begin
  result:=ExtractFileDir(ParamStr(0)) + '\';
end;

function is_array_e(rArray:array of Integer; r:Integer):Bool;
var
  i:Integer;  
begin
  result:=False;
  for i:=0 to HIGH(rArray) do begin
    if rArray[i] = r then begin
      result:=True;
      Exit;
    end;
  end;
end;

function ifStr(r:Integer):Integer;
var
  i:integer;
begin
  result:=-1;
  //1,2,3,6,7,11
  for i:=2 to NumToken(is_e,',') do begin
    if GetToken( is_e,',',i) = IntToStr(r)  then begin
      result:=i;
      Exit;
    end;
  end;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  MaxT, MaxG, r, i,x:Integer;
  Names:TStringList;
  tg:string;
begin
  if Edit1.Text = '' then begin
    ShowMessage('Anzahl der Teielnehmer Fehlen !');
    Edit1.SetFocus;
    Exit;
  end;

  if Edit2.Text = '' then begin
    ShowMessage('Teielnehmern in Gruppen Fehlern !');
    Edit2.SetFocus;
    Exit;
  end;

  MaxT:=StrToInt(Edit1.Text);
  MaxG:=StrToInt(Edit2.Text);
  is_e:='';
  if ( MaxT mod MaxG  <> 0) or ( StrToInt(Edit1.Text) in [ ord(1),ord(2),ord(3),ord(6),ord(7),ord(11)]) then begin;
    ShowMessage('Ungültige Teielnehmer zahl');
    Edit2.SetFocus;
  end; 

  Names:=TStringList.Create;

  if FileExists(GetExeDir + 'names.txt') = False then begin
    ShowMessage('Datei Names.txt nicht gefunden');
    Exit;
  end
  else
    Names.LoadFromFile(GetExeDir + 'names.txt');

  ListView1.Items.Clear;
  SetLength(rArray, Maxt);
  Randomize;
  for i:=1 to MaxT div MaxG do begin

    for x:=1 to MaxG do begin
      r:=Random(MaXT)+1;
      repeat
        r:=Random(MaXT)+1;
      until ifStr(r) = -1 ;

      is_e:=is_e + ',' + IntToStr(r) ;
      with ListView1.Items.Add do begin
        Caption:=Names.Strings[r-1];
        SubItems.Add(IntToStr(i))
      end;
    end;

  end;
end;

procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  x:=odd( StrToInt(item.SubItems.Strings[0]));
  if x then begin
    ListView1.Canvas.Font.Color:=clYellow;
    ListView1.Canvas.Brush.Color:=clRed;
    ListView1.Canvas.Font.Style:=[fsBold]
  end else begin
    ListView1.Canvas.Font.Color:=clBlue;
    ListView1.Canvas.Brush.Color:=clLime;
    ListView1.Canvas.Font.Style:=[fsBold]
  end;

end;

end.

der fehler, in deinem cod ist folgender:
wenn es 12 ist es ist im jeden fall durch 4 teielbar. und so
das gleiche gilt für 8 und die anderenzahlen

_________________
MFG
Michael Springwald, "kann kein englisch...."
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Mi 28.05.03 20:01 
superchatti hat folgendes geschrieben:
Irgendwie funktioniert der ganze code bei mir nicht!
lol


Einfach dashier in dein OnItemDraw packen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  x:=not x; 
  if x then begin 
    ListView1.Canvas.Font.Color:=clYellow;  
    ListView1.Canvas.Brush.Color:=clRed;  
    ListView1.Canvas.Font.Style:=[fsBold]  
  end  
  else begin  
    ListView1.Canvas.Font.Color:=clBlue;  
    ListView1.Canvas.Brush.Color:=clLime;  
    ListView1.Canvas.Font.Style:=[fsBold]  
  end;


und x als Globale Boolean Variable deklarieren.

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
superchatti
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 296

Win XP, Red Hat Linux 7.3
Delphi 6 PE
BeitragVerfasst: Mi 28.05.03 20:14 
Gut mach ich!

_________________
mfG Superchatti
superchatti
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 296

Win XP, Red Hat Linux 7.3
Delphi 6 PE
BeitragVerfasst: Mi 28.05.03 20:15 
Geht immer noch dein!

_________________
mfG Superchatti
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Mi 28.05.03 20:41 
wenn er nur jeden 2. machen will ist es einfach:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  if odd(item.index) = True then
    if x then begin  
      ListView1.Canvas.Font.Color:=clYellow;   
      ListView1.Canvas.Brush.Color:=clRed;   
      ListView1.Canvas.Font.Style:=[fsBold]   
    end   
    else begin   
      ListView1.Canvas.Font.Color:=clBlue;   
      ListView1.Canvas.Brush.Color:=clLime;   
      ListView1.Canvas.Font.Style:=[fsBold]   
    end;

_________________
MFG
Michael Springwald, "kann kein englisch...."
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: Do 29.05.03 00:53 
Für alle 4 abwechselnd geht doch auch einfach:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if (Item.Index and 4) = 4 then
  ...
else
  ...
Find ich eleganter als mit 'ner globalen Boolean-Variable... und die würde sowieso Probleme machen, wenn dann mal jemand anfängt, nach oben zu scrollen. :)

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.