Reputation: 1
I have problem with my form application created in Delphi 5. In this app I have few buttons which open (set visible property) different forms. This forms as a parent have Panel. Only one function is overridden:
procedure TForm.CreateParams(var Params : TCreateParams);
begin
inherited CreateParams(Params);
with Params do begin
Style := ws_Child;
X :=FormMain.panelMain.Left;
Y :=FormMain.panelMain.Top;
Height :=FormMain.panelMain.Height;
Width := FormMain.panelMain.Height;
WndParent := FormMain.Handle;
end
end;
I have also function to change actual form on panel:
procedure TFormMain.ChangeToForm(newForm: TMainForm);
begin
if (newForm=nil) or (newForm=lastForm) then EXIT;
actForm:=newForm;
actForm.Visible :=true;
if assigned(lastForm) then lastForm.Visible:=false;
lastForm:=actForm;
LabelScreen.Caption:=actForm.Caption;
newForm.Left := 0;
newForm.Top := 0;
newForm.Width := panelMDI.Width;
newForm.Height := panelMDI.Height;
newForm.Left := panelMDI.Left;
newForm.Top := panelMDI.Top;
end;
When I open application everything works fine. Buttons change forms. Everything is ok. But when user don't use this app (don't changes forms etc.) for some period of time. Clicking on the buttons generate exceptions:
Access violation at address 0044D761 in module 'rozpoznawanie.exe'. Read of address 00000004; EAccessViolation
[...]
00534f2e jz loc_534fe9
00534f34 196 mov eax, [ebp-8]
00534f37 mov [$54b3a4], eax
00534f3c 197 mov dl, 1
00534f3e mov eax, [$54b3a4]
00534f43 > call -$9c194 ($498db4) ; Forms.TCustomForm.SetVisible
00534f48 198 cmp dword ptr [$54b3a8], 0
00534f4f jz loc_534f5d
00534f51 xor edx, edx
00534f53 mov eax, [$54b3a8]
00534f58 call -$9c1a9 ($498db4) ; Forms.TCustomForm.SetVisible
[...]
I've looked everywhere and I don't know why it appears. Do you have some ideas?
EDIT
I found that the problem may be earlier:
00756bc8 vcl70.bpl Controls.TWinControl.HandleNeeded
00756bd5 vcl70.bpl Controls.TWinControl.GetHandle
0076e675 vcl70.bpl Forms.TCustomForm.GetMonitor
0076ecd0 vcl70.bpl Forms.TCustomForm.SetWindowToMonitor
0076daf1 vcl70.bpl Forms.TCustomForm.SetVisible
in SetWindowToMonitor I read that if on computer we have installed more than one monitor sometimes this problem appears. But I tried change DefaultMonitor property and this is not working.
Upvotes: 0
Views: 2283
Reputation: 53436
In addition, is:
Height :=FormMain.panelMain.Height;
Width := FormMain.panelMain.Height;
A typo? Else use
Height :=FormMain.panelMain.Height;
Width := FormMain.panelMain.Width;
Upvotes: 0
Reputation: 1
I probably found solution for my problem. I have Delphi 5 without Update Pack 1.
I do some research and I found that the problem as I said is in Delphi function TCustomForm.GetMonitor
On production computer is installed one real monitor and virtual (Radmin application).
After installing UP1 problem disapears.
I could also change function by myself:
function TCustomForm.GetMonitor: TMonitor;
var
HM: HMonitor;
I: Integer;
begin
Result := nil;
HM := MonitorFromWindow(Handle, MONITOR_DEFAULTTONEAREST);
for I := 0 to Screen.MonitorCount - 1 do
if Screen.Monitors[I].Handle = HM then
begin
Result := Screen.Monitors[I];
Exit;
end;
//if we get here, the Monitors array has changed, so we need to clear and reinitialize it
for i := 0 to Screen.MonitorCount-1 do
TMonitor(Screen.FMonitors[i]).Free;
Screen.FMonitors.Clear;
EnumDisplayMonitors(0, nil, @EnumMonitorsProc, LongInt(Screen.FMonitors));
for I := 0 to Screen.MonitorCount - 1 do
if Screen.Monitors[I].Handle = HM then
begin
Result := Screen.Monitors[I];
Exit;
end;
end;
Thanks for any comments !
Upvotes: 0