![]() |
AW: EllipsisCharacter funktioniert nicht
Zitat:
Konkret hat try..finally für dich in deinem Codebeispiel die folgenden Vorteile:
Klar kannst du es auch ohne try..finally hinbekommen, dass deine Objekte nur finalisiert werden, wenn sie zuvor auch korrekt initialisiert wurden, aber dann landest du zwangsweise bei Variante 1 oder 2 meines "C" Negativbeispiels. Edit: Zitat:
Zitat:
Delphi-Quellcode:
bzw. ein
Exit
Delphi-Quellcode:
folgen muss.
raise
|
AW: EllipsisCharacter funktioniert nicht
Zitat:
Wird der Code Langsamer ? oder was sonst. Im Moment sehe ich nur das ich vielleicht ein paar Zeilen mehr schreiben muss wobei das Ergebnis das gleiche ist. Mir erschließt sich das nicht so richtig. So wie ich hier im Forum sehe verwenden viele meine Variante über Verschachtelungen. EDIT: Zitat:
Dann wäre es sicherlich eine Bereicherung. gruss |
AW: EllipsisCharacter funktioniert nicht
Zitat:
|
AW: EllipsisCharacter funktioniert nicht
Zitat:
Delphi-Quellcode:
zweimal zu schreiben.
GdipDeleteGraphics(Graphics);
GdipDeleteFont(TempFont); GdipDeleteFontFamily(Fam); GdipDeleteStringFormat(strFormat); |
AW: EllipsisCharacter funktioniert nicht
Zitat:
Ok das ist ein Grund für mich diesen Block bei bestimmten Konstellationen zu verwenden. Danke! :) gruss |
AW: EllipsisCharacter funktioniert nicht
Ok habe es geändert und auch deine Exception Funktion mit eingebunden. ;)
Delphi-Quellcode:
Ich kann mir jetzt auch noch so etwas sparen.
function TSkinListView.DrawEllipsisText(DC: Hdc; UseText: WideString; rec: TRect;
ColrARGB: COLORREF; UseFont: WideString; UseSize: Single; FontStyle: TFontStyle; ShadowOffset: Single; UseStrFormat: Integer; WordWrap: Bool = False): GpStatus; var Width: Integer; Fam: GpFontFamily; TempFont: GpFont; Graphics: Cardinal; rectF: TGPRectF; Rect, rc, rc2: TRect; strFormat: Pointer; begin Result := GenericError; Graphics := 0; strFormat := nil; TempFont := nil; Fam := nil; try GdipCheck(GdipCreateFromHDC(DC, Graphics)); GdipCheck(GdipCreateFontFamilyFromName(UseFont, nil, Fam)); if assigned(Fam) then begin GdipCheck(GdipCreateFont(Fam, UseSize, FontStyle, 2, TempFont)); if assigned(TempFont) then begin GdipCheck(GdipCreateStringFormat(0, 0, strFormat)); GdipCheck(GdipMeasureString(Graphics, UseText, length(UseText), TempFont, @layoutRect, strFormat, @boundingBox, nil, nil)); GetWindowRect(HeaderHandle, rc); GetWindowRect(Handle, rc2); Width := (rec.Right - rec.Left) + ((rc.Left - rc2.Left) - 1); if boundingBox.Width > Width then begin rectF := MakeRect(rec.Left, rec.Top, Width, rec.Bottom); Rect.Left := round(rectF.x); Rect.Top := round(rectF.y); Rect.Bottom := round(rectF.Height); Rect.Right := round(rectF.Width); UseStrFormat := ZD_Ellipsis; Result := DrawTextToDC(DC, UseText, Rect, ColrARGB, UseFont, UseSize, FontStyle, ShadowOffset, UseStrFormat, True); end else Result := DrawTextToDC(DC, UseText, rec, ColrARGB, UseFont, UseSize, FontStyle, ShadowOffset, UseStrFormat, WordWrap); end; end; finally if Graphics <> 0 then GdipCheck(GdipDeleteGraphics(Graphics)); if assigned(TempFont) then GdipCheck(GdipDeleteFont(TempFont)); if assigned(Fam) then GdipCheck(GdipDeleteFontFamily(Fam)); if assigned(strFormat) then GdipCheck(GdipDeleteStringFormat(strFormat)); end; end;
Delphi-Quellcode:
if GdipDrawString(Graphics, PWideChar(sTxt), -1, curFont, @rcLayout, strFormat, brush)
= OK then // Resourcen freigeben GdipDeleteBrush(brush) else begin GdipDeleteBrush(brush); exit; end;
Delphi-Quellcode:
Von daher ;)
try
GdipCheck(GdipDrawString(Graphics, PWideChar(sTxt), -1, curFont, @rcLayout, strFormat, brush)) finally // Resourcen freigeben if Assigned(brush) then GdipCheck(GdipDeleteBrush(brush)); end; Na ja lohnt sich doch nehme alles zurück. Bei mir muss das schon einen sinn ergeben einfach etwas zu übernehmen weil es jemand sagt ist nicht so mein Ding :) Man muss es auch verstehen. gruss |
AW: EllipsisCharacter funktioniert nicht
Wo bitte habe ich dich als dumm bezeichnet? Ich habe dir nur versucht zu erklären, dass das pauschale Ablehnen eines Sprachkonstrukts eventuell auf Unwissenheit zurück zu führen ist. Aber mittlerweile wurde dir ja sehr gut mit Beispielen die Nützlichkeit gezeigt.
|
AW: EllipsisCharacter funktioniert nicht
Zitat:
Bau mir jetzt den Kompletten Code um.. Dauert ein paar Stunden. Aber auf der Basis lohnt sich das. Kein Problem :cheers: Zitat:
gruss |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:28 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz