Autor Beitrag
msickel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64

WinXP Pro
Delphi 2 Pro, Delphi 4 Pro, Delphi 7 Pers, Delphi 2005 Pers, Delphi 2005 Pro
BeitragVerfasst: Di 15.02.05 12:14 
habe folgende Routine gefunden, www.swissdelphicente...showcode.php?id=1823, weiss aber leider nicht so recht wie man Sie anwendet so das man eine html seite in ein richtext umwandelt, so das man im gleichen ordner die richtext datei ausgibt wo die Quelle der html datei ist.

kann mir da jemand kurz einen beispiel geben 8am liebsten mt source!

vielen dank schon mal im vorfeld!

mfg
Martin
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 15.02.05 12:17 
Hallo.

Guckst du dir mal die Parameter im Prozedurkopf an:
ausblenden Delphi-Quelltext
1:
procedure HTMLtoRTF(html: string; var rtf: TRichedit);					

Das erste ist ein ordinärer String, vermutlich also der HTML-Code, den man umwandeln wird, das zweite ist der Verweis auf eine TRichEdit-Komponente, in der der umgewandelte Text dann erscheint. Und soweit ich das noch im Kopf habe besitzt TRichEdit eine Methode zum Speichern der Daten (SaveToFile, glaube ich).
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Di 15.02.05 12:18 
Wo ist genau die Schwierigkeit? HTML-Datei einlesen, Inhalt der Routine übergeben, Rückgabewert speichern - fertig...

AXMD
msickel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64

WinXP Pro
Delphi 2 Pro, Delphi 4 Pro, Delphi 7 Pers, Delphi 2005 Pers, Delphi 2005 Pro
BeitragVerfasst: Di 15.02.05 12:27 
wenn ich eine Variable mit var texthalter: TRichedit; definiere, erhalte ich immer einen Fehler!

was mache ich da falsch ?

Martin
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Di 15.02.05 12:29 
Wie wär's mit etwas Code, damit wir dir helfen können?

AXMD
msickel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64

WinXP Pro
Delphi 2 Pro, Delphi 4 Pro, Delphi 7 Pers, Delphi 2005 Pers, Delphi 2005 Pro
BeitragVerfasst: Di 15.02.05 12:33 
gut, hier kommt er

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TfrmForm1.Button1(Sender: TObject);
var
    wandel: TRichedit;
begin
    HTMLtoRTF('D:\Projekte\APod\explantation.html',wandel);
end;


Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt.
opfer.der.genauigkeit
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754
Erhaltene Danke: 1



BeitragVerfasst: Di 15.02.05 12:35 
Ein Tip ins Blaue aber nach der Variablendeklaration..

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var
  texthalter: TRichedit;
begin
  texthalter := TRichedit.Create(Self);

..

end;


edit: mist zu langsam.. aber das bestätigt ja meine aussage.. es gibt keine gültige Instanz von TRichedit.

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.

_________________
Stellen Sie sich bitte Zirkusmusik vor.
msickel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64

WinXP Pro
Delphi 2 Pro, Delphi 4 Pro, Delphi 7 Pers, Delphi 2005 Pers, Delphi 2005 Pro
BeitragVerfasst: Di 15.02.05 14:46 
hab noch ne Routine gefunden, aber leider gibts beim einbinden auch ne Fehlermeldung

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:
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:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
procedure HTMLToRichEdit(strHTMLCode: string; RichEdit: TRichEdit);
var
  iBreakPos, iPosCtrlCharStart, iPosCtrlCharEnd, iPrevLinesLength, i, j: integer;
  strLine, strCtrlChar, strBreakChar: string;
  TextLayouts: array of TTextLayout;
  CurrentTextFormat: TTextFormat;
  CurrentParagraphFormat: TParagraphFormat;
