Vista, inifiles, and run at startup oddities... what the heck - delphi

I've got something happening with a little app that I made that I don't understand what the problem is. The app is just a little texted panel clock that sits above the taskbar on the second monitor. Settings are saved via inifile in the proper appdata folder, and the specs are saved properly, i.e. X and Y location, font, font style, etc.
I wanted it to run automatically when Windows boots up, so yesterday I just dragged a shortcut to the Start | Programs | Startup folder. This morning when booting up, for a moment, it loaded in the proper location, then quickly moved itself back to 0 by 0 on the X-Y plane. I looked at the inifile, and sure enough... it's Top=1133 Left=1920, just like it is supposed to be, yet windows starts it at Top=0 Left=0.
What the heck?...

Check that you have the 'position=poDesigned' as well. If you dont, it will use that setting preferentially. If this is ok, put a fixed offset in your X&Y properties to see if that is where it is defaulting to. Ideally you should be setting your desired XY position no earlier than AfterCreation, do it in FormCreate if you can because by that time the form is all yours to play with.
Brian.

Related

What can I do if my program stops running at the begin statement and forces me to click run again?

I have tried debugging, but because I'm a beginner I can’t seem to find the problem. I have a feeling it has to do with the text highlighted in red.
This can happen if you have breakpoints from a previous session (or in the CPU window) and they are out of sync. This can also happen if you have shifted your code to a different drive or folder. They are not visible, but the debugger has to break at the nearest line.
To fix
Click on View / Debug / Breakpoints or Ctrl+Alt+B
Delete All Breakpoints
EDIT
The project.dsk file stores the breakpoints as an absolute path to the filename. If the project is shifted so that the drive or folder change, the breakpoints remain pointing to the non-existent file. From my experience, the IDE then compensates by breaking at the first line of the project.

ScreenSnap not working anymore under Windows 10

There seems to be an issue with the TForm.ScreenSnap property on Windows 10.
I always have ScreenSnap active for Main Forms, and the SnapBuffer set to 10 pixels. This works fine until Windows 10.
Now, if ScreenSnap is active, the Form will stick to the screen edge as it is supposed to do. But, if I want to un-stick it, I have to move the window vigorously. If I move the mouse too slow, the Form will remain stuck to the screen border, resulting in a very weird user experience.
Does anyone know how to fix this (without disabling ScreenSnap on Windows 10)? Or, at least, can anyone else confirm this as a bug?

How to restore/clear form position after multi-monitor setup change

Within the IDE, when F12 toggles between code and form,
the forms are displayed outside the monitor borders,
and therefore not visible.
This happens after a multi monitor setup has changed,
and the forms no longer open within the available new monitor screen areas.
One way to resolve this is to use the property inspector and
set the Top/Left properties to 4 to make the forms visible.
This is however a lot of work,
especially if many forms and possibly many projects are involved.
Is there a better way to reset the form locations once and for all,
so they are all visible with the new monitor setup?
There is nothing (AFAIK) in Delphi 6 IDE that would help. But assuming you are using Windows, the help is near, (tested on Windows 7):
Right-click on taskbar and select 'Cascade windows', this affects all windows in one go.
or
Alt-Tab to the window, press Alt-Space and then M (for move). Move the window with the arrow keys. This you would have to do seperately for each window.
Close your Delphi IDE. Then, if your current project group file is xyz.groupproj, open the file xyz.dsk with an text editor. Look for section [UndockedDesigner] entry "Count" and change its value to zero.
[UndockedDesigner]
Count=0
That will force all design window positions to 0,0 on your main monitor.

Delphi D2010 Component Palette icons all wrong

I have just built a new system. (Win 8.1, 64 bit, D2010). Install went fine... adding some various VCLs. For some reason, in the Delphi Component Palette, all component glyphs PAST the 'Gestures' palette are all defaulting to the 'generic' icon. The first 13 tabsheets use proper icons. The remaining 30 or so tabsheets use the generic 'Blue box, red triangle, gold circle' image.
Delphi compiles my apps fine. For some reason the GLYPHs are just messed up. I have exited Delphi, restarted, even rebooted the machine. It was initially working fine, but then it messed up. So what did I do? I installed a few components, which I have installed before... I added some help files to the Windows help system for one of the components. I added some directories to the Delphi Path, and added a new BPL file for some of the components, and I went into the Tool/Options/Component Tool Bar and moved one component from a page by itself to another page. This left an empty page/tabsheet, so I deleted it. Thinking this might be the problem, I went back in and clicked on 'Reset to Default'. It did reset the one component back to a page by itself. Restarted Delphi... same issue.
UPDATED INFO***: Some Embarcadero supplied pages show fine, others show 'Unknown/Default' Glyph. For example, the first 13 pages are good, then are 10 or so pages bad, then SAMPLES, INTERNET, and few others are good. Pages that are bad include INDY (the whole set) and IW (the whole set). All my TMS stuff is good (which I installed). Some of the JVCL pages are good, some are bad. Interestingly, one page, Jv Edits, is half bad, then the rest of the page is good.
I don't know why, but when I switched back and forth to different IDE Layouts (Default Layout, Classic Undocked, etc) a few times, the palette glyphs got reloaded, and now everything looks as it should.

Windows appearing off edge of screen (Delphi)

Windows in my application are popping up off the edge of the screen, and this of course is a problem because some of the windows are modal and can't be dismissed (you don't even know they are there).
I'm using the TurboPower Orpheus component which remembers the location and size of each form, then restores it when the form is shown again. It saves the size and placement in an INI file.
What can I do to prevent windows from ever showing off the side of the screen?
It's common for this sort of thing to happen if you use multiple monitors and then disconnect one, such as when undocking a laptop. Or if you dock a laptop to a screen with a higher resolution. Or use remote desktop, etc..
The remedy is to override the "remember my position" behavior with a sanity check, to see if the left+width exceeds the width of the screen (Screen.Monitors array, actually - thanks guys), and vice-versa for the top+height.
Ideally, you "bump" by subtracting the difference, so you're butting up against the edge that the window wanted to straddle.
Also, see if there are updates to Orpheus that fix this. If not, you can get the source, make the correction (optional), and contribute it back to the project. It's OSS, as I recall.
You may want to give a look at their DefaultMonitor property and read the code from TCustomForm.SetWindowToMonitor to see how to deal with positioning relatively to Screen.Monitors.
Use DefaultMonitor to associate a form with a particular monitor in a multi-monitor application. The following table lists the possible values:
Value Meaning
dmDesktop No attempt is made to position the form on a specific monitor.
dmPrimary The form is positioned on the first monitor listed in the global screen object's Monitors property.
dmMainForm The form appears on the same monitor as the application's main form.
dmActiveForm The form appears on the same monitor as the currently active form.
Note: DefaultMonitor has no effect if the application does not have a main form.
To recall the previous position of a form, without having it suddenly in an area which is no longer available (due to a plugged off screen or changed resolution), you just call
TForm.MakeFullyVisible;
That's it. See the documentation.

Resources