Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-08-14
5
Medium Priority
?
401 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
[X]
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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

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…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 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