Einzelnen Beitrag anzeigen

S4SH1981

Registriert seit: 13. Jul 2007
59 Beiträge
 
#1

Ini Datei Problem

  Alt 10. Mär 2012, 20:43
Hallo zusammen,

habe folgendes Problem.
Im folgendem Code Speicher ich aus einer Listbox per Drag'n Drop Einträge und sortiere diese nach Tagen.
Das funktioniert soweit wunderbar.
Die Ini Datei sieht wie folgt aus.

Dateiname ist 2012-10-1.kw
[Montag]
Kunde=Edit1 Edit2.kd
Edit1 Edit22.kd
abc def.kd

Die gespeicherte KW ist nun KW 10. Ich möchte jetzt die Daten aus der Ini Datei für KW 10 auslesen und in den Listboxen anzeigen. Leider funktioniert das mal rein garnicht.
Ich bekomme es nur hin, dass ich entweder das Montag, oder den ersten Eintrag mit Kunde=Edit1. Edit2.kd in die Listbox auslesen lassen kann. Nie bekomme ich aber den gesamten Text unter der Sektion Montag in die Listbox geschrieben.

Es ist sicherlich ein einfaches Problem. Ich komme allerdings nicht drauf.
Wäre schön, wenn mir dazu je,and einen Lösungsansatz geben könnte.

Schonmal Danke

Anbei der Code:
Delphi-Quellcode:
unit KalMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls, Spin, Grids, ExtCtrls, SRCal, Buttons, Inifiles;

