Autor Beitrag
bl3nder
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Di 29.08.06 12:13 
Hoi
Ich habe eine mysql Datenbank , wo PCs, Monitore und Dockingstations gespeichert sind.
Ich benutze nur die mysql odbcs , kein zeos oder so.
Ich habe im private von TForm1
fmysql: Tmysqlclient und
Fresult: TmysqlResult
Bisher habe ich die Anzeige der wichtigsten Daten ueber folgende Prozeduren hinbekommen
Zuerst lasse ich mir einen entsprechenden sql befehl geben.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.mysqlqry ( q : string );
begin


if (q = '') then begin
  q := ' SELECT  r.inventar_Nr,r.netzwerkname,a.benutzer ,';
  q  := q + ' a.benutzer_alt, a.raum , r.bemerkungen ,m.inventar_Nr, d.inventar_Nr, r.statusID';
  q := q + ' from arbeitsplatz a inner join rechner r ';
  q := q + ' on a.rechnerid = r.rechnerid ';
  q := q + ' left join monitor m  ';
  q := q + ' on a.monitorid = m.monitorid ';
  q := q + ' left join dockingstation d ';
  q := q + ' on r.dockingstationid = d.dockingstationid ';
  q := q + ' WHERE "1=1" ';
  end;

FResult := FMysql.query(q, true, ex);
ShowInGrid;


end;

dann die Anzeige im StringGrid

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:
procedure TForm1.ShowInGrid;
var i,j: integer;


begin
if FMySql.Connected then begin

  if assigned(FResult) then begin   // <-- Falls eine SQL Abfrage vorliegt


          Grid.RowCount := FResult.RowsCount+1;  // <-- ZeilenAnzahl
          Grid.ColCount := FResult.FieldsCount; // <-- SpaltenAnzahl

          FResult.First;


          for i:=0 to FResult.RowsCount-1 do begin  // <-- Zeilen durchlaufen
              for j:=0 to FResult.FieldsCount-1 do  // <-- Spalten durchlaufen
                  Grid.Cells[j,i+1] := FResult.FieldValue(j);


              FResult.Next;
          Statusbar1.Panels[0].Text := IntToStr(Grid.RowCount) + ' Einträge';
          end;
  end
  else
    ShowMessage('Keine SQL-Abfrage !');

end
else
  ShowMessage('Not Connected');

end;


Nun moechte ich erreichen, dass er mir statt einer weiteren Spalte fuer "r.StatusID"-Werten die Zeilen abhaengig von der r.StatusID farblich markiert. Da ich aber zu FResult nichts gescheites gefunden habe, dachte ich mir ich frag mal, ob jemand weiß ich das am besten hinkrieg
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Di 29.08.06 12:50 
mein lösungsvorschlag für dich wäre:

1. ne dynamische stringlist erzeugen
2. für jede zeile, die du ins grid überträgst den Wert deiner ID in die Liste schreiben

Spalte1|Spalte2|Spalte3 Listenstatus
Zeile1 |Zeile1 |Zeile1 0
Zeile2 |Zeile2 |Zeile2 10
Zeile3 |Zeile3 |Zeile3 20
...

und dann bei onDrawGrid

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:
//Liste global 
var Liste: TStringList;

//erzeugen der List
Liste:= TStringList.create;
Liste.add(derStatus);

procedure Tmainform.datagridDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);

const c_entwicklung: TColor = $0009EDFF;
const c_fertig: TColor = $001A8CFF;
const c_neu: TColor = $00CA6500;

var i, i2: integer;
    status: integer;
begin
 with datagrid do
 begin
  status:= strtoint(Liste.strings[arow]);
  canvas.Font.Style:= [fsbold];
  case status of
    0: begin
        canvas.Brush.Color:= $00606060;
        canvas.font.Color:= clred;
       end;
   10: begin
        canvas.Brush.color:= c_entwicklung;
        canvas.Font.Color:= clblack;
       end;
   20: begin
        canvas.Brush.Color:= c_fertig;
        canvas.Font.Color:= clblack;
        end;
   30: begin
         canvas.Brush.color:= c_neu;
         canvas.Font.Color:= clwhite;
        end;
  end;
  Canvas.FillRect(Rect);
  Canvas.TextOut(Rect.Left+2, Rect.Top+2, Cells[ACol, ARow]);
 end;
 Liste.free;
