Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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