Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi NativeInt to string (https://www.delphipraxis.net/211400-nativeint-string.html)

venice2 10. Sep 2022 14:22

NativeInt to string
 
Kann ich NativeInt wie bisher mit IntToStr zu String konvertieren? Oder geht dabei was verloren..

Uwe Raabe 10. Sep 2022 14:26

AW: NativeInt to string
 
Kannst du. Unter 64-Bit wird dann die Int64-Variante von IntToStr verwendet.

venice2 10. Sep 2022 14:31

AW: NativeInt to string
 
Zitat:

Zitat von Uwe Raabe (Beitrag 1511550)
Kannst du. Unter 64-Bit wird dann die Int64-Variante von IntToStr verwendet.

Danke..

venice2 10. Sep 2022 15:24

AW: NativeInt to string
 
Es stimmt was nicht mehr.

Delphi-Quellcode:
ImgBack: LONG_PTR;


Das ImgBack wird geladen .

Delphi-Quellcode:
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.
Delphi-Quellcode:
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.

Delphi-Quellcode:
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.

himitsu 10. Sep 2022 15:27

AW: NativeInt to string
 
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.

venice2 10. Sep 2022 15:29

AW: NativeInt to string
 
Zitat:

Zitat von himitsu (Beitrag 1511556)
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;

himitsu 10. Sep 2022 15:35

AW: NativeInt to string
 
Zitat:

Delphi-Quellcode:
Result := LONG_PTR(SplitProperty[2])

:stupid:

Das wird der Zeiger auf den String, in dem die "Zahl" als Text drin steht, oder nicht?

venice2 10. Sep 2022 15:42

AW: NativeInt to string
 
Zitat:

Zitat von himitsu (Beitrag 1511560)
Zitat:

Delphi-Quellcode:
Result := LONG_PTR(SplitProperty[2])

:stupid:

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

himitsu 10. Sep 2022 16:11

AW: NativeInt to string
 
Egal was es für ein Typ ist.

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

venice2 10. Sep 2022 16:13

AW: NativeInt to string
 
Zitat:

Zitat von himitsu (Beitrag 1511566)
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.


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:47 Uhr.
Seite 1 von 2  1 2      

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