Solved

What is wrong with my code ?

Posted on 2004-10-08
10
236 Views
Last Modified: 2012-05-05
I write a vcl that use own editor.
I load into package next code and install it. All is perfect. I reCompile how many I wish. All is perfect.

I drop a mine vcl to a form. If I wish I can recompile the package and all is OK.

The problem come from here :

I double click on my vcl and open my editor. OK . Close it. OK. But if I try to recompile the vcl get an rtl60.dpk error message.

OR ... drop my vcl.. double click to open my editor...close my editor.. try to close my Delphi ... get an error message as my Delphi can read some memory address.

The code is next ( a sample code not my real code from vcl but get some errors )/

COMPONENT CODE:

unit Test;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, DesignIntf, DesignEditors;

type
  TTest = class(TCustomControl)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
  published
    { Published declarations }
  end;

  type
  TgnEditor = class(TComponentEditor)
    procedure ExecuteVerb(Index: Integer); override;
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
  end;

procedure Register;

implementation

uses editor;

// 8<-------- TgnEditor -------->8 \\

procedure TgnEditor.ExecuteVerb(Index: Integer);
begin
  case Index of
    0: ShowEditor(TTest(Component));
  end;
end;

function TgnEditor.GetVerb(Index: Integer): string;
begin
  case Index of
    0: Result := 'Edit...';
  end;
end;

function TgnEditor.GetVerbCount: Integer;
begin
  Result := 1;
end;


procedure Register;
begin
  RegisterComponents('Samples', [TTest]);
  RegisterComponentEditor(TTest, TgnEditor);
end;

end.
0
Comment
Question by:ginsonic
  • 6
  • 3
10 Comments
 
LVL 9

Author Comment

by:ginsonic
ID: 12261070
EDITOR CODE:

unit editor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, dialogs,
  test;

  procedure ShowEditor(FTest: TTest);

type
  TEdits = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Edits: TEdits;

implementation

{$R *.dfm}

procedure ShowEditor(FTest: TTest);
var FForm: TEdits;
begin;
  FForm := TEdits.Create(nil);
  FForm.Caption := Format(' %s Editor', [FTest.Name]);
  FForm.Show;
end;

end.
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 12262893
one thing I can see right away is this:

procedure ShowEditor(FTest: TTest);
var FForm: TEdits;
begin;
  FForm := TEdits.Create(nil);
  FForm.Caption := Format(' %s Editor', [FTest.Name]);
  FForm.Show;

  FForm.Free //add this line!!!
end;

you need to free that variable there, else is a memory leak problem
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12262997
My editor can be close just if click on close button from title bar ( the X one ). I think that is enough to free the form editor.

Somebody else get same problems when use the code ?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 9

Author Comment

by:ginsonic
ID: 12263029
In same time I'm sure that isn't a FForm.Free problem. How you can see is a blank form so not much memmory used.

I tested with FForm opened ( to see if is a destroy problem ) to recompile my package. Same rtl60.dpk error.
0
 
LVL 13

Accepted Solution

by:
BlackTigerX earned 500 total points
ID: 12263424
unless you have caFree in the Action of the OnClose event, the form is not freed automatically
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12265189
If I use a ShowModal all work perfect. The problem to bee the free of form !?!?
BlackTigerX can you tell me more about how to use an action to free ?
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12265237
procedure ShowEditor(FTest: TTest);
var FForm: TEdits;
begin;
  FForm := TEdits.Create(nil);
  try
    FForm.Caption := Format(' %s Editor', [FTest.Name]);
    FForm.ShowModal;
  finally
//    FForm.Release; // if is TForm
    FForm.Free;
  end;
end;
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12265252
Don't wish to use a modal form. The BlackTigerX comment is the solution to my problem. Thanks to all for support!
See you on net :)
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 12267306
please disregard this (my own) comment:

FForm.Show;

  FForm.Free //add this line!!!

(duh... the form would be shown and immediatly be gone)...
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12269260
Ni problem :) The answer was the caFree action on close. Thanks again !
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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