Autor Beitrag
lexmy3
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

WIN 2000 Prof. + Office 2000
Delphi 5 Enterprise
BeitragVerfasst: Di 10.01.06 11:55 
Hallo,

Ich möchte in einem RichEdit einen Inhaltsverzeichnis erstellen in Fett.
Aber bei mir wird nur die Überschrift Fett. Hat einer nen Tip wie ich diesen Code für alle Einträge mache.

ausblenden 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:
  with RichEditGeneral do
    begin
    SetFocus;
    SelStart := Length(Text);
    SelAttributes.Style := [fsBold];
///////////////////////////////////////////////////////////////////////////////
// Einfügen des Inhaltsverzeichnises///////////////////////////////////////////
Lines.Add (#10'Content:'#10#10);
Lines.Add ('1   General statements'#13#10);
Lines.Add ('2   Sewage, water and gas system'#13#10);
Lines.Add ('3   Heating supply system'#13#10);
Lines.Add ('4   Air handling system'#13#10);
Lines.Add ('5   Electrical installations'#13#10);
Lines.Add ('6   Lifts'+#13#10);
Lines.Add ('7   Building automation'#13#10);
Lines.Add ('8   Defaults and deficiencies'#13#10);
Lines.Add ('9   Costs'#13#10);
Lines.Add ('10   Photo documentation'
+#10#10#10#10#10#10#10#10#10#10#10#10#10#10#10 //15  // Zeilenumbruch
+#10#10#10#10#10#10#10#10#10#10#10#10#10);//13
/////////////////////////////////////////////////////////////////////////////////
    Lines.Add ('1   General Statements'#13#10);
    SelAttributes.Style := SelAttributes.Style-[fsBold];
    end;


mfg Lexmy3
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 10.01.06 13:09 
Hallo,

dein Code hier funktioniert einwandfrei,
hab ihn gerade 1 zu 1 getestet,
er hat doch auch dort schon funktioniert :arrow: Link
Ist das der komplette Code? :gruebel:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Di 10.01.06 17:07 
Hallo !
Ersetz mal in zeile 5 Sel durch Def dann funkt's.
ausblenden Delphi-Quelltext
1:
DefAttributes.Style := [fsBold];					
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 10.01.06 18:50 
Hallo,

@user profile iconlexmy3:
Du hast es richtig gesehen, hab gerade noch mal auf meinem anderen Rechner(XP) getestet,
da ist es so das der durch SelAttributes gesetzte Style,
nicht mit in die nächste Zeile übernommen wird.
Bei meinem anderen Rechner (NT, und demzufolge eine ältere Riched.dll)
wird der gesetzte Style auch für die nachfolgend angehängten Zeilen übernommen.

@user profile iconBlackheart666:
Mit DefAttributes wird der Style der Standard-Schrift des Richedits gesetzt.
Es ist das gleiche als wenn RichEdit1.Font.Style := [fsBold]; genutzt wird.

Sind schon Zeilen mit Normalschrift im Richedit enthalten,
werden diese durch DefAttributes auch in Fettschrift formatiert.
Der folgende Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  with RichEdit1 do
    begin
    SetFocus;
    Lines.Add ('Normalschrift');
    SelStart := Length(Text);
    DefAttributes.Style := [fsBold];
    Lines.Add ('Zeile 1 in bold');
    Lines.Add ('Zeile 2 in bold');
    SelAttributes.Style := SelAttributes.Style-[fsBold];
    Lines.Add ('Zeile wieder normal');
    end;

hat das Ergebnis unter NT und XP:
Zitat:
Normalschrift
Zeile 1 in bold
Zeile 2 in bold

Zeile wieder normal


So, und jetzt zur Lösung:
Damit es unabhängig funktioniert diese zwei Varianten.
Sie funktionieren mit NT, XP und Windows 2000:

Varinat 1.
Wenn die Anzahl und Inhalte der anzuhängenden Zeilen nicht feststeht,
z.B. wenn das Richedit über eine Schleife gefüllt wird:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
var x : Integer;
begin
  with RichEdit1 do
    begin
    SetFocus;
    Lines.Add ('Normalschrift');
    x := Length(Text); //merken
    Lines.Add ('Zeile 1 in bold');
    Lines.Add ('Zeile 2 in bold');
    SelStart := x;
    SelLength := Length(Text)-x;
    SelAttributes.Style := [fsBold];
    x := Length(Text); //merken
    Lines.Add ('Zeile wieder normal');
    Lines.Add ('Zeile auch normal');
    SelStart := x;
    SelLength := Length(Text)-x;
    SelAttributes.Style := SelAttributes.Style-[fsBold];
    end;


Varinat 2.
Wenn die Inhalte im Code festgelegt werden können.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
  with RichEdit1 do
    begin
    SetFocus;
    Lines.Add ('Normalschrift');
    SelStart := Length(Text);
    SelAttributes.Style := [fsBold];
    Lines.Add ('Zeile 1 in bold'+#13#10
              +'Zeile 2 in bold');
    SelStart := Length(Text);
    SelAttributes.Style := SelAttributes.Style-[fsBold];
    Lines.Add ('Zeile wieder normal'+#13#10
              +'Zeile auch normal');
    end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Di 10.01.06 19:00 
Das war doch Sinn der Sache denk Ich mal.
Sonst wäre doch diese Zeile
SelAttributes.Style := SelAttributes.Style-[fsBold];
überflüssig.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 10.01.06 19:39 
Hallo,
user profile iconBlackheart666 hat folgendes geschrieben:
Das war doch Sinn der Sache denk Ich mal.
Sonst wäre doch diese Zeile
SelAttributes.Style := SelAttributes.Style-[fsBold];
überflüssig.

Der Titel macht doch deutlich das user profile iconlexmy3 die Zeilen in RichEdit gezielt formatieren möchte.
Gut, mit DefAttributes oder RichEdit.Font.Style kann ich die ersten Zeilen des Richedits auf bold stellen.
Aber spätestens, wenn nach dem Inhaltsverzeichnis normal formatierte Zeilen angehängt werden sollen ist man mit DefAttributes am Ende.
Da geht es dann nur mit SelAttributes weiter. :wink:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Di 10.01.06 19:56 
@Lannes
Ja wenn man von der Warte rangeht hast Du natürlich recht.
Ich hatte das so verstanden das nur das Inhaltsverzeichnis Fett dargestellt wird und danach eben in Normalen Style weitergeschrieben wird.
Bin nur von Ich möchte in einem RichEdit einen Inhaltsverzeichnis erstellen in Fett.
Aber bei mir wird nur die Überschrift Fett.
ausgegangen.
lexmy3 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

WIN 2000 Prof. + Office 2000
Delphi 5 Enterprise
BeitragVerfasst: Do 12.01.06 10:55 
Titel: Zeilen gezielt formatieren?
Hey Leute,

Danke für die Tips!

Aber jetzt habe ich ein weiteres Problem.

Das mit dem Inhaltsverzeichnis in Bold hat funktioniert doch für die Überschrift auf der Titelseite nicht.

Und zwar, weil diese Form in welcher der Text in RichEdit gesammelt wird geschlossen wird. Und hier kommt eine Exeption auf mit 'Ein deaktiviertes oder geschlossenes Fenster kann nicht den Focus erhalten'

Wie kan ich es umgehen? Es hat ja auch bei Inhaltsverzeichnis geklappt, obwohl es auch geschlossen wird.
:gruebel:

mfg lexmy3
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 12.01.06 12:22 
Hallo,

ohne jetzt die Zusammenhänge in Deinem Programm genau zu kennen,
deaktivier mal die Zeile mit: SetFocus;
dann funktioniert es wahrscheinlich.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
lexmy3 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

WIN 2000 Prof. + Office 2000
Delphi 5 Enterprise
BeitragVerfasst: Do 12.01.06 13:53 
user profile iconLannes hat folgendes geschrieben:
Hallo,

ohne jetzt die Zusammenhänge in Deinem Programm genau zu kennen,
deaktivier mal die Zeile mit: SetFocus;
dann funktioniert es wahrscheinlich.


Hey Supper, hat geklappt!!!

Aber Warum setze ich den Focus überhaupt?
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 12.01.06 14:29 
Hallo,

zum Beispiel, wenn Zeilen über einen Button eingefügt werden,
ist der Focus nach dem Button-Klick durch SetFocus; wieder beim RichEdit und man kann direkt per Tastatur weiterschreiben ohne das Richedit erst Aktivieren zu müssen.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
lexmy3 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

WIN 2000 Prof. + Office 2000
Delphi 5 Enterprise
BeitragVerfasst: Do 12.01.06 16:38 
Aha jetz ja

Danke Dir Lannes!!!

mfg

Lexmy3