Autor Beitrag
D.Elphi
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 128
Erhaltene Danke: 10

Windows 10 Edu x64
Tokyo Starter, BlueJ
BeitragVerfasst: Do 12.01.17 15:24 
Hallo zusammen,
mein Programm generiert während seiner Ausführung ein Log in einem Memo. Ich möchte dem User anbieten, das Log als txt oder als html exportieren zu können. Damit die HTML-Datei aber "was taugt", muss an jede Zeile des Memos ja der </br>-Tag angefügt werden, damit alles schön wie im Memo untereinander steht. Folgendes ist mein bisheriger Ansatz:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
if SaveDialog1.FilterIndex = 1 then //Auswahl: HTML
begin
for x := 0 to Memo1.Lines.Count do
Memo1.Lines.??? ; //hier liegt mein Problem - was muss da hin?
end;


Wie kann ich also an jede Zeile des Memos den Tag anfügen?

MfG

D.Elphi
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6386
Erhaltene Danke: 146

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 12.01.17 15:49 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
if SaveDialog1.FilterIndex = 1 then //Auswahl: HTML
begin
for x := 0 to Memo1.Lines.Count-1 do // bitte bei dir korrigieren
Memo1.Lines[x] := Memo1.Lines[x] + '</br>';
end;

Für diesen Beitrag haben gedankt: D.Elphi
D.Elphi Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 128
Erhaltene Danke: 10

Windows 10 Edu x64
Tokyo Starter, BlueJ
BeitragVerfasst: Do 12.01.17 15:54 
Das ging ja schnell. Besten Dank! :D :zustimm:
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19272
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 12.01.17 17:06 
Besser weil deutlich schneller ist direkt die Logdaten im Hintergrund über eine TStringList zu speichern. Die ist deutlich schneller als die TMemoStrings in Memo1.Lines.

Sprich wenn das mehr als nur ein paar Zeilen sind, kann das mit deiner Lösung schonmal etwas dauern.
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1652
Erhaltene Danke: 243

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Do 12.01.17 19:28 
Hallo,

user profile iconjaenicke hat vollkommen recht.Eine Stringliste ist erheblich schneller.
Hier mal ein Beispiel mit Button1 und Memo1 mit 1 Mio Zeilen mit Lazarus, deshalb {$R *.lfm} statt {$R *.dfm}.
Mit Memo1.lines dauert es insgesamt 31 Sekunden mit der Stringliste 1.56 Sekunden ( die Stringerzeugung in DoSomething dauert auch ohne einfügen in die Stringliste 1.46 Sekunden, das anhängen von '</BR>' nur 0.09 Sekunden ) und dass anschliessende einfügen auf Memo1 1,09 Sekunden, was aber zum schreiben in eine Datei nicht nötig ist.

ausblenden volle Höhe 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:
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:
type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    const
      cMax = 20;
    var
      n_max : NativeInt;
      m_max,gesCount :NativeInt;
      dummyTxt : String;
      combination: array [0..cMax] of byte;
      MeineListe : TStringlist;

    procedure DoSomething;
    procedure generate(m, n: NativeInt);
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation
{$IFDEF FPC} {$R *.lfm} {$ELSE} {$R *.dfm} {$ENDIF}

{ TForm1 }

procedure TForm1.DoSomething;
//Erzeugen des Strings einer Kombination
var
  i : NativeInt;
  s : String;
Begin
  inc(gesCount);

  s := '';
  for i := 1 to m_max do
  begin
    str(combination[i]:3,dummyTxt);
    s := s+dummyTxt;
  end;

  MeineListe.Add(s);
//  Memo1.Lines.Add(s)

end;

procedure TForm1.generate(m,n: NativeInt);
//Erzeugt alle Kombinationen aus 1.. n_max mit m_max Stellen
 begin
  IF m = m_max then
    For n := n to n_max do
    Begin
      combination[m] := n;
      DoSomething;
    end
  else
    For n := n to n_max do
    Begin
      combination[m] := n;
      generate(m+1,n+1);
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   T1,T0: TDateTime;
   i : NativeInt;

begin
  Memo1.lines.clear;
  Memo1.lines.BeginUpdate;
  T0:= now;
  n_max := cMax;
  MeineListe:= TStringlist.create;
  MeineListe.Capacity:= 1 shl cMax -1;
  Memo1.lines.Capacity:= 1 shl cMax -1;
  For i := 1 to cMax do
  Begin
    m_Max:= i;
    generate(1,1);
  end;
  T1:= now;

  Memo1.Lines.Add(Format(' MeineListe.Count   %d',[MeineListe.Count]));
  Memo1.Lines.Add(Format(' Laufzeit           %f',[(T1-T0)*86400]));
  T0:= now;
  For i := MeineListe.Count-1 downto 0 do
     MeineListe[i]:= MeineListe[i]+'</BR>';
  T1:= now;
  Memo1.Lines.Add(Format(' Laufzeit anfuegen %f',[(T1-T0)*86400]));
  Memo1.Lines.addstrings(MeineListe);
  T0:= now;
  Memo1.Lines.Add(Format(' Laufzeit einfuegen %f',[(T0-T1)*86400]));

  Memo1.lines.EndUpdate;
  MeineListe.free;
end;

end.
{Laufzeit Memo1.lines
 Memo1.Lines.Count   1048575</BR>
 Laufzeit           12.08</BR>
 Laufzeit anfuegen 19.10
.........
 Laufzeit MeineListe
 MeineListe.Count   1048575</BR>
 Laufzeit           1.46
 Laufzeit anfuegen  0.09
Laufzeit einfuegen  1.09
}


Gruß Horst