Thanks for all the suggestions. But it worked in the way I called the method. Problem was in setting the new resolution.
Yah, I do agree that better way would be to type-cast the pointer and then dereference it, instead of type-casting the dereferenced pointer. Best regards, Shweta Jain Tata Consultancy Services Limited Raja Shree Bldg. 8 Tadiwalla Road Pune - 411 001,Maharashtra India Mailto: [EMAIL PROTECTED] Website: http://www.tcs.com "Katja Bergman" <[EMAIL PROTECTED]> Sent by: [email protected] 07/19/2005 07:24 PM Please respond to [email protected] To [email protected] cc Subject [delphi-en] Re: Restoring default display setting problem That's exactly what I wanted to say. Then again, after reading nil^ I was first too busy laughing about such a very obvious error. ;-) But to be more serious... The problem is that in the Windows unit, this function is declared as: function ChangeDisplaySettings(var lpDevMode: TDeviceMode; dwFlags: DWORD): Longint; stdcall; Now checking the http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_7gz7.asp page, I immediately see the problem. You have to send a nil to this function but unfortunately, Delphi doesn't allow this to be used with VAR parameters. So how to get around this? Well, this code should work: ChangeDisplaySettings(PDeviceMode(Nil)^, 0); However, it might be easier to just re-include this function in your source like this: function ChangeDisplaySettings(lpDevMode: pDeviceMode; dwFlags: DWORD): Longint; stdcall; external 'user32.dll' name 'ChangeDisplaySettingsA'; And then you can just use: ChangeDisplaySettings(Nil, 0); Simply because this function is now better defined than the Delphi version. But it means adjusting code at more than one location. I would use: ChangeDisplaySettings(Nil,0); or ChangeDisplaySettings(TDeviceMode(Nil),0); though... That is This is a well-known problem with some of the Delphi WINAPI convertions. Delphi has defined them as VAR parameters yet the WINAPI allows nil values tto be used here. Personally, I would have preferred it if Borland just kept these things as pointers instead as VAR parameters but then again, no one else seems to be complaining about this and it's probably been in there for about 7 Delphi versions... With kind regards, X Katja Bergman. (Who still has to giggle about it.) --- In [email protected], "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi Shweta, > my windows help says to call ChangeDisplaySettings(0,0) or ChangeDisplaySettings(Null,0) > your construction of TDeviceMode(Nil^) is invalid an should lead to access violations because Nil is never adressing anything. > > Have fun > Bob > > > > I am calling method as ChangeDisplaySettings(TDeviceMode(Nil^),0). > > According to documentation of ChangeDisplaySettings, it should restore the > > default display settings that are stored in registry, but it is not doing > > so. Can any body suggest the reason. > > > > > > ----------------------------------------------------- Home page: http://groups.yahoo.com/group/delphi-en/ To unsubscribe: [EMAIL PROTECTED] SPONSORED LINKS C programming language Computer programming languages The c programming language C programming language List of programming languages Delphi programmer YAHOO! GROUPS LINKS Visit your group "delphi-en" on the web. To unsubscribe from this group, send an email to: [EMAIL PROTECTED] Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. ForwardSourceID:NT0000A116 Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you [Non-text portions of this message have been removed] ----------------------------------------------------- Home page: http://groups.yahoo.com/group/delphi-en/ To unsubscribe: [EMAIL PROTECTED] Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/delphi-en/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