type
  TMainForm = class(TForm)
    Label2: TLabel;
    Label3: TLabel;
    LblDatum: TLabel;
    LblFeiertag: TLabel;
    LblSternzeichen: TLabel;
    LblTagImJahr: TLabel;
    LblWocheImJahr: TLabel;
    LblMonat: TLabel;
    LblJahr: TLabel;
    SpinMonat: TSpinButton;
    SpinJahr: TSpinButton;
    Label5: TLabel;
    Kalender: TSRCalendar;
    LblSeason: TLabel;
    ListBox1: TListBox;
    Label1: TLabel;
    Label4: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    ListBox2: TListBox;
    ListBox3: TListBox;
    ListBox4: TListBox;
    ListBox5: TListBox;
    ListBox6: TListBox;
    ListBox7: TListBox;
    ListBox8: TListBox;
    ListBox9: TListBox;
    ListBox10: TListBox;
    ListBox11: TListBox;
    ListBox12: TListBox;
    ListBox13: TListBox;
    ListBox14: TListBox;
    ListBox15: TListBox;
    ListBox16: TListBox;
    ListBox17: TListBox;
    ListBox18: TListBox;
    ListBox19: TListBox;
    ListBox20: TListBox;
    ListBox21: TListBox;
    ListBox22: TListBox;
    Button1: TButton;
    Button2: TButton;
    procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure KalenderChange(Sender: TObject);
    procedure SpinMonatDownClick(Sender: TObject);
    procedure SpinMonatUpClick(Sender: TObject);
    procedure SpinJahrDownClick(Sender: TObject);
    procedure SpinJahrUpClick(Sender: TObject);
    procedure KalenderDblClick(Sender: TObject);
    procedure KalenderMonthChange(Sender: TObject);
    procedure KalenderYearChange(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  MainForm: TMainForm;
  ini: Tinifile;

implementation

{$R *.DFM}

procedure ListFileDir(Path: string; FileList: TStrings);
var
  SR: TSearchRec;
begin
  if FindFirst(Path + '*.kd', faAnyFile, SR) = 0 then
  begin
    repeat
      if (SR.Attr <> faDirectory) then
      begin
        FileList.Add(SR.Name);
      end;
    until FindNext(SR) <> 0;
    FindClose(SR);
  end;
end;

procedure TMainForm.SpinMonatDownClick(Sender: TObject);
begin
  Kalender.PrevMonth;
end;

procedure TMainForm.SpinMonatUpClick(Sender: TObject);
begin
  Kalender.NextMonth;
end;

procedure TMainForm.SpinJahrDownClick(Sender: TObject);
begin
  Kalender.PrevYear;
end;

procedure TMainForm.SpinJahrUpClick(Sender: TObject);
begin
  Kalender.NextYear;
end;

procedure TMainForm.KalenderChange(Sender: TObject);
begin
  listbox2.clear;
  listbox3.clear;
  listbox4.clear;
  listbox5.clear;
  listbox6.clear;
  listbox7.clear;
  listbox8.clear;

  LblDatum.Caption:=FormatDateTime('dddd, dd. mmmm yyyy',Kalender.Date);
  LblTagImJahr.Caption:=IntToStr(Kalender.DayOfYear)+'. Tag im Jahr';
  LblWocheImJahr.Caption:=IntToStr(Kalender.WeekOfYear)+'. Woche im Jahr';

  Label7.Caption:=inttostr(kalender.weekofyear);
  Label8.Caption:=inttostr(kalender.weekofyear-1);
  label9.caption:=inttostr(kalender.weekofyear+1);

  if Kalender.HolidayNr<0 then
    LblFeiertag.Font.Color:=clNavy
  else
    LblFeiertag.Font.Color:=clRed;
  LblFeiertag.Caption:=Kalender.Holiday;
  LblSeason.Caption:=Jahreszeit[ord(Kalender.Season)];
  LblSternzeichen.Caption:='Sternzeichen: '+Sternzeichen[ord(Kalender.ZodiacSign)];
end;

procedure TMainForm.KalenderDblClick(Sender: TObject);
begin
  Kalender.Marked[Kalender.Day]:=not Kalender.Marked[Kalender.Day];
end;

procedure TMainForm.KalenderMonthChange(Sender: TObject);
begin
  LblMonat.Caption:=LongMonthNames[Kalender.Month];
end;

procedure TMainForm.KalenderYearChange(Sender: TObject);
begin
  LblJahr.Caption:=IntToStr(Kalender.Year);
end;



procedure TMainForm.FormCreate(Sender: TObject);
var i : byte;
begin
  ListFileDir('C:\FPV\KUNDEN\', ListBox1.Items);
  for i:=1 to 7 do
  Kalender.Date:=Date;
  KalenderChange(nil);
  KalenderMonthChange(nil);
  KalenderYearChange(nil);

  ListBox1.OnDragOver := ListBox1DragOver;
  ListBox2.OnDragOver := ListBox1DragOver;
  ListBox3.OnDragOver := ListBox1DragOver;
  ListBox4.OnDragOver := ListBox1DragOver;
  ListBox5.OnDragOver := ListBox1DragOver;
  ListBox6.OnDragOver := ListBox1DragOver;
  ListBox7.OnDragOver := ListBox1DragOver;
  ListBox8.OnDragOver := ListBox1DragOver;

  ListBox1.OnDragDrop := ListBox1DragDrop;
  ListBox2.OnDragDrop := ListBox1DragDrop;
  ListBox3.OnDragDrop := ListBox1DragDrop;
  ListBox4.OnDragDrop := ListBox1DragDrop;
  ListBox5.OnDragDrop := ListBox1DragDrop;
  ListBox6.OnDragDrop := ListBox1DragDrop;
  ListBox7.OnDragDrop := ListBox1DragDrop;
  ListBox8.OnDragDrop := ListBox1DragDrop;

  Listbox1.Dragmode := dmAutomatic;
  Listbox2.Dragmode := dmAutomatic;
  Listbox3.Dragmode := dmAutomatic;
  Listbox4.Dragmode := dmAutomatic;
  Listbox5.Dragmode := dmAutomatic;
  Listbox6.Dragmode := dmAutomatic;
  Listbox7.Dragmode := dmAutomatic;
  Listbox8.Dragmode := dmAutomatic;

  ListBox1.MultiSelect := true;
  ListBox2.MultiSelect := true;
  ListBox3.MultiSelect := true;
  ListBox4.MultiSelect := true;
  ListBox5.MultiSelect := true;
  ListBox6.MultiSelect := true;
  ListBox7.MultiSelect := true;
  ListBox8.MultiSelect := true;
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
ini:=TIniFile.create('C:\FPV\KW\' + lbljahr.Caption + '-'+ label7.caption+'-1.kw');
ini.WriteString('Montag','Kunde', '' +listbox2.Items.Text);
ini:=TIniFile.create('C:\FPV\KW\' + lbljahr.Caption + '-'+ label7.caption+'-2.kw');
ini.WriteString('Dienstag','Kunde', '' +listbox3.Items.Text);
ini:=TIniFile.create('C:\FPV\KW\' + lbljahr.Caption + '-'+ label7.caption+'-3.kw');
ini.WriteString('Mittwoch','Kunde', '' +listbox4.Items.Text);
ini:=TIniFile.create('C:\FPV\KW\' + lbljahr.Caption + '-'+ label7.caption+'-4.kw');
ini.WriteString('Donnerstag','Kunde', '' +listbox5.Items.Text);
ini:=TIniFile.create('C:\FPV\KW\' + lbljahr.Caption + '-'+ label7.caption+'-5.kw');
ini.WriteString('Freitag','Kunde', '' +listbox6.Items.Text);
ini:=TIniFile.create('C:\FPV\KW\' + lbljahr.Caption + '-'+ label7.caption+'-6.kw');
ini.WriteString('Samstag','Kunde', '' +listbox7.Items.Text);
ini:=TIniFile.create('C:\FPV\KW\' + lbljahr.Caption + '-'+ label7.caption+'-7.kw');
ini.WriteString('Sonntag','Kunde', '' +listbox8.Items.Text);
end;

procedure TMainForm.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  accept := (Source is TListBox) and (sender<>Source);
end;

procedure TMainForm.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var i,i2 : integer;
    lbSource,lbSender : TListBox;
begin
  lbSource := Source as TListBox;
  lbSender := Sender as TListbox;
  //Drag and drop der gleichen LB verhindern
  if lbSource <> lbSender then
    begin
      //items kopieren
      //du löschst items, deswegen müßte die for Schleife rückwärts zählen, dann würden die itmes aber spiegelverkehrt hinzugefügt
      //ich nehm da lieber eine while schleife, eine for-schleife macht dir das leben schwerer (finde ich)
      i:=0;
      while i<=lbSource.count-1 do //hier muß Source stehen, du willst von source nach Sender!
        begin
          if lbSource.Selected [i] then
            begin
              //Variante 1 = hinzufügen
              //lbSender.Items.Add(lbSource.Items[i]);

              //Variante 2 = Einfügen
              i2:=lbSender.ItemAtPos(point(x,y),false);
              lbSender.Items.insert(i2,lbSource.Items[i]);

              //Einträge in sourceListbox löschen
              lbSource.Items.Delete (i);
              continue; //inc(i) "überspringen" und mit gleichem item (wegen Löschung) weiterarbeiten
            end;
          inc(i);
        end;
    end;
      listbox1.clear;
      ListFileDir('C:\FPV\KUNDEN\', ListBox1.Items);
end;


end.
  Mit Zitat antworten Zitat