Hi,
ich hab ein bisschen Probleme mit
TCanvas, mit der Delphi-Hilfe komm ich auch nicht wirklich weiter...
Es geht um eine Funktion, die einen Pfad einkürzt.
In der Funktion will ich die Länge eines Strings bei einer verwendeten Schrift (
AFont) feststellen. Dafür benutze ich einen "Test"-Canvas und dessen Funktion
TextWidth.
Allerdings bekomme ich immer den Fehler "Drawing not allowed on Canvas"!
Was muss ich machen, damit ich TestCanvas.TextLength(String) auch wirklich aufrufen kann?
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
| function ShortenPath(const APath: String; AMaxPixelWidth: Integer; APlaceHldr: String; APrefferedSection: TPrefferedSection; AFont: TFont): String; var WorkStr: String; i,a,AvailPixels: Integer; DirParts: TStrings; TestCanvas.TCanvas; begin if ACanvas.TextWidth(APath) <= AMaxPixelWidth then begin Result := APath; Exit; end; DirParts := TStringList.Create; TestCanvas := TCanvas.Create; TestCanvas.Font := AFont; AvailPixels := AMaxPixelWidth-TestCanvas.TextWidth(Copy(APath,1,2))-TestCanvas.TextWidth(APlaceHldr);
TestCanvas.Free; end; |
Vielen Dank schon mal für jede Hilfe!!
Frankie
Moderiert von
Narses: Topic aus Multimedia / Grafik verschoben am Mo 17.03.2008 um 11:57