end;


is aufsm Kopf der Code...denke er sollte passen =)

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
bl3nder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Di 29.08.06 14:26 
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:
//Liste global   
var Liste: TStringList;  

 
//erzeugen der List  
Liste:= TStringList.create;  
Liste.add(derStatus);  // <-- derStatus ist aus meiner mysql Datenbank r.StatusID ? 
                      // Wenn ja , kann ich das sicher nicht so reinschreiben oder ?

 
procedure Tmainform.datagridDrawCell(Sender: TObject; ACol,  
  ARow: Integer; Rect: TRect; State: TGridDrawState);  

 
const c_entwicklung: TColor = $0009EDFF;  
const c_fertig: TColor = $001A8CFF;  
const c_neu: TColor = $00CA6500;  

 
var i, i2: integer;  
    status: integer;  
begin  
 with datagrid do  
 begin  
  status:= strtoint(Liste.strings[arow]);  // <-- aehm woher der string ? check ich nicht :/
  canvas.Font.Style:= [fsbold];  
  case status of  
    0: begin  
        canvas.Brush.Color:= $00606060;  
        canvas.font.Color:= clred;  
       end;  
   10: begin  
        canvas.Brush.color:= c_entwicklung;  
        canvas.Font.Color:= clblack;  
       end;  
   20: begin  
        canvas.Brush.Color:= c_fertig;  
        canvas.Font.Color:= clblack;  
        end;  
   30: begin  
         canvas.Brush.color:= c_neu;  
         canvas.Font.Color:= clwhite;  
        end;  
  end;  
  Canvas.FillRect(Rect);  
  Canvas.TextOut(Rect.Left+2, Rect.Top+2, Cells[ACol, ARow]);  
 end;  
 Liste.free;  
end;
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Di 29.08.06 14:51 
hmm was fürn datentyp ist dein r.status?
wenns n string ist kannst du den einfach so in die liste kopieren
ausblenden Delphi-Quelltext
1:
liste.add(meinStatus);					


Bei nem Status is aber immer Integer zu empfehlen...

und der String den du meinst ist folgendes

ich bin bei deinem Status von einem Integer-Typ ausgegangen, drum ist meine Variable Status: integer;.

drum hab ich dann

ausblenden Delphi-Quelltext
1:
status:= strtoint(liste.strings[arow]);					


meinen in der Liste stehenden Status, der mit liste.add(meinStatus); hinzugefügt wurde in einen Integer umgewandelt, da man so einfach auf case status of prüfen kann.

Liste.strings[arow] macht nix anderes als dir den Status für deine aktuelle Zeile im Grid zu geben...

hoffe es war einigermaßen verständlich...

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
bl3nder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Di 29.08.06 15:01 
user profile iconZeitGeist87 hat folgendes geschrieben:
hmm was fürn datentyp ist dein r.status?
wenns n string ist kannst du den einfach so in die liste kopieren
ausblenden Delphi-Quelltext
1:
liste.add(meinStatus);					



der typ von r.statusID ist Integer, ist ja eine ID.
Aber ich kann doch nicht einfach liste.add(r.statusID) machen, weil r.statusID eine Spalte der mySQL Tabelle ist, keine Stringvariable . Das bloede ist halt, dass das alles im FResult steht und ich nicht weiß wie ich das da rauszieh um es dann mit solchen Sachen zu verknuepfen

Hab noch nen Screen mitgeschickt
Einloggen, um Attachments anzusehen!
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Di 29.08.06 15:14 
gut dann geh doch einfach die letzte spalte zeile für zeile durch und übertrag den wert mit liste.add(grid.cells[col,row]) in die liste und lösch anschließend die letze spalte =)

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Di 29.08.06 15:24 
hast du bei dem FResult eigentlich die möglichkeit explizit auf die Statusspalte zuzugreifen?

ich arbeite mit dbgrids da gehts so

ausblenden Delphi-Quelltext
1:
2:
3:
//x meine Spalte (haha)
//.asDatentyp zum Bleistift asInteger, asString oder asVariant
dbgrid1.fields[x].asDatentyp;


