AGB  ·  Datenschutz  ·  Impressum  







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

NativeInt to string

Ein Thema von venice2 · begonnen am 10. Sep 2022 · letzter Beitrag vom 10. Sep 2022
Antwort Antwort
Seite 1 von 2  1 2      
venice2
(Gast)

n/a Beiträge
 
#1

NativeInt to string

  Alt 10. Sep 2022, 14:22
Kann ich NativeInt wie bisher mit IntToStr zu String konvertieren? Oder geht dabei was verloren..
  Mit Zitat antworten Zitat
Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.009 Beiträge
 
Delphi 12 Athens
 
#2

AW: NativeInt to string

  Alt 10. Sep 2022, 14:26
Kannst du. Unter 64-Bit wird dann die Int64-Variante von IntToStr verwendet.
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat
venice2
(Gast)

n/a Beiträge
 
#3

AW: NativeInt to string

  Alt 10. Sep 2022, 14:31
Kannst du. Unter 64-Bit wird dann die Int64-Variante von IntToStr verwendet.
Danke..
  Mit Zitat antworten Zitat
venice2
(Gast)

n/a Beiträge
 
#4

AW: NativeInt to string

  Alt 10. Sep 2022, 15:24
Es stimmt was nicht mehr.

ImgBack: LONG_PTR;

Das ImgBack wird geladen .

ImgBack := SkinEngine.skCreateImageFromFile(SelectedImg);
Delphi-Quellcode:
function TSkinEngine.skCreateImageFromFile(FileName: WideString): LONG_PTR;
var
  Img: LONG_PTR;
begin

  Img := 0;

  if not FileExists(FileName) then
  begin
    Result := 0;
    Exit;
  end;

  //Image laden
  try
    GdipCheck(GdipLoadImageFromFile(PWideChar(FileName), Img));
  finally
    Result := Img;
  end;
end;
und in eine TStringList gepackt.
SetProperty(Handle, PROP_IMAGE_SELECTED, ImgBack);
Delphi-Quellcode:
procedure TSkinListBox.SetProperty(WinHandle: hWnd; Item: Integer; V: LONG_PTR);
begin
  if (Item > 0) and (WinHandle <> 0) then
    PropList.Add(IntToStr(WinHandle) + ',' + IntToStr(Item) + ',' + IntToStr(V));

end;
Delphi-Quellcode:
function TSkinListBox.GetProperty(WinHandle: hWnd; Item: Integer): LONG_PTR;
var
  SplitProperty: TSplitStrArray;
  IntI: Integer;
begin
  Result := 0;

  if (Item > 0) and (WinHandle <> 0) then
  begin
    for IntI := 0 to PropList.Count - 1 do
    begin
      SplitProperty := Split(PropList.Strings[IntI], ',');
      if SplitProperty[0] = IntToStr(WinHandle) then
      begin
        Result := LONG_PTR(SplitProperty[2]);
        exit;
      end;
    end;
  end;

end;
Später lese ich das ImgBack aus den Propertys zurück.

ImgBack := GetProperty(WinHandle, PROP_IMAGE_SELECTED);

Zeichne ich jetzt den Button
Delphi-Quellcode:
          SkinEngine.PaintButton(Graphics, 4, ImgBack, Rect.Left,
            Rect.Top - (ListItemHeight - 16) div 2, UInt(Rect.Right - FLeft), UInt(ListItemHeight),
            BS_PUSHBUTTON)
und hole mir die Image Größe dann krachts.
Delphi-Quellcode:
  if ImgBack <> 0 then
  begin
    GetImageSize(ImgBack, BackW, BackH);
Delphi-Quellcode:
procedure TSkinEngine.GetImageSize(Img: LONG_PTR; var imgW, imgH: UINT);
begin
  if img <> 0 then
  begin
    GdipCheck(GdipGetImageWidth(Img, imgW));
    GdipCheck(GdipGetImageHeight(Img, imgH));
  end;
end;
Die Probleme habe ich nur unter 64Bit und D11.2 vorher unter D11 funktioniert noch alles.

Geändert von venice2 (10. Sep 2022 um 16:16 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.142 Beiträge
 
Delphi 12 Athens
 
#5

AW: NativeInt to string

  Alt 10. Sep 2022, 15:27
TSplitStrArray sind Strings.

Zitat:
Result := LONG_PTR(SplitProperty[2])
Wieso castest du also einen "String" in einen Pointer, wenn du doch einen "Integer" in den Pointer casten willst?

Fazit: Zuerst der String zu Integer NativeInt (weil sonst knallt es mal im 64 Bit) und das dann zum Pointer.



Ja, IntToStr gibt es in zwei Varianten, wie dir das CodeInsight und die Hilfe sagen wird.
Nur anderstum, muß man es manuell machen, also StrToInt64, weil der Parameter "String" ja identisch wäre.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (10. Sep 2022 um 15:29 Uhr)
  Mit Zitat antworten Zitat
venice2
(Gast)

n/a Beiträge
 
#6

AW: NativeInt to string

  Alt 10. Sep 2022, 15:29
TSplitStrArray sind Strings.

Wieso castest du also einen "String" in einen Pointer, wenn du doch einen "Integer" in den Pointer casten willst?

Fazit: Zuerst der String zu Integer NativeInt (weil sonst knallt es mal im 64 Bit) und das dann zum Pointer.
Wo caste (konvertiere) ich den String in einen Pointer? LONG_PTR ist NativeInt kein Pointer oder?
Delphi-Quellcode:
  {$EXTERNALSYM UINT_PTR}
  LONG_PTR = NativeInt;

Geändert von venice2 (10. Sep 2022 um 15:34 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.142 Beiträge
 
Delphi 12 Athens
 
#7

AW: NativeInt to string

  Alt 10. Sep 2022, 15:35
Zitat:
Result := LONG_PTR(SplitProperty[2])


Das wird der Zeiger auf den String, in dem die "Zahl" als Text drin steht, oder nicht?
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
venice2
(Gast)

n/a Beiträge
 
#8

AW: NativeInt to string

  Alt 10. Sep 2022, 15:42
Zitat:
Result := LONG_PTR(SplitProperty[2])


Das wird der Zeiger auf den String, in dem die "Zahl" als Text drin steht, oder nicht?
Für mich wird hier ein NativeInt Datentyp zurückgegeben vielleicht verstehe ich dich auch nicht.

So funktioniert es nun bis das nächste Problem auftaucht.

Delphi-Quellcode:
function TSkinListBox.GetProperty(WinHandle: hWnd; Item: Integer): LONG_PTR;
var
  SplitProperty: TSplitStrArray;
  IntI: Integer;
begin
  Result := 0;

  if (Item > 0) and (WinHandle <> 0) then
  begin
    for IntI := 0 to PropList.Count - 1 do
    begin
      SplitProperty := Split(PropList.Strings[IntI], ',');
      if SplitProperty[0] = IntToStr(WinHandle) then
      begin
        Result := LONG_PTR(StrToInt64(SplitProperty[2]));
        exit;
      end;
    end;
  end;

end;
Danke
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.142 Beiträge
 
Delphi 12 Athens
 
#9

AW: NativeInt to string

  Alt 10. Sep 2022, 16:11
Egal was es für ein Typ ist.

Der "Wert" ist/war die Adresse (Zeiger) des Strings.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
venice2
(Gast)

n/a Beiträge
 
#10

AW: NativeInt to string

  Alt 10. Sep 2022, 16:13
Egal was es für ein Typ ist.

Der "Wert" ist/war die Adresse (Zeiger) des Strings.
Verstehe Danke..

Ohne deine Hilfe hätte ich das Problem nicht so schnell gefunden.
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


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 12:35 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz