Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Sa 20.02.10 09:37 
Hi, Delpher,

ich möchte mit dem folgenden Code verschiedene Komponenten, die eine Canvas haben, ansprechen können, also z.B. ein Label oder das Formular.
Es wird klaglos kompiliert, aber auf dem Label wird nichts ausgegeben, sondern nur auf dem Formular.

Irgendetwas habe ich wohl vergessen ...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TBuchMain.TextGedreht(kompo: Tcomponent; ts: String; xw, yw, hoch, winkel: smallint);  //Gedrehte Schrift
var  lf: LOGFONT;                  // Windows-eigene Schriftartstruktur
begin
  Canvas.Brush.Style := bsClear;   // Pinselstil auf Transparent setzen
  FillChar(lf, SizeOf(lf), Byte(0));
  lf.lfHeight := hoch;             // z.B. 20
  lf.lfEscapement  := 10 * winkel; // z.B. 45, Grad der Drehung
  lf.lfOrientation := 10 * winkel;
  lf.lfCharSet := DEFAULT_CHARSET;
  StrCopy(lf.lfFaceName, 'Tahoma');

  Canvas.Font.Handle := CreateFontIndirect(lf);
  Canvas.TextOut(xw, yw, ts);     // z.B. bei 75, 700 'Los geht´s!'
end;

// ..............

TextGedreht(label10, DateiName, 5, 0, 11, 0);
TextGedreht(BuchMain, 'Los geht´s', 75, 680, 20, 45);


Aber was?
Danke für Hilfe,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Sa 20.02.10 09:50 
Falls TBuchMain dein Formular ist, dann ist der Canvas den du verwendest immer der Canvas von dem Forumlar und nicht der von der übergebenen Komponente.

Beste Grüße
Tastaro
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Sa 20.02.10 09:55 
Das sieht so aus. Und was müsste ich jetzt verändern?
Det

_________________
ut vires desint, tamen est laudanda voluntas
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Sa 20.02.10 10:11 
Naja, das geht nur mit Komponenten an deren Canvas du heran kommst.
Auswenig weiß ichs grad nicht aber entwerde tpanel oder tlabel können das.
Würde dann etwa so aussehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TBuchMain.TextGedreht(kompo: Tcomponent; ts: String; xw, yw, hoch, winkel: smallint);  
var
   LocalCanvas: tcanvas;
   ...
begin
   LocalCanvas := nil;
   if kompo is tlabel then
      LocalCanvas := (kompo as tlabel).Canvas;
   if kompo is tform then
      LocalCanvas := (kompo as tform).Canvas;
   if assigned(LocalCanvas) then
   begin 
      //Hier Text ausgeben
   end;
   
end;


Beste Grüße
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Sa 20.02.10 10:55 
Nun habe ich den folgenden Code, aber auf dem Label wird immer noch nichts ausgegeben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TBuchMain.TextGedreht(kompo: Tcomponent; ts: String; xw, yw, hoch, winkel: smallint);  //Gedrehte Schrift
var  lf: LOGFONT;                  // Windows-eigene Schriftartstruktur
   LocalCanvas: tcanvas;
begin
  FillChar(lf, SizeOf(lf), Byte(0));
  lf.lfHeight := hoch;             // z.B. 20
  lf.lfEscapement  := 10 * winkel; // z.B. 45, Grad der Drehung
  lf.lfOrientation := 10 * winkel;
  lf.lfCharSet := DEFAULT_CHARSET;
  StrCopy(lf.lfFaceName, 'Tahoma');

  LocalCanvas := nil;
  if kompo is tlabel then  LocalCanvas := (kompo as tlabel).Canvas;
  if kompo is tform then   LocalCanvas := (kompo as tform).Canvas;
  if assigned(LocalCanvas) then
  begin
    LocalCanvas.Brush.Style := bsClear;   // Pinselstil auf Transparent setzen
    LocalCanvas.Font.Handle := CreateFontIndirect(lf);
    LocalCanvas.TextOut(xw, yw, ts);     // z.B. bei 75, 700 'Los geht´s!'
  end;
end;


Uff, Det

_________________
ut vires desint, tamen est laudanda voluntas
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 20.02.10 11:06 
Ich habe es gerade ausprobiert, das klappt so problemlos bei mir. Rufst du es vielleicht an der falschen Stelle auf? Wenn du zum Beispiel das in OnShow oder OnCreate oder so hast, bringt es natürlich nix, weil danach die Komponente ohnehin neu gezeichnet wird. Und diesen Fall behandelst du dann gar nicht.
Oder reagierst du aufs Neuzeichnen schon?

Dann noch ein Tipp: Wenn du mit is abgefragt hast, ob es ein bestimmter Typ ist, dann kannst du danach auch direkt casten. Mit as wird erneut der Typ geprüft, damit sonst eine Exception kommt, das kannst du dir da sparen. Und ein else spart nochmal unnötige Prüfungen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
  if kompo is TLabel then
    LocalCanvas := TLabel(kompo).Canvas
  else if kompo is TForm then
    LocalCanvas := TForm(kompo).Canvas;
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Sa 20.02.10 11:15 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Dann noch ein Tipp: Wenn du mit is abgefragt hast, ob es ein bestimmter Typ ist, dann kannst du danach auch direkt casten. Mit as wird erneut der Typ geprüft, damit sonst eine Exception kommt, das kannst du dir da sparen. Und ein else spart nochmal unnötige Prüfungen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
  if kompo is TLabel then
    LocalCanvas := TLabel(kompo).Canvas
  else if kompo is TForm then
    LocalCanvas := TForm(kompo).Canvas;


Du hast Recht, aber
Leserlichkeit > Meist nutzloser Einsparung von Nanosekunden.

Beste Grüße
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 20.02.10 11:20 
Es gibt mit as auch andere Nachteile. Zum Beispiel ist da nix mit direktem Debuggen, jedenfalls in D2006. Halt die Maus direkt hinter TLabel(kompo) und du bekommst sofort den Tooltip zum Ausklappen usw. mit der Komponente.
Wenn du das bei (kompo as TLabel) versuchst, geht das nicht.

Genausowenig kannst du das mit Strg + F7 auswerten.

Klar ist die Zeiteinsparung alleine nicht so wichtig, ich wollte eben nur nicht so ausführlich werden, warum es noch so sinnvoller ist. ;-)
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Sa 20.02.10 13:58 
Vielen Dank, ihr zwei! Wieder viel gelernt!
Gruß aus HL, Detlef

(War eben schwimmen [1500m, *strunz*], deshalb hat meine Antwort so lange gedauert)

_________________
ut vires desint, tamen est laudanda voluntas