bei mir würde das dann so aussehen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
//das ganze DBgrid durchgehen
for i:= 1 to dbgrid1.datasource.dataset.recordcount do
begin
 //Daten aus DBgrid in StringGrid übertragen
 stringgrid1.cells[x,i]:= dbgrid1.fields[0].asstring;
 stringgrid1.cells[x,i]:= dbgrid1.fields[1].asstring;
 stringgrid1.cells[x,i]:= dbgrid1.fields[2].asstring;
 stringgrid1.cells[x,i]:= dbgrid1.fields[3].asstring;
 stringgrid1.cells[x,i]:= dbgrid1.fields[4].asstring;
 stringgrid1.cells[x,i]:= dbgrid1.fields[5].asstring;

 //Angenommen mein Status steht in der 6. Spalte
 //den füg ich nur in die Liste aber nicht ins StringGrid
 Liste.add(dbgrid1.fields[6].asstring);

 //Nächster Datensatz im DBgrid selektieren
 dbgrid1.datasource.dataset.moveby(1);
end;

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
bl3nder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mo 04.09.06 13:08 
Hallo
Hab das ganze jetz auf Zeos geaendert . Es funktioniert trotzdem noch nicht :

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:
procedure TForm1.ShowInGrid( s : String);
var
state: TGridDrawState;
begin

if SQLConnection.Connected then begin

  if (s = '') then begin
    s := ' SELECT  ';
    s := s + ' r.inventar_Nr ,a.benutzer,a.benutzer_alt, r.netzwerkname,a.raum ,';
    s := s + ' r.bemerkungen ,m.inventar_Nr, d.inventar_Nr, r.statusid';
    s := s + ' FROM arbeitsplatz a inner JOIN rechner r ';
    s := s + ' ON a.rechnerid = r.rechnerid ' ;
    s := s + ' LEFT JOIN monitor m      '  ;
    s := s + ' ON a.monitorid = m.monitorid   ';
    s := s + ' LEFT JOIN dockingstation d  ' ;
    s := s + ' ON r.dockingstationid = d.dockingstationid ';
    s := s + ' WHERE "1=1" ';
    end;

  SQLQuery.Close;
  SQLQuery.SQL.Text := s;
  SQLQuery.Open;

  Grid.RowCount := 2;  // <-- ZeilenAnzahl
  Grid.ColCount := 7; // <-- SpaltenAnzahl

  while not SQLQuery.Eof do begin
  Grid.RowCount := Grid.RowCount + 1;
  Grid.Cells[0,Grid.RowCount-2] := SQLQuery.FieldByName('Inventar_Nr').AsString;
  Grid.Cells[1,Grid.RowCount-2] := SQLQuery.FieldByName('NetzwerkName').AsString;
  Grid.Cells[2,Grid.RowCount-2] := SQLQuery.FieldByName('Benutzer').AsString;
  Grid.Cells[3,Grid.RowCount-2] := SQLQuery.FieldByName('Benutzer_alt').AsString;
  Grid.Cells[4,Grid.RowCount-2] := SQLQuery.FieldByName('Raum').AsString;
  Grid.Cells[5,Grid.RowCount-2] := SQLQuery.FieldByName('Bemerkungen').AsString;
  grid.cells[6,grid.RowCount-2] := SQLQuery.FieldByName('StatusID').AsString;


    GridDrawCell(self,0,grid.rowcount-2,grid.CellRect(0,grid.RowCount-2),state);
  SQLQuery.Next;

  end;
  Statusbar1.Panels[0].Text := IntToStr(Grid.RowCount) + ' Einträge';

  end

else
  ShowMessage('Not Connected');
end;

procedure TForm1.GridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
          State: TGridDrawState);

var markierung : TColor;
begin
// Zeile einfärben
markierung := clWindow;
case SQLQuery.FieldByName('StatusID').AsInteger of
  1: markierung := $00FBE2D9; // hell-blau      {Status: verwendet
  2: markierung := $0095FF95; // grün           {Status: IT-Pool
  3: markierung := $005B9DFF; // orange         {Status: ausgemustert
  4: markierung := $005B9DFF; // orange         {Status: verkauft
  5: markierung := $0095FF95; // grün           {Status: nicht verwendet
  6: markierung := $005A5AF5; // rot            {Status: ausgeschlachtet
  7: markierung := $000D0DD9; // dunkleres-rot  {Status: gestohlen
  end;
