Solved

What is wrong with my code ?

Posted on 2004-10-08
10
234 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 9

Author Comment

by:ginsonic
Comment Utility
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
Comment Utility
unless you have caFree in the Action of the OnClose event, the form is not freed automatically
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Author Comment

by:ginsonic
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ni problem :) The answer was the caFree action on close. Thanks again !
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now