| Autor |
Beitrag |
Ironhead
      
Beiträge: 57
Win XP,Kanotix 5
|
Verfasst: Mi 31.05.06 20:43
Hallo zusammen,
ich wollte in mein Programm die Hintergrundfarbe abspeichern lassen, das klappt auch soweit, habe nur ein Problem mit dem auslesen der Information.
Speichern:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
| procedure TForm5.Button2Click(Sender: TObject); var ini: TIniFile; begin showMessage ('Datei Gespeichert'); ini := TIniFile.Create(IncludeTrailingPathDelimiter(GetCurrentDir)+'einstellungen.ini');
ini.WriteInteger('Hintergrundfarbe','Name',(Form1.Color));
end;
end. |
Laden:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| procedure TForm3.FormCreate(Sender: TObject); var ini: TIniFile; begin try ini := TIniFile.Create(IncludeTrailingPathDelimiter(GetCurrentDir)+'einstellungen.ini');
Form1.Color := Ini.ReadInteger('Hintergrundfarbe', 'Name', '');
finally ini.Free; end; |
Beim Compilieren, haut er raus Inkompatible Typen
Kann mir vielleicht einer sagen wie ich das hinbekomme, Danke schon mal
|
|
Arno Nym
      
Beiträge: 131
|
Verfasst: Mi 31.05.06 21:15
Hi!
Farben sind nunmal keine "normalen" Integer-werte.
Benutze am besten die ColortoString, StringtoColor funktionen und schreibe es mit "writestring" in die INI-Datei.
MFG, Arno Nym
|
|
DarkLord05
      
Beiträge: 449
WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
|
Verfasst: Mi 31.05.06 21:16
|
|
Ironhead 
      
Beiträge: 57
Win XP,Kanotix 5
|
Verfasst: Mi 31.05.06 21:59
Ja gut das hat mich ein stück weiter gebracht, speichern geht also,
habe jetzt diesen code zum Speichern
Delphi-Quelltext 1:
| writestring('Hintergrundfarbe', 'Color', ColorToString(Form1.Color)); |
und fürs Lesen
Delphi-Quelltext 1:
| Form1.Color := StringToColor(ini.Readstring('Hintergrundfarbe','Color','' )); |
er Comeliert das Programm auch, aber bei Starten kommt eine Meldung "ist kein Gültiger Integerwert
waran könnte das nun liegen?
|
|
Arno Nym
      
Beiträge: 131
|
Verfasst: Mi 31.05.06 22:11
Hi!
das ist merkwürdig, das die Fehlermeldung da kommt, hast du mal Break-Points gesetzt, vielleicht liegts an etwas anderem das am Anfang abläuft, wenn ja, musst du mal den ganzen unit-code posten.
MFG, Arno Nym
|
|
fidionael
      
Beiträge: 232
Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
|
Verfasst: Mi 31.05.06 22:22
Öhm, gucken wir uns kurz mal an was eine Farbe ist...
Delphi-Quelltext 1:
| type TColor = -$7FFFFFFF-1..$7FFFFFFF; |
Also nichts anderes als ein Integer. Insofern kann man auch WriteInteger und ReadInteger benutzen. Nun gucken wir uns an, was die Funktion ReadInteger tut:
Delphi-Quelltext 1: 2: 3: 4: 5:
| TIniFile.ReadInteger(const Section: String; const Ident: String; Default: Integer ) : Integer; |
Nun müssen wir uns nur überlegen, welche Farbe wir als Default nehmen wollen. Schwarz wäre z. B. 0.
Mfg
//Edit: Wenn du unbedingt bei Strings bleiben willst, versuchs doch als Default-Wert anstatt mit '' mal mit 'clBlack' 
Zuletzt bearbeitet von fidionael am Mi 31.05.06 22:25, insgesamt 1-mal bearbeitet
|
|
Ironhead 
      
