![]() |
AW: Inifile Problem
Zitat:
Zum Problem, guck dir mal den Part an:
Delphi-Quellcode:
Du füllst in 2 Schleifen jeweils "helpd[l]:=". Damit überschreibst du beim 2x das, was du beim 1x reingeschrieben hast, ist das gewollt?
ini.ReadSectionValues('BMI', sl);
for l := 0 to sl.Count-1 do helpd[l] := StrToDate(sl.Names[l]); for l := 0 to sl.Count-1 do helpb[l] := Integer(sl.Objects[l]); Davon ab scheint mir das "helpb[l] := Integer(sl.Objects[l]);" auch falsch, denn was soll in den Objekten drin sein, eigentlich doch nix, daher vllt. die 0 überall drin. Du meintest wahrsch. sowas: helpb[l] := Integer(sl.values[helpb[l]]); |
AW: Inifile Problem
Zitat:
Zitat:
"helpd[l]:=" "helpb[l]:=" |
AW: Inifile Problem
Ich kann mir kaum vorstellen, dass in
Delphi-Quellcode:
irgendwas Sinnvolles drinsteht. Kann es sein, dass du
sl.Objects
Delphi-Quellcode:
suchst?
sl.Values
Und noch eine Sache:
Delphi-Quellcode:
liefert den Pfad inkl. abschließendem Pfadtrenner (bei Windows Backslash), d.h. du brauchst beim Zusammenbauen deines Dateinamens keinen Backslash einzufügen. Sinnvoller wäre die Verwendung der Funktion
ExtractFilePath
Delphi-Quellcode:
(bzw. IncludeTrailingBackslash bei Delphi 5 und älter).
IncludeTrailingPathDelimiter
MfG Dalai |
AW: Inifile Problem
Warum gibt GetApplicationDirectory den Path und nicht das Directory zurück?
Dir = ohne abschließendes \ Path = mit Und für aktuellere Delphis: ![]() |
AW: Inifile Problem
Zitat:
Davon ab steht aber der Rest meines Posts noch, dass wahrscheinlich sl.Values statt sl.Objects verwendet werden sollte. |
AW: Inifile Problem
Zitat:
Also ich sehe kein: p :-D:lol::spin2::coder2: |
AW: Inifile Problem
Zitat:
|
AW: Inifile Problem
p b d
ist doch egal, Hauptsache lesbar! Gruß K-H |
AW: Inifile Problem
Hallo Leute,
Erstmal ein großes Danke an alle die sich mit meinem Problem beschäftigen und versuchen mir zu helfen! Ich hab mir eure Antworten angekuckt und Vorschläge ausprobiert(Backslash bleibt vorerst, da ich wie schon gesagt erstmal erreichen will, dass es funktioniert). Folgendes kam dabei raus:
Delphi-Quellcode:
So nachdem ich nun test in einem Editfeld ausgebe bleibt dieses jedoch leer, verändert sich jedoch(Defaulttext:'Edit1'; nach Ausführung des Befehls:''; )
unit ULoad2;
interface uses SysUtils,StdCtrls, ExtCtrls,FileCtrl, Classes, Graphics, Controls, Forms,IniFiles, Dialogs; type tladenbmi= array[1..365] of String; tladendate= array[1..365] of TDate; function GetApplicationDirectory: string; procedure loadfileb(n:string); var helpbmi:tladenbmi; helpdate:tladendate; test: string; implementation function GetApplicationDirectory: string; begin GetApplicationDirectory := ExtractFilePath(ParamStr(0)); end; procedure loadfileb(n:string); var Ini: TIniFile; dir:string; sl : TStringList; l:integer; begin dir:=GetApplicationDirectory+n; sl:=TStringlist.Create; Ini:=TIniFile.Create(dir+'\'+n+'.ini'); //Datei in Stringliste laden try ini.ReadSectionValues('BMI', sl); for l := 0 to sl.Count-1 do begin helpdate[l]:=StrToDate(sl.Names[l]); helpbmi[l]:=sl.Values[DateToStr(helpdate[l])]; end; test:= helpbmi[1]; finally Ini.Free; sl.Free; end; end; end. Ich weiß schonwieder echt nicht weiter. Ist mir echt peinlich, wie blöd ich mich anstell... PS: Sorry das ich so unregelmäßig antworte, hab zur Zeit nicht viel Zeit. |
AW: Inifile Problem
Ich habe die Unit jetzt mal ein wenig umgeschrieben, auch wenn die Struktur der Daten immer noch nicht optimal ist ... aber das ist ja auch ein anderes Thema.
Delphi-Quellcode:
unit ULoad2;
interface uses SysUtils, Classes, IniFiles; type // ## INFO ## // // Zusammengehörende Informationen fassen wir auch zusammen // tladen = array [1 .. 365] of Integer; // tladend = array [1 .. 365] of TDate; TTagesWert = record Datum: TDate; Wert: Integer; end; TJahresWerte = array of TTagesWert; // ## INFO ## // // Statt irgendwelcher Magic Values, die überall im Code auftauchen // benutzen wir Konstanten const PATH_SEPARATOR = '\'; DATA_DIRECTORY_NAME = 'Data'; BMIFILE_EXTENSION = '.ini'; BMIFILE_BMI_SECTIONNAME = 'BMI'; function GetApplicationDirectory: string; // ## INFO ## // // DRY - **D**on't **R**epeat **Y**ourself // // Niemals an irgendwelchen Stellen den gleichen Code mit der gleichen Bedeutung // doppelt schreiben. Diese Teile werden ausgelagert und bekommen sprechende // Namen. function GetDataDirectory: string; function GetDataFileName( const AName: string ): string; // procedure loadfileb( n: string ); function LoadBmiFileData( const AName: string ): TJahresWerte; procedure SaveBmiFileData( const AName: string; AData: TJahresWerte ); // ## INFO ## // // Globale Variablen müssen nicht sein und sind mehr BÖSE als nützlich // var // helpb: tladen; // helpd: tladend; // j: Integer; implementation function GetApplicationDirectory: string; begin // ## INFO ## // // Wenn wir das Verzeichnis möchten, dann müssen wir uns auch das Verzeichnis // holen und nicht den Pfad // GetApplicationDirectory := ExtractFilePath( ParamStr( 0 ) ); GetApplicationDirectory := ExtractFileDir( ParamStr( 0 ) ); end; function GetDataDirectory: string; begin GetDataDirectory := GetApplicationDirectory + PATH_SEPARATOR + DATA_DIRECTORY_NAME; end; function GetDataFileName( const AName: string ): string; begin GetDataFileName := GetDataDirectory + PATH_SEPARATOR + AName + BMIFILE_EXTENSION; end; // procedure loadfileb( n: string ); // var // Ini: TIniFile; // dir: string; // sl: TStringList; // l: Integer; // begin // dir := GetApplicationDirectory + n; // sl := TStringList.Create; // Ini := TIniFile.Create( dir + '\' + n + '.ini' ); // Datei in Stringliste laden // try // Ini.ReadSectionValues( 'BMI', sl ); // for l := 0 to sl.Count - 1 do // helpd[l] := StrToDate( sl.Names[l] ); // for l := 0 to sl.Count - 1 do // helpb[l] := Integer( sl.Objects[l] ); // j := Length( helpb ); // finally // Ini.Free; // sl.Free; // end; // end; function LoadBmiFileData( const AName: string ): TJahresWerte; var LBmiFileName: string; LBmiFile: TIniFile; LSectionNames: TStringList; LIdx: Integer; begin LSectionNames := nil; LBmiFile := nil; try LBmiFileName := GetDataFileName( AName ); LBmiFile := TIniFile.Create( LBmiFileName ); LBmiFile.ReadSection( {Section} BMIFILE_BMI_SECTIONNAME, {Strings} LSectionNames ); SetLength( Result, LSectionNames.Count ); for LIdx := 0 to LSectionNames.Count - 1 do begin Result[LIdx].Datum := StrToDate( LSectionNames[LIdx] ); Result[LIdx].Wert := LBmiFile.ReadInteger( {Section} BMIFILE_BMI_SECTIONNAME, {Ident} LSectionNames[LIdx], {Default} 0 ); end; finally LSectionNames.Free; LBmiFile.Free; end; end; procedure SaveBmiFileData( const AName: string; AData: TJahresWerte ); var LBmiFileName: string; LBmiFile: TIniFile; LIdx: Integer; begin LBmiFile := nil; try LBmiFileName := GetDataFileName( AName ); LBmiFile := TIniFile.Create( LBmiFileName ); LBmiFile.EraseSection( BMIFILE_BMI_SECTIONNAME ); for LIdx := Low( AData ) to High( AData ) do begin LBmiFile.WriteInteger( {Section} BMIFILE_BMI_SECTIONNAME, {Ident} DateToStr( AData[LIdx].Datum ), {Value} AData[LIdx].Wert ); end; finally LBmiFile.Free; end; end; end. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:09 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz