Welcome, Guest
Guest Settings
Help

Thread: Delphi2010 high dpi issue with MessageDlg



Permlink Replies: 7 - Last Post: Feb 22, 2017 6:40 AM Last Post By: Michael Rabatsc... Threads: [ Previous | Next ]
Michael Rabatsc...

Posts: 104
Registered: 1/22/07
Delphi2010 high dpi issue with MessageDlg
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 28, 2016 2:48 AM
Hi Folks!

On my new laptop (192dpi) I just ran into a problem with high dpi aware
applications and the displayed icon when calling MessageDlg....

As far as I could analyze the problem is within Dialogs.pas
-> CreateMessageDialog and the creation of the icon image.
It has a fixed size of 32 pixels and does not account for the real icon
size that it loads (which is on my system 64x64) thus
just a quarter of the icon is displyed.

How can I patch that routine (preferable by not copying
the unit into my root directory). And if I need to do
this as a last resort how does it behave if I need to use
packages which also define this unit?

kind regards
Mike
Michael Rabatsc...

Posts: 104
Registered: 1/22/07
Re: Delphi2010 high dpi issue with MessageDlg
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 28, 2016 6:29 AM   in response to: Michael Rabatsc... in response to: Michael Rabatsc...
Am 28.01.2016 um 11:48 schrieb Michael Rabatscher:
Hi Folks!

On my new laptop (192dpi) I just ran into a problem with high dpi aware
applications and the displayed icon when calling MessageDlg....

As far as I could analyze the problem is within Dialogs.pas
-> CreateMessageDialog and the creation of the icon image.
It has a fixed size of 32 pixels and does not account for the real icon
size that it loads (which is on my system 64x64) thus
just a quarter of the icon is displyed.

How can I patch that routine (preferable by not copying
the unit into my root directory). And if I need to do
this as a last resort how does it behave if I need to use
packages which also define this unit?

I was able to patch the CreateMessageDlg function defined in dialogs.pas
such that the icon is displyed properly.
(via some detour code that exchanges the pointer to that function)

Nevertheless if I use packages the code does not work... anyone got an
idea here?

kind regards
Mike
Peter Below

Posts: 1,065
Registered: 12/16/99
Re: Delphi2010 high dpi issue with MessageDlg
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 28, 2016 10:19 AM   in response to: Michael Rabatsc... in response to: Michael Rabatsc...
Michael Rabatscher wrote:

Am 28.01.2016 um 11:48 schrieb Michael Rabatscher:
Hi Folks!

On my new laptop (192dpi) I just ran into a problem with high dpi
aware applications and the displayed icon when calling
MessageDlg....

As far as I could analyze the problem is within Dialogs.pas
-> CreateMessageDialog and the creation of the icon image.
It has a fixed size of 32 pixels and does not account for the real
icon size that it loads (which is on my system 64x64) thus
just a quarter of the icon is displyed.

How can I patch that routine (preferable by not copying
the unit into my root directory). And if I need to do
this as a last resort how does it behave if I need to use
packages which also define this unit?

I was able to patch the CreateMessageDlg function defined in
dialogs.pas such that the icon is displyed properly.
(via some detour code that exchanges the pointer to that function)

Nevertheless if I use packages the code does not work... anyone got
an idea here?

Perhaps it would be easier to rewrite your code to use
Windows.MessageBox instead. If you need something that works if the
application is build with run-time packages you would otherwise patch
the dialog at run-time (so you can patch the code contained in the
package).

To replace the use of Dialogs.MessageDlg in your code create a new
unit, redefine MessageDlg with the exact same parameter list (all the
overloads the Dialogs unit contains should be replaced), and implement
it by calling Window.MessageBox. You now only need add this unit to the
end of the Uses list (the one in the implementation section) of the
unit that calls MessageDlg, rebuild, and the code will use your
function.

--
Peter Below
TeamB
Michael Rabatsc...

Posts: 104
Registered: 1/22/07
Re: Delphi2010 high dpi issue with MessageDlg
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 1, 2016 1:07 AM   in response to: Peter Below in response to: Peter Below

I was able to patch the CreateMessageDlg function defined in
dialogs.pas such that the icon is displyed properly.
(via some detour code that exchanges the pointer to that function)

Nevertheless if I use packages the code does not work... anyone got
an idea here?

Perhaps it would be easier to rewrite your code to use
Windows.MessageBox instead. If you need something that works if the
application is build with run-time packages you would otherwise patch
the dialog at run-time (so you can patch the code contained in the
package).

To replace the use of Dialogs.MessageDlg in your code create a new
unit, redefine MessageDlg with the exact same parameter list (all the
overloads the Dialogs unit contains should be replaced), and implement
it by calling Window.MessageBox. You now only need add this unit to the
end of the Uses list (the one in the implementation section) of the
unit that calls MessageDlg, rebuild, and the code will use your
function.

Thanks for the hint. As far as I can see is the parameter handling in
MessageBox quite different to the one in MessageDlg (e.g. button
appearance) so I guess this is not the way to go...

I also tried to copy the unit dialogs.pas into the local directory
and add the unit to the project list so it should override
the one in the rtl source code. This only works if I don't use
packages. The problem is that the unit in Delphi2010 uses some pointer
references to resource strings which create compiler errors if I use the
copy and rename the unit name...)

So.. is there any solution like code detour (I would only need to patch
one function CreateMessageDialog) or such that works
for both monolithic executables and packages?

kind regards
Mike

Remy Lebeau (Te...


Posts: 8,062
Registered: 12/23/01
Re: Delphi2010 high dpi issue with MessageDlg
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 1, 2016 9:45 AM   in response to: Michael Rabatsc... in response to: Michael Rabatsc...
Michael wrote:

The problem is that the unit in Delphi2010 uses some pointer references
to resource strings which create compiler errors if I use the copy

Such as? The RTL's resource strings are publically accessible via the Consts
and RtlConsts units.

and rename the unit name...

You are not supposed to rename anything.

--
Remy Lebeau (TeamB)
Michael Rabatsc...

Posts: 104
Registered: 1/22/07
Re: Delphi2010 high dpi issue with MessageDlg
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2016 5:38 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Such as? The RTL's resource strings are publically accessible via the Consts
and RtlConsts units.

Just as a test... copy dialogs.pas to the local source directory,
rename the unit to mydialogs.pas and add it to the a new project.

If you compile with packages you get the error:

[DCC Fehler] E2201 Für den Zugriff auf 'SMsgDlgInformation' von Unit 'HighDPIDialogs' wird die Referenz auf importierte Daten ($G) benötigt

Meaning that for the access to SMsgDlgInformation in the renamed unit I need a reference to the imported Data...

So.. how do I achieve that. EMB help suggests to add the directive
(*$IMPORTEDDATA ON*) to the new unit (or did I misread something??)... The thing is that doesn't do a thing...

You are not supposed to rename anything.

Then how can I use e.g. dialogs.pas without any headache in my local project (when I use packages)?

kind regards
Mike

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 8,062
Registered: 12/23/01
Re: Delphi2010 high dpi issue with MessageDlg
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2016 11:23 AM   in response to: Michael Rabatsc... in response to: Michael Rabatsc...
Michael wrote:

Just as a test... copy dialogs.pas to the local source directory,
rename the unit to mydialogs.pas and add it to the a new project.

If you compile with packages you get the error:

[DCC Fehler] E2201 Für den Zugriff auf 'SMsgDlgInformation' von Unit
'HighDPIDialogs' wird die Referenz auf importierte Daten ($G) benötigt

The error is referring to the {$IMPORTEDDATA} compiler directive:

http://docwiki.embarcadero.com/RADStudio/en/Imported_data

SMsgDlgInformation is declared in the Vcl.Consts unit. Maybe the Vcl runtime
package has been compiled with {$G-} enabled, preventing other packages from
accessing its resource strings directly. You don't run into this problem
when compiling without runtime packages.

--
Remy Lebeau (TeamB)
Michael Rabatsc...

Posts: 104
Registered: 1/22/07
Re: Delphi2010 high dpi issue with MessageDlg
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 22, 2017 6:40 AM   in response to: Michael Rabatsc... in response to: Michael Rabatsc...
Hi!

Finally - I think I got a solution for the patching problem by orienting
how A. Hausladen does his patching in the VCL fixing unit.

-> actually now I reroute the procedure calls to my own (mostly copied from Dialogs.pas)
CreateMessageDlg function globally.

afaik that would works for packages and for non package compiled versions + it doesn't interfere
with any of the previous resourcestring problems.

kind regards
Mike
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02