Beiträge: 57
Win XP,Kanotix 5
|
Verfasst: Mi 31.05.06 22:23
Tut mir leid das ich schon wieder Fragen muss, aber was meinst du mit Break Points setzen?
Wenn ich dir die units hier posten soll muss ich sagen, die beiden Prozeduren sitzen auf zwei verschidenen units und die sind nich gerade nur 20 zeilen lang.
Die Zeile zum Speichern iss ab 161(nur um dir die suche zu erleichtern)
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: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179:
| unit Einstellungen;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,inifiles;
type TForm5 = class(TForm) Label1: TLabel; Label2: TLabel; Button1: TButton; Label4: TLabel; Button2: TButton; Button3: TButton; ColorDialog1: TColorDialog; Label9: TLabel; Button4: TButton; Button5: TButton; Button6: TButton; Label3: TLabel; procedure Button2Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject); private public end;
var Form5: TForm5;
implementation
uses Willkommen, Hauptformular, Profil, Notenliste, ABOUT;
{$R *.dfm}
procedure TForm5.Button1Click(Sender: TObject); begin Form3.Close; Form2.Close; Form1.Close; Form4.Close; Form5.Close; end;
procedure TForm5.Button3Click(Sender: TObject); begin Form5.Hide; Form2.Show; end;
procedure TForm5.Button4Click(Sender: TObject); begin if ColorDialog1.Execute then Form1.Color :=ColorDialog1.Color; Form2.Color := ColorDialog1.Color; Form3.Color := ColorDialog1.Color; Form4.Color := ColorDialog1.Color; Form5.Color := ColorDialog1.Color; end; procedure TForm5.Button5Click(Sender: TObject); begin if ColorDialog1.Execute then Form1.Edit1.Color :=ColorDialog1.Color; Form1.Edit2.Color := ColorDialog1.Color; Form1.Edit3.Color := ColorDialog1.Color; Form1.Edit4.Color := ColorDialog1.Color; Form1.Edit5.Color := ColorDialog1.Color; Form1.Edit6.Color := ColorDialog1.Color; Form1.Edit7.Color := ColorDialog1.Color; Form1.Edit8.Color := ColorDialog1.Color; Form1.Edit9.Color := ColorDialog1.Color; Form1.Edit10.Color := ColorDialog1.Color; Form1.Edit11.Color := ColorDialog1.Color; Form1.Edit12.Color := ColorDialog1.Color; Form1.Edit13.Color := ColorDialog1.Color; Form1.ComboBox1.Color := ColorDialog1.Color; Form1.ComboBox2.Color := ColorDialog1.Color; Form1.ComboBox3.Color := ColorDialog1.Color; Form1.ComboBox4.Color := ColorDialog1.Color; Form2.Edit1.Color :=ColorDialog1.Color; Form2.Edit2.Color :=ColorDialog1.Color; Form2.ComboBox1.Color :=ColorDialog1.Color; Form4.Listbox1.Color :=ColorDialog1.Color; Form4.Listbox2.Color :=ColorDialog1.Color; Form4.Listbox3.Color :=ColorDialog1.Color; Form4.Listbox4.Color :=ColorDialog1.Color;
end;
procedure TForm5.Button6Click(Sender: TObject); begin if ColorDialog1.Execute then Form3.Label1.Font.Color :=ColorDialog1.Color; Form3.Label2.Font.Color :=ColorDialog1.Color; Form3.Label3.Font.Color :=ColorDialog1.Color; Form3.Label4.Font.Color :=ColorDialog1.Color; Form3.Label12.Font.Color :=ColorDialog1.Color; Form3.Label13.Font.Color :=ColorDialog1.Color; Form3.Label5.Font.Color :=ColorDialog1.Color; Form3.Label7.Font.Color :=ColorDialog1.Color; Form3.Label8.Font.Color :=ColorDialog1.Color; Form3.Label10.Font.Color :=ColorDialog1.Color; Form3.Label14.Font.Color :=ColorDialog1.Color; Form1.Label1.Font.Color :=ColorDialog1.Color; Form1.Label2.Font.Color :=ColorDialog1.Color; Form1.Label3.Font.Color :=ColorDialog1.Color; Form1.Label4.Font.Color :=ColorDialog1.Color; Form1.Label5.Font.Color :=ColorDialog1.Color; Form1.Label13.Font.Color :=ColorDialog1.Color; Form1.Label14.Font.Color :=ColorDialog1.Color; Form1.Label6.Font.Color :=ColorDialog1.Color; Form1.Label7.Font.Color :=ColorDialog1.Color; Form1.Label8.Font.Color :=ColorDialog1.Color; Form1.Label9.Font.Color :=ColorDialog1.Color; Form1.Label10.Font.Color :=ColorDialog1.Color; Form1.Label11.Font.Color :=ColorDialog1.Color; Form1.Label12.Font.Color :=ColorDialog1.Color; Form1.Label17.Font.Color :=ColorDialog1.Color; Form1.Label20.Font.Color :=ColorDialog1.Color; Form2.Label3.Font.Color :=ColorDialog1.Color; Form2.Label4.Font.Color :=ColorDialog1.Color; Form2.Label1.Font.Color :=ColorDialog1.Color; Form2.Label2.Font.Color :=ColorDialog1.Color; Form2.Label21.Font.Color :=ColorDialog1.Color; Form2.Label33.Font.Color :=ColorDialog1.Color; Form2.Label28.Font.Color :=ColorDialog1.Color; Form2.Label29.Font.Color :=ColorDialog1.Color; Form2.Label30.Font.Color :=ColorDialog1.Color; Form2.Label31.Font.Color :=ColorDialog1.Color; Form2.Label32.Font.Color :=ColorDialog1.Color; Form2.Label5.Font.Color :=ColorDialog1.Color; Form2.Label6.Font.Color :=ColorDialog1.Color; Form2.Label7.Font.Color :=ColorDialog1.Color; Form4.Label1.Font.Color :=ColorDialog1.Color; Form4.Label2.Font.Color :=ColorDialog1.Color; Form4.Label3.Font.Color :=ColorDialog1.Color; Form4.Label4.Font.Color :=ColorDialog1.Color; Form4.Label5.Font.Color :=ColorDialog1.Color; Form4.Label6.Font.Color :=ColorDialog1.Color; Form4.Label7.Font.Color :=ColorDialog1.Color; Form4.Label8.Font.Color :=ColorDialog1.Color; Form5.Label1.Font.Color :=ColorDialog1.Color; Form5.Label2.Font.Color :=ColorDialog1.Color; Form5.Label3.Font.Color :=ColorDialog1.Color; Form5.Label4.Font.Color :=ColorDialog1.Color; Form5.Label9.Font.Color :=ColorDialog1.Color; end; procedure TForm5.Button2Click(Sender: TObject); var ini: TIniFile;
begin
showMessage ('Datei Gespeichert'); ini := TIniFile.Create(IncludeTrailingPathDelimiter(GetCurrentDir)+'einstellungen.ini'); with ini do begin try writestring('Hintergrundfarbe', 'Color', ColorToString(Form1.Color)); finally free; end; end; end;
end. |
Die Zeile zum Laden iss ab 70(nur um dir die suche zu erleichtern)
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:
| unit Willkommen;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Menus, iniFiles;
type TForm3 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Label9: TLabel; Label10: TLabel; Label11: TLabel; Label12: TLabel; Label13: TLabel; Label14: TLabel; Button1: TButton; Button2: TButton; Button3: TButton; procedure FormCreate(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private public end;
var Form3: TForm3;
implementation
uses Profil, Hauptformular, Notenliste, Einstellungen, ABOUT;
{$R *.dfm}
procedure TForm3.Button2Click(Sender: TObject); begin Form3.Close; Form2.Close; Form1.Close; Form4.Close; Form5.Close; end;
procedure TForm3.Button1Click(Sender: TObject); begin Form1.Show; Form3.Hide;
end;
procedure TForm3.Button3Click(Sender: TObject); begin Info.Show; end;
procedure TForm3.FormCreate(Sender: TObject); var ini: TIniFile; begin ini := TIniFile.Create(IncludeTrailingPathDelimiter(GetCurrentDir)+'einstellungen.ini'); with ini do begin try Form1.Color := StringToColor(ini.Readstring('Hintergrundfarbe','Color','' )); finally free; end; end; end;
end. |
Vielleicht haste irgend eine Ahnung wo der Wurm drin iss.
Da du nicht zu meinem Code gesagt hast, darf ich annehmen das der richtig iss?
Vielen Dank für deinen Geduld.
|
|
Ironhead 
      
Beiträge: 57
Win XP,Kanotix 5
|
Verfasst: Mi 31.05.06 22:44
Ich habs rausbekommen, er meint die beiden '' am ende, aber warum?
Delphi-Quelltext 1:
| Form1.Color := StringToColor(ini.Readstring('Hintergrundfarbe','Color','')); |
tu ich sie weg dann zählt er es als Fehler.
|
|
Blackheart666
      
Beiträge: 2195
XP
D3Prof, D6Pers.
|
Verfasst: Mi 31.05.06 23:16
|
|
Ironhead 
      
Beiträge: 57
Win XP,Kanotix 5
|
Verfasst: Mi 31.05.06 23:25
Ja, mit dem Teil Meckert er auch rum, ZUGRIFFSVERLETZUNG
|
|
Lannes
      
Beiträge: 2352
Erhaltene Danke: 4
Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
|
Verfasst: Mi 31.05.06 23:27
Hallo,
GetCurrentDir liefert das aktuelle Verzeichnis.
Das aktuelle Verzeichnis ist nicht immer gleich dem Anwendungsverzeichnis.
Lass Dir mal vor dem Laden und speichern das Verzeichnis mit Showmessage(GetCurrentDir);ausgeben.
ExtractFilePath(ParamStr(0)) liefert Dir das Anwendungsverzeichnis.
_________________ MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
|
|
fidionael
      
Beiträge: 232
Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
|
Verfasst: Mi 31.05.06 23:59
Ironhead hat folgendes geschrieben: | | Ja, mit dem Teil Meckert er auch rum, ZUGRIFFSVERLETZUNG |
Also an der 0 liegt's nicht. Habs grade getestet
Delphi-Quelltext 1: 2: 3: 4:
| procedure TForm1.FormPaint(Sender: TObject); begin Form1.Color:=0; end; |
Die Prozedur färbt den Hintergrund des Formulares völlig einwandfrei und ohne Zugriffsverletzung Schwarz. Außerdem finde ich es ein wenig erschreckend, dass in diesem Thread soviele Leute mit so beschränkter Ahnung versuchen zu helfen
Tut mir Leid das so zu sagen, aber z. B. Color zuerst in einen String umwandeln um es dann wieder in einen Integer zurück zu konvertieren, wenn man es von Anfang an in einem Integer speichern kann?
Mfg
|
|
0xCC
      
Beiträge: 150
|
Verfasst: Do 01.06.06 02:14
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:
| uses inifile; const cinifile = 'C:\farbtest.ini';
procedure TForm1.Button1Click(Sender: TObject); var c : tcolor; begin with tinifile.Create(cinifile) do try c := ReadInteger('farben', 'background', clWhite); self.Color := c; finally free; end; end;
procedure TForm1.Button2Click(Sender: TObject); begin if fileexists(cinifile) then deletefile(cinifile); with tinifile.Create(cinifile) do try WriteInteger('farben', 'background', integer($DEADBEEF)); finally free; end; end; |
funktioniert bestens, ich würde mal lannes ratschlag befolgen.
|
|
Ironhead 
      
Beiträge: 57
Win XP,Kanotix 5
|
Verfasst: Fr 02.06.06 00:35
So Leute nach langem überlegen, Fummeln, Basteln, hin und her schauen, und viele viele viele Zigaretten später hab ichs doch endlich geschaft.
zum Speichern:
Delphi-Quelltext 1:
| Ini.WriteInteger('Application', 'Color', Form3.Color); |
zum Laden:
Delphi-Quelltext 1:
| Form3.Color := Ini.ReadInteger('Application', 'Color', clBtnFace); |
Ich Danke allen für Ihre Anregungen und Beispiele.
Bis zum nächsten mal 
|
|
|