Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Windows Icon (https://www.delphipraxis.net/195324-windows-icon.html)

Willie1 20. Feb 2018 10:40

Windows Icon
 
Hallo Leute,
ich bin immer noch mit dem Umzug von D 2005 zu Delphi Berlin beschäftigt und erlebe Überrascungen.

Ich will eine Windows Ikone - hier das weiße ? auf blauem Grund - auf ein eigenes Fenster plazieren. Ich gehe so vor:
Delphi-Quellcode:
procedure TForm2.FormPaint(Sender: TObject);
var
  Icon: TIcon;
begin
  Icon:=TIcon.Create;
  Icon.Handle:=LoadIcon(0,IDI_QUESTION);
  if Icon.Handle > 0 then Form2.Canvas.Draw(25,35,Icon); //<------
  Icon.Free
end;
Das klappt, wenn ich das Fenster statisch anlege. Falls ich es dynamisch anlege, so:
Delphi-Quellcode:
    with TForm2.Create(Form1) do
      try
        aw:=ShowModal;
      finally
        free
      end;
dann kracht es in der markierten Zeile: Zugriffsverletzung. Ich verstehe, das Fenster ist für Paint (noch) nicht bereit. Ich habe es mit OldOrderCreate=true versucht, bringt aber nichts. Aber warum hat es mit Delphi 2005 funktioniert!?

Gruß Willie..

Sherlock 20. Feb 2018 10:44

AW: Windows Icon
 
Ich behaupte mal, es liegt am
Delphi-Quellcode:
with
.

Sherlock

Jasocul 20. Feb 2018 10:45

AW: Windows Icon
 
Delphi-Quellcode:
procedure TForm2.FormPaint(Sender: TObject);
var
  Icon: TIcon;
begin
  Icon:=TIcon.Create;
  Icon.Handle:=LoadIcon(0,IDI_QUESTION);
//  if Icon.Handle > 0 then Form2.Canvas.Draw(25,35,Icon); //<------
  if Icon.Handle > 0 then Canvas.Draw(25,35,Icon); //<------
  Icon.Free
end;
So sollte es theoretisch funktionieren.

Willie1 20. Feb 2018 10:55

AW: Windows Icon
 
Hallo Jasoul, das ist die Lösung!

Hallo Sherlock,
Zitat:

Ich behaupte mal, es liegt am with .
diesen "Trick" habe ich mir Jahren ausgedacht, er funktioniert prima.

Tschüss und danke
Willie.

himitsu 20. Feb 2018 11:48

AW: Windows Icon
 
Zitat:

Delphi-Quellcode:
Form2.xxx

Du erstellst die Form manuell, setzt diese Variable nicht und wunderst dich, dass es beim Zugriff darauf knallt?

Abgesehn davon, dass man innerhalb der eigenen Klasse "niemals" auf diese Variable zugreifen sollte.


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:40 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