Autor Beitrag
Scotch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 101


Delphi 6 Prof
BeitragVerfasst: Do 28.12.06 15:14 
Hallo,

ich habe eine Stringliste in der Farbe entweder als clWhite oder als $000080ff drinnen stehen.
Wie kann ich daraus wieder eine Farbe machen um z.B ein Panel einzufärben?

Gruß Ingo
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 28.12.06 15:20 
Moin!

Stringlisten bieten sich nicht gerade dafür an, darin Farben abzulegen. Gibt es dafür einen bestimmten Grund? ;)

Besser wäre eine TList, dort kannst du in den Items die Farbe direkt ablegen.

Noch eine Alternative: In die .Objects[] der Stringliste beim Befüllen schon die Farbe zu dem .Strings[]-Eintrag dazu setzen, dann sparst du dir die Konvertierung String->TColor.

Aber zu der eigentlichen Frage: clWhite kannst du nicht anders "übersetzen", als mit einem Vergleichswert (eben "clWhite") zu vergleichen und dann passend den Farbwert zuzuweisen. Für "$000080ff" solltest du StrToInt() nehmen können, bzw. besser StrToIntDef('$000080ff',Integer(clWhite)), dann hast du auch gleich eine Default-Farbe drin. ;)

cu
Narses

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



BeitragVerfasst: Do 28.12.06 15:27 
Nimm doch einfach StringToColor :D
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 28.12.06 15:50 
Moin!

user profile iconChryzler hat folgendes geschrieben:
Nimm doch einfach StringToColor :D

Cool 8), kannte ich noch gar nicht... ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Scotch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 101


Delphi 6 Prof
BeitragVerfasst: Do 28.12.06 20:29 
Hallo, vielen Dank für die schnelle Hilfe.
@Narses
der Grund warum ich das brauche ist, so stehen die Farben + andere Werte in einer Ini Datei, die ich benutzen will.

@Chryzler
Super :flehan: , ab welcher Delphi Version gibt es diese Funktion?
Mein D7 kann es auf jedem Fall.

Gruß und ein guten Rutsch ins Neue Jahr 2007
Ingo
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Do 28.12.06 20:40 
Hmm, grad den Titel dieses Themas ohne Leerzeichen und schon haste die Funktion. :roll:

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Scotch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 101


Delphi 6 Prof
BeitragVerfasst: Do 28.12.06 20:58 
Jo manchmal ist die Lösung näher als man denkt *lol*

Gruß Ingo

Ps. In Delphi 6 gibt es das auch schon.
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: Fr 29.12.06 13:44 
Hallo,
user profile iconScotch hat folgendes geschrieben:
der Grund warum ich das brauche ist, so stehen die Farben + andere Werte in einer Ini Datei, die ich benutzen will...
TColor ist ein Integer, folglich kann man direkt als Integer in einer Ini speichern und wieder laden:
ausblenden Delphi-Quelltext
1:
Ini.WriteInteger('Memo', 'SchriftFarbe', Memo.Font.Color);					


user profile iconScotch hat folgendes geschrieben:
...ab welcher Delphi Version gibt es diese Funktion?
StringToColor/ColorToString gibt es schon ab Delphi 1

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Scotch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 101


Delphi 6 Prof
BeitragVerfasst: Fr 29.12.06 14:45 
Hallo Lannes,

Danke für den Tipp aber wenn die Ini so aufgebaut ist
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
[HTML]
Comment=clSilver,clNone,0,1,0,0
Escape Ampersand=clMaroon,clNone,0,0,0,0
Identifier=clTeal,clNone,0,0,0,0
Reserved Word=clBlue,clNone,0,0,0,0
Space=clNone,clNone,0,0,0,0
Symbol=clNavy,clNone,0,0,0,0
Text=clNone,clNone,0,0,0,0
Unknown Word=clRed,clNone,0,0,1,0
Value=clGreen,clNone,0,0,0,0

kann ich nur noch mit Strings arbeiten oder irre ich mich da?
Ich lade mir das Betreffende Value in eine Stringliste und
werte diese mit CommaText und StringToColor bzw. StrToBool aus.
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:
23:
24:
25:
26:
27:
28:
procedure TForm1.ListBox1Click(Sender: TObject);
var  i,index:integer;
     sections,sl:TStrings;
begin 
  index:= ListBox1.ItemIndex;
  sections:=TStringList.Create;
  sl :=  TStringList.Create;

  try
    ini:=TIniFile.create(ExtractFilePath(ParamStr(0))+'highlighter.ini');
    ini.ReadSection(ComboBox1.text,sections);
    ini.ReadSectionValues(ComboBox1.text,sections);
        try
          sl.CommaText:=sections.Values[sections.Names[index]];
          ColorBox1.Selected:=StringToColor(sl.Strings[0]);
          ColorBox2.Selected:=StringToColor(sl.Strings[1]);
          CheckBox2.Checked:= StrToBool(sl.Strings[2]);
          CheckBox2.Checked:= StrToBool(sl.Strings[3]);
          CheckBox3.Checked:= StrToBool(sl.Strings[4]);
          CheckBox4.Checked:= StrToBool(sl.Strings[5]);
        finally
          sl.Free;
  end;
  finally
    ini.Free;
    sections.Free;;
  end;
end;


gruß Ingo
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: Fr 29.12.06 19:02 
Hallo,

Erstellst Du die ini selbst?
dann kann man den Colorwert als Integer-String in die Ini schreiben
ausblenden Delphi-Quelltext
1:
xx := IntToStr(ColorBox1.Selected)+','+IntToStr(ColorBox2.Selected)+'....					


Lesen würde dann so aussehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
//...
ColorBox1.Selected:=StrToInt(sl.Strings[0]);  
ColorBox2.Selected:=StrToInt(sl.Strings[1]);  
//...


Wobei die Geschwindigkeitsunterschiede zu ColorToString/StringToColor, wenn man nicht gerade zigtausende Colorwerte schreibt, vernachlässigbar sind.

ColorToString ist etwa doppelt so schnell wie IntToStr aber
StrToInt ist dagegen 4x schneller als StringToColor.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )