Solved

How do I free up a self made class correctly?

Posted on 2004-05-01
4
178 Views
Last Modified: 2010-04-05
Ive made a really small class object in a unit (no form)

Type TQICheck = class
  Private
    MessageString: String;

    procedure CheckQValid;
    procedure CheckIValid;
  Public
     constructor Create;
     destructor Destroy; override;
     function QMessageMe: String;
     function IMessageMe: String;
  End;

2 public functions to return me a message string based on calculations within the private procedures.

constructor TQICheck.Create;
begin
  inherited Create;
  MessageString := '';
end;

destructor TQICheck.Destroy;
begin
  inherited Destroy;
end;

From another form when I click a button
procedure TForm_Main.TBB_QMessagesClick(Sender: TObject);
var
  OutputString: string;
  MyMessage: TQICheck;
begin
  MyMessage.Create;
  OutputString := MyMessage.QMessageMe;
  MessageDlg(OutputString, mtInformation, [mbOK], 0);
end;

Everything seems ok to me but obivously Im missing a basic line or something if I want free/destroy it (through the application)
When I shutdown my App I get lots of access violations.
I havent put any other code into the program apart from this.
Can someone tell me what I need to handle this correctly
0
Comment
Question by:mikelittlewood
  • 3
4 Comments
 
LVL 4

Accepted Solution

by:
ceoworks earned 100 total points
ID: 10969216
You forget to assign your created class to the MyMessage.

procedure TForm_Main.TBB_QMessagesClick(Sender: TObject);
var
  OutputString: string;
  MyMessage: TQICheck;
begin
  MyMessage := TQICheck.Create; // not MyMessage.Create;
  OutputString := MyMessage.QMessageMe;
  MessageDlg(OutputString, mtInformation, [mbOK], 0);
end;
0
 
LVL 4

Expert Comment

by:ceoworks
ID: 10969228
You get access violations because you are trying to do something with a non-created class.

Cheers,

Oktay Sancak
0
 
LVL 15

Author Comment

by:mikelittlewood
ID: 10970870
doh!

stupid mistake  :/

thanks
0
 
LVL 4

Expert Comment

by:ceoworks
ID: 10970965
Don't think it's a little mistake..

Have a nice day,

Oktay
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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