begin
  RichEdit.Clear;
  // Per regel de RichEdit vullen en opmaak toepassen.
  CurrentParagraphFormat.IsItemized := False;
  CurrentParagraphFormat.Alignment := taLeftJustify;

  strHTMLCode := StringReplace(strHTMLCode, ' ', ' ', [rfReplaceAll]);

  strLine := strHTMLCode;

  GetLineBreak(iBreakPos, strLine, strBreakChar, CurrentParagraphFormat);

  iPrevLinesLength := 0;
  CurrentTextFormat.Bold := swNeutral;
  CurrentTextFormat.Italic := swNeutral;
  CurrentTextFormat.Underline := swNeutral;

  while iBreakPos <> 0 do
  begin
    if iBreakPos = -1 then
    begin
      iBreakPos := 0;
      strHTMLCode := '';
    end
    else
    begin
      strHTMLCode := Copy(strHTMLCode, iBreakPos + Length(strBreakChar), Length(strHTMLCode));
    end;
    // De tekstregel in strLine zetten:
    // De huidige regel van strHTMLCode afknippen:
    i := 0;
    SetLength(TextLayouts, i);
     iPosCtrlCharStart := Pos('<', strLine);
    if iPosCtrlCharStart <> 1 then
    begin
      // De HTML-code begint niet een controlchar; het eerste deel van
      // de text heeft geen opmaak.
      SetLength(TextLayouts, i + 1);
      TextLayouts[i].strText := Copy(strLine, 1, iPosCtrlCharStart - 1);
      TextLayouts[i].TextFormat.Bold := swNeutral;
      TextLayouts[i].TextFormat.Italic := swNeutral;
      TextLayouts[i].TextFormat.Underline := swNeutral;
      strLine := Copy(strLine, iPosCtrlCharStart, Length(strLine));
      inc(i);
    end;
    // iPosCtrlCharStart = 1 in strLine
    iPosCtrlCharEnd := Pos('>', strLine);
    while iPosCtrlCharEnd > 0 do
    begin
      SetLength(TextLayouts, i + 1);
      strCtrlChar := Copy(strLine, 2, iPosCtrlCharEnd - 2);
      strLine := Copy(strLine, iPosCtrlCharEnd + 1, Length(strLine));
      iPosCtrlCharStart := Pos('<', strLine);
      if iPosCtrlCharStart > 0 then
      begin
        TextLayouts[i].strText := Copy(strLine, 1, iPosCtrlCharStart - 1);
        strLine := Copy(strLine, iPosCtrlCharStart, Length(strLine));
      end
      else
      begin
        // Geen controlchars meer; rest van strLine toevoegen:
        TextLayouts[i].strText := strLine;
        strLine := '';
      end;
      // Opmaak toepassen:
      TextLayouts[i].TextFormat.Bold := swNeutral;
      TextLayouts[i].TextFormat.Italic := swNeutral;
      TextLayouts[i].TextFormat.Underline := swNeutral;

      if strCtrlChar = 'B' then
        TextLayouts[i].TextFormat.Bold := swActivate;
      if strCtrlChar = '/B' then
        TextLayouts[i].TextFormat.Bold := swDeactivate;
      if strCtrlChar = 'I' then
        TextLayouts[i].TextFormat.Italic := swActivate;
      if strCtrlChar = '/I' then
        TextLayouts[i].TextFormat.Italic := swDeactivate;
      if strCtrlChar = 'U' then
        TextLayouts[i].TextFormat.Underline := swActivate;
      if strCtrlChar = '/U' then
        TextLayouts[i].TextFormat.Underline := swDeactivate;

      iPosCtrlCharEnd := Pos('>', strLine);

      inc(i);
    end;
    if Length(strLine) > 0 then
    begin
      SetLength(TextLayouts, i + 1);
      TextLayouts[i].strText := strLine;
      TextLayouts[i].TextFormat.Bold := swNeutral;
      TextLayouts[i].TextFormat.Italic := swNeutral;
      TextLayouts[i].TextFormat.Underline := swNeutral;
    end;

    strLine := '';
    for i := Low(TextLayouts) to High(TextLayouts) do
    begin
      strLine := strLine + TextLayouts[i].strText;
    end;
    RichEdit.Lines.Add(strLine);

    RichEdit.Paragraph.Alignment := CurrentParagraphFormat.Alignment;

    if CurrentParagraphFormat.IsItemized and
      (RichEdit.Paragraph.Numbering = nsNone) then
      RichEdit.Paragraph.Numbering := nsBullet;
    if (not CurrentParagraphFormat.IsItemized) and
      (RichEdit.Paragraph.Numbering = nsBullet) then
      RichEdit.Paragraph.Numbering := nsNone;

    j := 0;
    for i := Low(TextLayouts) to High(TextLayouts) do
    begin
      if (TextLayouts[i].TextFormat.Bold = swActivate) then
        CurrentTextFormat.Bold := swActivate;
      if (TextLayouts[i].TextFormat.Bold = swDeactivate) then
        CurrentTextFormat.Bold := swDeactivate;

      if (TextLayouts[i].TextFormat.Italic = swActivate) then
        CurrentTextFormat.Italic := swActivate;
      if (TextLayouts[i].TextFormat.Italic = swDeactivate) then
        CurrentTextFormat.Italic := swDeactivate;

      if (TextLayouts[i].TextFormat.Underline = swActivate) then
        CurrentTextFormat.Underline := swActivate;
      if (TextLayouts[i].TextFormat.Underline = swDeactivate) then
        CurrentTextFormat.Underline := swDeactivate;

      RichEdit.SelStart := j + iPrevLinesLength;
      RichEdit.SelLength := Length(TextLayouts[i].strText);

      if (CurrentTextFormat.Bold = swActivate) and
        not (fsBold in RichEdit.SelAttributes.Style) then
        RichEdit.SelAttributes.Style := RichEdit.SelAttributes.Style + [fsBold];
      if (CurrentTextFormat.Bold = swDeactivate) and
        (fsBold in RichEdit.SelAttributes.Style) then
        RichEdit.SelAttributes.Style := RichEdit.SelAttributes.Style - [fsBold];

      if (CurrentTextFormat.Italic = swActivate) and
        not (fsItalic in RichEdit.SelAttributes.Style) then
        RichEdit.SelAttributes.Style := RichEdit.SelAttributes.Style + [fsItalic];
      if (CurrentTextFormat.Italic = swDeactivate) and
        (fsItalic in RichEdit.SelAttributes.Style) then
        RichEdit.SelAttributes.Style := RichEdit.SelAttributes.Style - [fsItalic];

      if (CurrentTextFormat.Underline = swActivate) and
        not (fsUnderline in RichEdit.SelAttributes.Style) then
        RichEdit.SelAttributes.Style := RichEdit.SelAttributes.Style + [fsUnderline];
      if (CurrentTextFormat.Underline = swDeactivate) and
        (fsUnderline in RichEdit.SelAttributes.Style) then
        RichEdit.SelAttributes.Style := RichEdit.SelAttributes.Style - [fsUnderline];

      j := j + Length(TextLayouts[i].strText);
    end;
    iPrevLinesLength := Length(RichEdit.Text);

    strLine := strHTMLCode;
    if iBreakPos > 0 then
      GetLineBreak(iBreakPos, strLine, strBreakChar, CurrentParagraphFormat);
  end;
