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

x
?
Solved

Program ran out of memory!

Posted on 2003-11-28
1
Medium Priority
?
354 Views
Last Modified: 2010-04-05
Hi Experts,

I really can't figure this out but what my program does is have a picture, and when you drage your mouse over it, it masks it with a color. When i drag it over the form and picture a lot of times, I get a "not enough memory to complete" task error. Please help.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, ExtCtrls, jpeg;

type
  TForm1 = class(TForm)
    Image1: TImage;
    SpeedButton1: TSpeedButton;
    ColorDialog1: TColorDialog;
    SaveDialog1: TSaveDialog;
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure SpeedButton1Click(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1; //The Form lol
  OrginalPic : TImage; //Orginal Picture
  MyPicState : Boolean; //true are false varible
implementation
{$R *.dfm}


procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
Pic : TBitmap;//Bitmap
AForm : Word;//A Unsigned 4 byte number
damn : Thandle;//handle
blah : HPALETTE;
begin
Pic := TBitmap.Create; //making a pic a bitmap
Pic.Assign(Image1.Picture.Graphic); //assign the image to pic
Pic.SaveToClipboardFormat(AForm,damn,blah);//save the bitmap in a clipboard
Pic.Free;//freeing the pic from memory
Image1.Picture.LoadFromClipboardFormat(AForm,damn,blah);//load the pic saved to the clippedbaord
Image1.Canvas.Pen.Mode := pmMask;//puts the translucent color over the image
Image1.Canvas.Brush.Color := ColorDialog1.Color;//Set the brush color to to color dialog color
Image1.canvas.Rectangle(0,0,Image1.Width,Image1.Height);//Paint over the whole image
MyPicState := False; //if the mouse is already over it make it stop loading over and over to save memory
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
ColorDialog1.Color := $00FF00;//Color Green In hex just like the rgb function
MyPicState := True;//Set Pic State To True
OrginalPic := TImage.Create(self); //Make the orginalpic
OrginalPic.Picture := Image1.Picture; //save the orginal pic thats from startup
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
OrginalPic.Free; //when the programs done free the orginalpic
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if MyPicState = False then
begin
Image1.Picture := OrginalPic.Picture; //if the mouse is over the form the pic is back to normal
MyPicState := True; //MyPicState is true so when you put the mouse over the pic it will highlight
end;
end;
0
Comment
Question by:ionet
[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
1 Comment
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 480 total points
ID: 9841847
Hello

  Use Clipboard object to save the image to and from it, it will remove the error, here's the modified code

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
Pic : TBitmap;//Bitmap
AForm : Word;//A Unsigned 4 byte number
damn : Thandle;//handle
blah : HPALETTE;
C : TClipBoard;
begin
C := TClipBoard.Create;
Pic := TBitmap.Create; //making a pic a bitmap
Pic.Assign(Image1.Picture.Graphic); //assign the image to pic
//Pic.SaveToClipboardFormat(AForm,damn,blah);//save the bitmap in a clipboard
C.Assign(Pic);
Pic.Free;//freeing the pic from memory

//Image1.Picture.LoadFromClipboardFormat(AForm,damn,blah);//load the pic saved to the clippedbaord
Image1.Picture.Assign(C);
Image1.Canvas.Pen.Mode := pmMask;//puts the translucent color over the image
Image1.Canvas.Brush.Color := ColorDialog1.Color;//Set the brush color to to color dialog color
Image1.canvas.Rectangle(0,0,Image1.Width,Image1.Height);//Paint over the whole image
MyPicState := False; //if the mouse is already over it make it stop loading over and over to save memory
C.Free;

end;

by the way, why you are copy to and from clipboard, you can avoid these steps
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

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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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