Solved

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

Posted on 2010-08-14
5
395 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 37

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 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

21 Experts available now in Live!

Get 1:1 Help Now