grid.Canvas.Brush.Color := markierung;
grid.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,grid.Cells[ACol,ARow]);
end;


Er malt in allen Zeilen den Hintergrund hellblau d.h. StatusID = 1 , aber nicht alle HABEN StatusID = 1 .
Wo is der Fehler ?
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mo 04.09.06 13:34 
probiers mal damit
hab Kommentar hingeschrieben was gefehlt hat (meiner Meinung nach, habs leider nicht nachgeprüft)

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:
procedure TForm1.ShowInGrid( s : String);
var
state: TGridDrawState;
begin

if SQLConnection.Connected then begin

  if (s = '') then begin
    s := ' SELECT  ';
    s := s + ' r.inventar_Nr ,a.benutzer,a.benutzer_alt, r.netzwerkname,a.raum ,';
    s := s + ' r.bemerkungen ,m.inventar_Nr, d.inventar_Nr, r.statusid';
    s := s + ' FROM arbeitsplatz a inner JOIN rechner r ';
    s := s + ' ON a.rechnerid = r.rechnerid ' ;
    s := s + ' LEFT JOIN monitor m      '  ;
    s := s + ' ON a.monitorid = m.monitorid   ';
    s := s + ' LEFT JOIN dockingstation d  ' ;
    s := s + ' ON r.dockingstationid = d.dockingstationid ';
    s := s + ' WHERE "1=1" ';
    end;

  SQLQuery.Close;
  SQLQuery.SQL.Text := s;
  SQLQuery.Open;

  Grid.RowCount := 2;  // <-- ZeilenAnzahl
  Grid.ColCount := 7; // <-- SpaltenAnzahl
  while not SQLQuery.Eof do begin
  Grid.RowCount := Grid.RowCount + 1;
  Grid.Cells[0,Grid.RowCount-2] := SQLQuery.FieldByName('Inventar_Nr').AsString;
  Grid.Cells[1,Grid.RowCount-2] := SQLQuery.FieldByName('NetzwerkName').AsString;
  Grid.Cells[2,Grid.RowCount-2] := SQLQuery.FieldByName('Benutzer').AsString;
  Grid.Cells[3,Grid.RowCount-2] := SQLQuery.FieldByName('Benutzer_alt').AsString;
  Grid.Cells[4,Grid.RowCount-2] := SQLQuery.FieldByName('Raum').AsString;
  Grid.Cells[5,Grid.RowCount-2] := SQLQuery.FieldByName('Bemerkungen').AsString;
  grid.cells[6,grid.RowCount-2] := SQLQuery.FieldByName('StatusID').AsString;


    GridDrawCell(self,0,grid.rowcount-2,grid.CellRect(0,grid.RowCount-2),state);
  SQLQuery.Next;

  end;
  Statusbar1.Panels[0].Text := IntToStr(Grid.RowCount) + ' Einträge';

  end

else
  ShowMessage('Not Connected');
end;

procedure TForm1.GridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
          State: TGridDrawState);

var markierung : TColor;
begin
// Zeile einfärben
markierung := clWindow;
case SQLQuery.FieldByName('StatusID').AsInteger of
  1: markierung := $00FBE2D9; // hell-blau      {Status: verwendet
  2: markierung := $0095FF95; // grün           {Status: IT-Pool
  3: markierung := $005B9DFF; // orange         {Status: ausgemustert
  4: markierung := $005B9DFF; // orange         {Status: verkauft
  5: markierung := $0095FF95; // grün           {Status: nicht verwendet
  6: markierung := $005A5AF5; // rot            {Status: ausgeschlachtet
  7: markierung := $000D0DD9; // dunkleres-rot  {Status: gestohlen
  end; 
grid.Canvas.Brush.Color := markierung; 
//hast du vergessen (so wird ja nix markiert)
grid.Canvas.FillRect(Rect);
grid.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,grid.Cells[ACol,ARow]);
end;


hoffe es geht

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
bl3nder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mo 04.09.06 14:09 
ne das hat leider auch nix gebracht.. :/
hab mal defaultdrawing deaktiviert und wieder aktiviert
daran lags auch nicht
bl3nder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mo 04.09.06 14:21 
hab mal den debugger hier angehalten..
komisch was er mir markierung sagt.. was soll das heissen ? "Wegen der Optimierung"
Einloggen, um Attachments anzusehen!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 04.09.06 14:38 
Hallo,

den Aufruf von DrawCell nimm mal aus deinem Code raus,
denn OnDrawCell wird automatisch ausgelöst, sobald eine Zelle neu gezeichnet werden muss; vorrausgesetzt das Ereignis OnDrawCell ist beim StringGrid im OI zugewiesen.
Das Neuzeichnen erfolgt wenn:
- gescrollt wird
- ein anderes Fenster das Grid verdeckt hatte
- wenn ein String in Cells[x,y] gesetzt wird
- wenn Objects[x,y] gesetzt wird

Also, mit dem Code:
ausblenden Delphi-Quelltext
1:
2:
3:
  Grid.Cells[2,Grid.RowCount-2] := SQLQuery.FieldByName('Benutzer').AsString;  
  Grid.Cells[3,Grid.RowCount-2] := SQLQuery.FieldByName('Benutzer_alt').AsString;  
  Grid.Cells[4,Grid.RowCount-2] := SQLQuery.FieldByName('Raum').AsString;

hast du z.B. 3-mal OnDrawCell ausgelöst.

Mit:
ausblenden Delphi-Quelltext
1:
grid.cells[6,grid.RowCount-2] := SQLQuery.FieldByName('StatusID').AsString;					
hast Du Die StatusID in Col 6 des StringGrids hinterlegt.
Wobei das IMHO besser in Objects aufgehoben ist(hat man Dir aber schon mal in der DP dort Link) empfohlen. :roll:

Aber bleiben wir mal dabei das Col 6 die StatusID enthält.
Darauf muss DrawCell reagieren, änder das mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
//case SQLQuery.FieldByName('StatusID').AsInteger of  
//  1: markierung := $00FBE2D9; // hell-blau      {Status: verwendet  
//  2: markierung := $0095FF95; // grün           {Status: IT-Pool  
case Grid.Cells[6,ARow][1] of//[1] weil case will Char
  '1' : markierung := $00FBE2D9; // hell-blau      {Status: verwendet  
  '2' : markierung := $0095FF95; // grün           {Status: IT-Pool 
  //...

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mo 04.09.06 14:57 
stimmt...lannes hat recht =)
völlig übersehen
denn du prüfst ja bei dem query immer auf die selbe zeile
also wenn in der ersten 1 ist dann ist egal was in der 2. oder 3. zeile ist...es wird immer mit Status "1" überschrieben..

so geht er alle daten im stringgrid durch und geht auf den status der schon drinsteht..

*hand an kopf klatsch*

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
bl3nder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mo 04.09.06 15:09 
Hallo Lannes
Erstmal Danke fuer die Antwort. Habe den Aufruf mal raus und meine onDrawCell geaendert.

Nun sagt er mir beim Compilieren

[Pascal Fehler] Search.pas(293): E2010 Inkompatible Typen: 'Char' und 'Integer'

bei der Zeile
ausblenden Delphi-Quelltext
1:
case Grid.Cells[6,ARow][1] of//[1] weil case will Char					


will der nicht doch Integer statt char ?
bl3nder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mo 04.09.06 15:14 
Ah habs.
Ich muss im case of Teil die Nummern auch "stringen" :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
// Zeile einfärben
markierung := clWindow;

//case SQLQuery.FieldByName('StatusID').AsInteger of
//  1: markierung := $00FBE2D9; // hell-blau      {Status: verwendet
//  2: markierung := $0095FF95; // grün           {Status: IT-Pool
case Grid.Cells[6,ARow][1] of//[1] weil case will Char


  '1': markierung := $00FBE2D9; // hell-blau      {Status: verwendet
  '2': markierung := $0095FF95; // grün           {Status: IT-Pool
  '3': markierung := $005B9DFF; // orange         {Status: ausgemustert
  '4': markierung := $005B9DFF; // orange         {Status: verkauft
  '5': markierung := $0095FF95; // grün           {Status: nicht verwendet
  '6': markierung := $005A5AF5; // rot            {Status: ausgeschlachtet
  '7': markierung := $000D0DD9; // dunkleres-rot  {Status: gestohlen
  end;


grid.Canvas.Brush.Color := markierung;
grid.Canvas.FillRect(Rect);
grid.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,grid.Cells[ACol,ARow]);


