AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Variablen nicht NIL 64Bit

Ein Thema von EWeiss · begonnen am 1. Sep 2018 · letzter Beitrag vom 12. Sep 2018
 
Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.055 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#22

AW: Variablen nicht NIL 64Bit

  Alt 3. Sep 2018, 12:20
Ich hab mal an die entsprechenden Stellen Kommentare gepackt und sie mit SG markiert.

Delphi-Quellcode:
var
  Graphics: LONG_PTR;
  Fam: GpFontFamily;
  TempFont: GpFont;
  rb: TRect;
  xWidth, YHeight: Integer;
  strFormat: GPSTRINGFORMAT;
  boundingBox, layoutRect: TGPRectF;

begin

  result := GenericError;
  strFormat := nil;
  Fam := nil;
  TempFont := nil; ..// hier kommt Warnung unter D2010 in Delphi 10.2.3 nicht. Deshalb war es vorher nicht addiert.
                     // habe es aber jetzt trotzdem addiert und ignoriere die Warnung.

                     // SG: Einige Hinweise in Bezug auf nicht initialisierte Variablen oder nicht benutzte Werte
                     // wurden erst jüngst in 10.1 oder 10.2 gefixt, siehe Changelogs/fixed issues, daher fälschlicherweise Hinweis unter Delphi 2010
  Graphics := 0;

  try
    GdipCheck(GdipCreateFontFamilyFromName(PWideChar(UseFont), FontCollection, Fam));
    if Assigned(Fam) then
    begin
      GdipCheck(GdipCreateFont(Fam, UseSize, FontStyle, 2, TempFont));
      if Assigned(TempFont) then
      begin
        // 0: Kein Schatten
        // Positiver wert für Schatten Rechts
        // Negativer wert für Schatten links
        // Zeichne den string
        GdipCheck(GdipCreateStringFormat(0, 0, strFormat));
        GdipCheck(GdipCreateFromHDC(DC, Graphics));

        FillChar(boundingBox, SizeOf(boundingBox), 0);
        FillChar(layoutRect, SizeOf(layoutRect), 0);

        GdipCheck(GdipMeasureString(Graphics, PWideChar(UseText), length(UseText), TempFont,
            @layoutRect, strFormat, @boundingBox, nil, nil));

        if Assigned(strFormat) then
          GdipCheck(GdipDeleteStringFormat(strFormat));

        if not WordWrap then
        begin
          xWidth := round(boundingBox.Width + 0.5);
          YHeight := round(boundingBox.Height + 1.5);
          if BlurText then
          begin
            SetRect(rb, rec.Left, rec.Top, rec.Left + xWidth, rec.Top + YHeight);
            BlurTextPlus(DC, UseText, rb, TempFont, BlurColor, 4, UseStrFormat);
          end;
        end else
        begin
          xWidth := rec.Right;
          YHeight := rec.Bottom;
          if BlurText then
          begin
            SetRect(rb, rec.Left, rec.Top, rec.Left + xWidth, rec.Top + YHeight);
            BlurTextPlus(DC, UseText, rb, TempFont, BlurColor, 4, UseStrFormat);
          end;
        end;

        result := DrawStringFormatedEx(Graphics, UseText, rec.Left, rec.Top, xWidth, YHeight,
          ColrARGB, SkinEngine.SK_TEXTRENDERING, TempFont, ShadowOffset, UseStrFormat);
      end;
    end;
  finally
    if Graphics <> 0 then
    begin
      GdipCheck(GdipDeleteGraphics(Graphics));
      Graphics := 0;
    end;

    if Assigned(TempFont) then // SG: Dieser Code kann ausgeführt werden wenn z.B. oben if Assigned(Fam) false lieferte.
                               // Dann wird TempFont nämlich nicht durch GdipCreateFont gesetzt und ist somit nicht initialisiert
                               // Da nun aber auf dem Stack unter 32bit "immer" nil stand, hat man hier Glück gehabt
    begin
      GdipCheck(GdipDeleteFont(TempFont)); // Und hier kracht es unter Win10 wenn TempFont mit irgendwas gefüllt wird. (In D2010 nicht! )
      TempFont := nil;
    end;

    if Assigned(Fam) then
    begin
      GdipCheck(GdipDeleteFontFamily(Fam));
      Fam := nil;
    end;
  end;

end;
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:46 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