Solved

What is wrong with my code ?

Posted on 2004-10-08
10
235 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

18 Experts available now in Live!

Get 1:1 Help Now