Vielen Dank jetzt gehts ! Supernette Hilfe hier :)
bl3nder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Di 05.09.06 07:41 
ist geklaert..
bl3nder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mi 06.09.06 08:30 
Tut mir Leid,dass ich nochmal nerven muss, aber ich habe bemerkt, dass es doch am Case of Teil liegt, wieso er mir irgendwelche Adresszugriffsverletzungen bringt...

Ich hab den Code nochmal umgeschrieben und die Variable markierung : TColor global gemacht. Zwar nicht schoen, aber so gehts vielleicht.

Nun hab ich wieder das Problem, dass er mir alles in der Farbe von case of FALL 1 anzeigt, obwohl ich doch die Variable Markierung jedes Mal wieder umstelle:

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:
procedure TForm1.ShowInGrid( s : String);
var Liste : TStringList;
begin
  Grid.ColWidths[0] := 110;
  Grid.ColWidths[1] := 110;
  Grid.ColWidths[2] := 160;
  Grid.ColWidths[3] := 160;
  Grid.ColWidths[4] := 80;
  Grid.ColWidths[5] := 200;
  Grid.ColWidths[6] := 110;
  Grid.ColWidths[7] := 110;


  if SQLConnection.Connected then begin

    if (s = '') then begin
      s := ' SELECT  ';
      s := s + ' r.inventar_Nr as Inventar_Nr, a.benutzer,a.benutzer_alt, r.netzwerkname,a.raum ,';
      s := s + ' r.bemerkungen ,m.inventar_Nr as MonitorInv_Nr, m.monitorid,d.dockingstationid,';
      s := s + ' a.monitor2id, d.inventar_Nr  as DockingstInv_Nr, r.statusid ';
      s := s + ' FROM test.arbeitsplatz a inner JOIN test.rechner r  ON a.rechnerid = r.rechnerid';
      s := s + ' LEFT JOIN test.monitor m   ON a.monitorid = m.monitorid LEFT JOIN test.dockingstation d';
      s := s + ' ON r.dockingstationid = d.dockingstationid  Order by r.Inventar_Nr ';
    end;

    SQLQuery.Close;
    SQLQuery.SQL.Text := s;
    SQLQuery.Open;

    Grid.RowCount := 2;  // <-- ZeilenAnzahl
    Grid.ColCount := 8; // <-- SpaltenAnzahl

    while not SQLQuery.Eof do begin
      case SQLQuery.FieldByName('StatusID').AsInteger of
        1: markierung := $00FBE2D9; // hell-blau      {Status: verwendet}
        2: markierung := $0095FF95; // grün           {Status: IT-Pool}
        3: markierung := $005B9DFF; // orange         {Status: ausgemustert}
        4: markierung := $005B9DFF; // orange         {Status: verkauft}
        5: markierung := $0095FF95; // grün           {Status: nicht verwendet}
        6: markierung := $005A5AF5; // rot            {Status: ausgeschlachtet}
        7: markierung := $000D0DD9; // dunkleres-rot  {Status: gestohlen}
      end;
      Grid.RowCount := Grid.RowCount + 1;
      Grid.Cells[0,Grid.RowCount-2] := SQLQuery.FieldByName('Inventar_Nr').AsString;
      Grid.Cells[1,Grid.RowCount-2] := SQLQuery.FieldByName('NetzwerkName').AsString;
      Grid.Cells[2,Grid.RowCount-2] := SQLQuery.FieldByName('Benutzer').AsString;
      Grid.Cells[3,Grid.RowCount-2] := SQLQuery.FieldByName('Benutzer_alt').AsString;
      Grid.Cells[4,Grid.RowCount-2] := SQLQuery.FieldByName('Raum').AsString;
      Grid.Cells[5,Grid.RowCount-2] := SQLQuery.FieldByName('Bemerkungen').AsString;
      Grid.Cells[6,grid.RowCount-2] := SQLQuery.FieldByName('MonitorInv_Nr').AsString;
      Grid.Cells[7,grid.RowCount-2] := SQLQuery.FieldByName('DockingstInv_Nr').AsString;

      SQLQuery.Next;

    end;


  Statusbar1.Panels[0].Text := IntToStr(Grid.RowCount) + ' Einträge';

  end

else
  ShowMessage('Not Connected');
end;





