?
Solved

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

Posted on 2010-08-14
5
Medium Priority
?
402 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 1000 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 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 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