Solved

Having problem when compiling a Frame with a form on it.

Posted on 2010-08-14
5
394 Views
Last Modified: 2012-06-27
Hi,

I'm on a Win XP Pro SP4 box using Delphi 7.

I'm trying to get a clean compile of the Frame program.  There are two Units.

Unit1 - Defined as a Frame.  See "Top Of Frame Program(Unit1)"  in the code section.  
Unit2 - Defined as a form that is launched/hidden by a PopUpMenu.  I added the form after programming the Frame.

See the image below.  There are two images stacked vertically.  A red line divides the two images:
1. Top image - right click on the image, in this case an Invoice, select "Show" on PopUpMenu, release right mouse button and the "Flying Magnifier" appears.  Hold Left Mouse button to drag magnifier over invoice image.
2.  Bottom Image  is the error message.

The program dies here:

if Frame1.IM1.Picture = '' then frmMagnify.Close;  <<== EAccessViolation here.

When I "hover" the mouse over each element of Frame1.IM1.Picture, the following messages appear:
1. Frame1 - nil.
2. IM1 - unreachable.
3. Picture - unreachable.

I don't understand how to reference properties of the image ActiveX control (IM1)  on the Frame Unit from the Flying Magnifier which is a Form Unit I added later?

If I comment out that line, then it dies on the next line: dRatio := Frame1.IM1.Width / Frame1.IM1.ScaleWidth; with same error message.

Thanks.





Top Of Frame Program(Unit1).

============================

unit uF1ImageDisplay;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms.....

type

  TFrame1 = class(TFrame)



Getting error in this code.

===========================

procedure SizeIMM();

begin

  if Frame1.IM1.Picture = '' then frmMagnify.Close;  <<== EAccessViolation here.



  dRatio := Frame1.IM1.Width / Frame1.IM1.ScaleWidth;

  frmMagnify.IMM.Width  := cx * dRAtio  - 10;

  frmMagnify.IMM.Height := cy * dRatio  - 10;

end;

Open in new window

Frame.jpg
0
Comment
Question by:IT79637
5 Comments
 
LVL 3

Accepted Solution

by:
piba earned 250 total points
ID: 33438520
The main problem is that the Frame1 variable you are using is "nil" that means that it is does not reference an object in memory, and accessing properties of NO object will always cause access violations..

Probably there are more then one variables called "Frame1" I think you need to change that to "frmMagnify.Frame1IM1.xxx"

If i understand correctly the class TFrame1 contains the image IM1. That frame is also used on a form so you could move the "procedure SizeIMM();" into the TFrame type and use the following code

then from the form you should be able to use (for example)

procedure TfrmMagnify.ButtonPressed(Sender:TObject);
Begin
  Frame1.SizeIMM();
End;

procedure TFrame.SizeIMM();
begin
  if IM1.Picture = '' then frmMagnify.Close;

  dRatio := IM1.Width / IM1.ScaleWidth;
  frmMagnify.IMM.Width  := cx * dRAtio  - 10;
  frmMagnify.IMM.Height := cy * dRatio  - 10;
end;

is this does not help could you explain a bit more about the structure of the frame in relation to the form and how one calls the other?
0
 
LVL 8

Expert Comment

by:BdLm
ID: 33439702
downlaod a debugging tool like madshi  (my favorite)  or fastMM4  (free)  or Eurekalog,  you while see the line creating your AV
0
 
LVL 36

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 250 total points
ID: 33440459
you are using a standalone procedure
and assuming the frame to have name = Frame1
you are also assuming the form is named frmMagnify
and are also assuming the form and frame are initialised

>> don't assume anything, but pass and check the necessary variables to work with

procedure TfrmMagnify.ButtonPressed(Sender:TObject);
begin
  SizeImm(Imm, Frame1.Im1);
end;

procedure SizeIMM(FormImage, FrameImage: TImage);
begin
  if Assigned(FormImage) and Assigned(FrameImage) then 
  begin
    if FrameImage.Picture = '' then 
    begin
      // Are you sure you need to do this here ???
      // explain what you are trying to do, why close the form ???
      // here i am assuming the owner of the image is the form ;-)
      SendMessage(TForm(FormImage.Owner).Handle, WM_Close, 0, 0);
    end
      else 
    begin
      dRatio := FrameImage.Width / FrameImage.ScaleWidth;
      FormImage.Width  := cx * dRAtio  - 10;
      FormImage.Height := cy * dRatio  - 10;
    end;
  end;
end;

Open in new window

0
 
LVL 1

Author Comment

by:IT79637
ID: 33550604
I'm not a professional by trade.  I have done some programming, but the vast majority of my work life has been writing all kinds of specifications.  Consequently, I decided to do the reprogramming from scratch.  I'm just going to have to experiment with it until I get it correct!

0
 
LVL 1

Author Closing Comment

by:IT79637
ID: 33550612
"Was the solution easy to follow?"  That's my issue.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now