procedure TForm1.GridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
          State: TGridDrawState);

begin
// Zeile einfärben

  grid.Canvas.Brush.Color := markierung;
  grid.Canvas.FillRect(Rect);
  grid.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,grid.Cells[ACol,ARow]);

  if gdselected in state then
    with (Sender as TStringGrid).Canvas do begin
        Brush.Color := clWhite;
        Font.Color := clBlack;
        FillRect(Rect);
        TextOut(Rect.Left+2,Rect.Top+2,(Sender as TStringGrid).Cells[ACol,ARow]);
      end;


     end;


Wo ist da der Fehler ? Der Case Teil wird doch bei jeder Zeile neu durchgegangen und somit auch die Farbe veraendert
bl3nder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mi 06.09.06 14:19 
hmm ok schade , muss ich anderweitig schaun wie ichs hinbekomme ,trotzdem danke
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mi 06.09.06 14:45 
ist der letzte wert der StatusID identisch mit dem des ersten?
kann mir schon denken wo der Fehler liegt aber ich schaus mir jetzt mal in ruhe an..so wies dus jetzt gemacht hast wird markierung doch immer wieder überschrieben..und onDrawCell bekommt dann immer den letzten wert der in markierung gespeichert ist übergeben, das heißt du musst etwas bauen, wo jeder zeile im stringgrid der wert zugeordnet ist, z. B. so wie ichs oben schon mal gepostet hab, indem du dir einfach in einer StringList den Wert/markierung/StatusID zu jeder Zeile im StringGrid merkst und bei on DrawCell einfach den Case einbaust...

unverständlich?

Bei Fragen fragen =)

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
bl3nder Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mi 06.09.06 14:59 
Wenn ich es so mache, bekomme ich wieder ne komische Zugriffsverletzung ( liegt am case of teil )


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:
procedure TForm1.ShowInGrid( s : String);
begin
Liste.Create;
//..
Grid.RowCount := 2;  // <-- ZeilenAnzahl
    Grid.ColCount := 8; // <-- SpaltenAnzahl

    while not SQLQuery.Eof do begin

      Grid.RowCount := Grid.RowCount + 1;
      Grid.Cells[0,Grid.RowCount-2] := SQLQuery.FieldByName('Inventar_Nr').AsString;
      Grid.Cells[1,Grid.RowCount-2] := SQLQuery.FieldByName('NetzwerkName').AsString;
      Grid.Cells[2,Grid.RowCount-2] := SQLQuery.FieldByName('Benutzer').AsString;
      Grid.Cells[3,Grid.RowCount-2] := SQLQuery.FieldByName('Benutzer_alt').AsString;
      Grid.Cells[4,Grid.RowCount-2] := SQLQuery.FieldByName('Raum').AsString;
      Grid.Cells[5,Grid.RowCount-2] := SQLQuery.FieldByName('Bemerkungen').AsString;
      Grid.Cells[6,grid.RowCount-2] := SQLQuery.FieldByName('MonitorInv_Nr').AsString;
      Grid.Cells[7,grid.RowCount-2] := SQLQuery.FieldByName('DockingstInv_Nr').AsString;

      Liste.Add(SQLQuery.FieldByName('StatusID').AsString);

      SQLQuery.Next;
//..


procedure TForm1.GridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
          State: TGridDrawState);
var i : integer;
begin
//...
 //Farben der Zeilen abhaengig von der StatusID des Arbeitsplatzes
  for I := 0 to Liste.Count - 1 do begin

  case Liste[i][1] of
        '1': markierung := $00FBE2D9; // hell-blau      {Status: verwendet}
        '2': markierung := $0095FF95; // grün           {Status: IT-Pool}
        '3': markierung := $005B9DFF; // orange         {Status: ausgemustert}
        '4': markierung := $005B9DFF; // orange         {Status: verkauft}
        '5': markierung := $0095FF95; // grün           {Status: nicht verwendet}
        '6': markierung := $005A5AF5; // rot            {Status: ausgeschlachtet}
        '7': markierung := $000D0DD9; // dunkleres-rot  {Status: gestohlen}
      end;
  end;
  grid.Canvas.Brush.Color := markierung;
  grid.Canvas.FillRect(Rect);
  grid.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,grid.Cells[ACol,ARow]);
  end;
end;