end;

procedure GetLineBreak(var iBreakPos: integer;
            var strLine, strBreakChar: string;
            var CurrentParagraphFormat: TParagraphFormat);
var
  i, j: integer;
  str0, str1: string;
  IsOk: boolean;
begin
  iBreakPos := 0;
  for i := 1 to 7 do
  begin
    case i of
      1: str0 := '<BR>';
      2: str0 := '<LI>';
      3: str0 := '</LI>';
      4: str0 := '</P>';
      5: str0 := '<P Align="LEFT">';
      6: str0 := '<P Align="CENTER">';
      7: str0 := '<P Align="RIGHT">';
    end;
    j := Pos(str0, strLine);
    if j > 0 then
    begin
      if iBreakPos = 0 then
      begin
        iBreakPos := j
      end
      else
      begin
        if j < iBreakPos then iBreakPos := j;
      end;
    end;
  end;
  str1 := Copy(strLine, iBreakPos, Length(strLine));
  if iBreakPos > 0 then
    strLine := Copy(strLine, 1, iBreakPos - 1)
  else iBreakPos := -1;
  strBreakChar := '';
  IsOk := True;
  while IsOk do
  begin
    IsOk := False;
    for i := 1 to 7 do
    begin
      case i of
        1: str0 := '<BR>';
        2: str0 := '<LI>';
        3: str0 := '</LI>';
        4: str0 := '</P>';
        5: str0 := '<P Align="LEFT">';
        6: str0 := '<P Align="CENTER">';
        7: str0 := '<P Align="RIGHT">';
      end;
      if Pos(str0, str1) = 1 then
      begin
        if (str0 <> '<BR>') or (Length(strBreakChar) = 0) then
          strBreakChar := strBreakChar + str0;
          str1 := Copy(str1, Length(str0) + 1, Length(str1));

        if str0 <> '<BR>' then
          IsOk := True;

        if str0 = '</P>' then
          CurrentParagraphFormat.Alignment := taLeftJustify;

        if str0 = '<LI>' then
          CurrentParagraphFormat.IsItemized := True;

        if str0 = '</LI>' then
          CurrentParagraphFormat.IsItemized := False;

        if str0 = '<P Align="LEFT">' then
        begin
          CurrentParagraphFormat.Alignment := taLeftJustify;
          IsOk := True;
        end;
        if str0 = '<P Align="CENTER">' then
        begin
          CurrentParagraphFormat.Alignment := taCenter;
          IsOk := True;
        end;
        if str0 = '<P Align="RIGHT">' then
        begin
          CurrentParagraphFormat.Alignment := taRightJustify;
          IsOk := True;
        end;
      end;
    end;
  end;
end;


welche uses muss ich den einbinden um die Fehlermeldungen bei den Variablendeklarationen zu verwmeiden
CurrentTextFormat: TTextFormat;
CurrentParagraphFormat: TParagraphFormat;

hier kommt immer undefinierter bezeichner
Lesco
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 42



BeitragVerfasst: Mi 16.03.05 18:56 
user profile iconopfer.der.genauigkeit hat folgendes geschrieben:
Ein Tip ins Blaue aber nach der Variablendeklaration..

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var
  texthalter: TRichedit;
begin
  texthalter := TRichedit.Create(Self);

..

end;


edit: mist zu langsam.. aber das bestätigt ja meine aussage.. es gibt keine gültige Instanz von TRichedit.

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.


man könnte auch ne komponente einfügen und visible auf false setzen, dann erspart man sich das create usw