Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Listview speichern in mehrere Dateien (https://www.delphipraxis.net/104215-listview-speichern-mehrere-dateien.html)

capo 29. Nov 2007 11:23


Listview speichern in mehrere Dateien
 
Delphi-Quellcode:
procedure TMain.Button13Click(Sender: TObject);
var LCount1, LCount2: Integer;
    LListe: TStringlist;
    LStr: String;
begin
if SaveDialog1.Execute then
  begin
    LListe := TStringlist.Create;
    for LCount1 := 0 to ListView1.Items.Count - 1 do
    begin
     LStr := ' ';
      for LCount2 := 0 to ListView1.Items.Item[LCount1].SubItems.Count - 1 do begin
      if LCount2 = 0 then
  LStr := LStr + '<ansicht>' + Listview1.Items.Item[LCount1].SubItems.Strings[LCount2]+'</ansicht>
'
     else
  LStr := LStr + Listview1.Items.Item[LCount1].SubItems.Strings[LCount2]+'
'
      LListe.Add(LStr);
    end;
    LListe.SaveToFile(SaveDialog1.FileName);
    LListe.Free;
  end;
end;
end;
end;
Hallo,
angenommen in der Listview sind 300 Zeilen.
Wie kann ich alle 10 Zeilen in einer neuen Datei speichern?
Also die ersten 10 = 1. Datei
die nächsten 10 = 2. Datei
usw.

gruss vom capo

marabu 29. Nov 2007 12:01

Re: Listview speichern in mehrere Dateien
 
Hallo Vito,

ich bin mir nicht sicher, ob du mit deinem Ansatz so glücklich wirst, aber dein technisches Problem kannst du etwa so lösen:

Delphi-Quellcode:
const
  MAX_PER_FILE = 10;

function BuildFileName(const fn: TFileName; n: Integer): TFileName;
var
  base, ext: string;
begin
  base := ChangeFileExt(fn, '');
  ext := ExtractFileExt(fn);
  Result := Format('%s.%d%s', [base, n, ext]);
end;

procedure TMain.Button13Click(Sender: TObject);
var
  LCount1, LCount2, n: Integer;
  LListe: TStringlist;
  LStr: String;
  fn: TFileName;
begin
  if SaveDialog1.Execute then
  begin
    n := 0;
    LListe := TStringlist.Create;
    for LCount1 := 0 to ListView1.Items.Count - 1 do
    begin
      LStr := ' ';
      for LCount2 := 0 to ListView1.Items.Item[LCount1].SubItems.Count - 1 do
      begin
        if LCount2 = 0
          then LStr := LStr + '<ansicht>'
                            + Listview1.Items.Item[LCount1].SubItems.Strings[LCount2]
                            + '</ansicht>
'
          else LStr := LStr + Listview1.Items.Item[LCount1].SubItems.Strings[LCount2]
                            + '
';
        LListe.Add(LStr);
      end;
      if (LListe.Count = MAX_PER_FILE) or (LCount1 = Pred(ListView1.Items.Count)) then
      begin
        LListe.SaveToFile(BuildFileName(SaveDialog1.FileName, n));
        Inc(n);
        LListe.Clear; // EDIT
      end;
    end;
    LListe.Free;
  end;
end;
Getippt und nicht getestet.

Grüße vom marabu

SirThornberry 29. Nov 2007 13:22

Re: Listview speichern in mehrere Dateien
 
oder mit modulo:
Delphi-Quellcode:
for i := 0 to x do
begin
  if (i mod 3 = 0) then
    //Neue Datei erstellen
end;

capo 29. Nov 2007 19:49

Re: Listview speichern in mehrere Dateien
 
:hi:
Danke für die Hilfe.


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:36 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz