Autor Beitrag
en!gma
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: So 01.05.05 11:24 
hi
also ich wollte bei meinem programm jetzt eine load function einbauen,
aber sobald ich die OpenDialogBox schliesse, schmiert das programm ab und er zeigt auf folgende zeile:

ausblenden Delphi-Quelltext
1:
canvas.TextOut(rect.Left+150,rect.top+1,color1[3]);					


also die zeile ist im listbox.ondraw...
und da liest er jedesmal werte aus, hier color[1]

weiss jemand wo der fehler liegt?
oder soll ich ein wenig code posten?

mfg

en!gma
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 01.05.05 11:26 
Wenn er auf diese Zeile zeigt, ist es meistens die Zeile davor wo der Fehler liegt :wink: . Und welche Fehlermeldung bekommst du?
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 01.05.05 11:26 
user profile iconen!gma hat folgendes geschrieben:
weiss jemand wo der fehler liegt? oder soll ich ein wenig code posten?


Mehr Code. Was ist Colors? Wird es beim Laden irgendwelcher Files uU überschrieben/neu gesetzt?

AXMD
en!gma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: So 01.05.05 11:30 
ok hier ist meine onDraw function

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:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
Var Rect2 : TRect;
    color1,color2: TStringDynArray;
    color1Temp,color2Temp: String;

  function GetRect(Dx,Dy: Integer): TRect;
  begin
    Result.Left := Rect.Left+Dx;
    Result.Top := Rect.Top+Dy;
    Result.Right := Result.Left+8;
    Result.Bottom := Result.Top+8;
  end;

    function GetRect2(Dx,Dy: Integer): TRect;
  begin
    Result.Left := Rect.Left+Dx;
    Result.Top := Rect.Top+Dy;
    Result.Right := Result.Left+10;
    Result.Bottom := Result.Top+10;
  end;

begin
  with control as TListBox do
    begin
      if odd(index) then canvas.Brush.Color := clwindowdark
                    else canvas.Brush.Color := clwindow;
      if odSelected in state then canvas.Brush.Color := clHighlight;
      canvas.FillRect(rect);
      Font.Size:=8;
      canvas.TextOut(rect.Left+5,rect.top+7,items[index]);
      IniFile := TIniFile.Create('.\temp.gas');
      //load colorA
color1Temp:=iniFile.ReadString(items[index],'ColorA','');
color1 := Split(color1Temp);
color2Temp:=iniFile.ReadString(items[index],'ColorB','');
color2 := Split(color1Temp);
if color2Temp='' then
   begin
    IniFile := TIniFile.Create('.\temp.gas');
     color1Temp:=iniFile.ReadString(items[index],'Color','');
     color1 := Split(color1Temp);
     color2Temp:=iniFile.ReadString(items[index],'Color','');
     color2 := Split(color2Temp);
     canvas.TextOut(rect.Left+150,rect.top+1,color1[3]);
     //black frame
     canvas.Brush.Color := $000000;
     Rect2 := GetRect2(139,3) ;
     canvas.FillRect(Rect2);
     canvas.Brush.Color := RGB(StrToInt(color1[0]),StrToInt(color1[1]),StrToInt(color1[2]));
     Rect2 := GetRect(140,4) ;
     canvas.FillRect(Rect2);
   end
else
  begin
      IniFile := TIniFile.Create('.\temp.gas');
      //load colorA
      color1Temp:=iniFile.ReadString(items[index],'ColorA','');     //
      color1 := Split(color1Temp);
      color2Temp:=iniFile.ReadString(items[index],'ColorB','');
      if color2Temp='' then color2Temp:=color1Temp;
      color2 := Split(color2Temp);
      //  iniFile.Free;
      canvas.TextOut(rect.Left+150,rect.top+1,color1[3]);
      canvas.TextOut(rect.Left+150,rect.top+15,color2[3]);
      //black frame
      canvas.Brush.Color := $000000;
      Rect2 := GetRect2(139,3) ;
      canvas.FillRect(Rect2);
      Rect2 := GetRect2(139,17) ;
      canvas.FillRect(Rect2);
      canvas.Brush.Color := RGB(StrToInt(color1[0]),StrToInt(color1[1]),StrToInt(color1[2]));
      Rect2 := GetRect(140,4) ;
      canvas.FillRect(Rect2);
      canvas.Brush.Color := RGB(StrToInt(color2[0]),StrToInt(color2[1]),StrToInt(color2[2]));
      Rect2 := GetRect(140,18) ;
      canvas.FillRect(Rect2);
 end;
end;
end;


naja und hier ist ein pic wie es bis jetzt aussieht.
also es werden insgesamt 4 kästchen gezeichnet und die farben für 2 dieser kästchen werden aus einer ini datei ausgelesen:

www.phoenix-designz....ditor/matEditor5.JPG
en!gma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: So 01.05.05 11:57 
kann ich villeicht das programm solange anhalten, bis die dialogBox geschlossen wurde??
ich denke er versucht zu zeichnen, obwohl die dialog box offen ist
en!gma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: So 01.05.05 12:11 
also wenn ich Listbox1.Visible:=False vorher setze, kommt der fehler nicht,
wenn ich aber nach dem laden es wieder auf true setze, kommt der fehler sofort..
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 01.05.05 12:17 
Kannst du mal dein Programm als Anhang hier reinstellen? Es lässt sich dann wesentlich leichter nach Fehlern suchen, als wenn man nur den Quelltext vor sich hat, ohne es selber auszuprobieren.
en!gma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: So 01.05.05 12:22 
hmm ich seh grad, nachdem ich versuche, eine datei zu laden,
findet er die ini datei nicht mehr.
TIniFile.Create('.\temp.gas');
deswegen sind die werte leer und er versucht ein rechteck zu zeichnen, obwohl keine farben angegeben sind.
en!gma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: So 01.05.05 12:27 
ok hab das problem gelöst thx
Muetze1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 346



BeitragVerfasst: So 01.05.05 14:26 
Moin!

Noch 2 Tipps zu deinem Code:

1. Für die Rechteck arbeiten schau dir mal die Funktionen OffsetRect() und InflateRect() an aus der WinAPI - die vereinfachen das zum Teil.
2. Versuche die Farben im Speicher zu halten, da der INI Zugriff - der ja für jede Zeile immer wieder neu ausgeführt wird - recht langsam ist.

MfG
Muetze1