Solved

How do I free up a self made class correctly?

Posted on 2004-05-01
4
172 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
Comment Utility
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
Comment Utility
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
Comment Utility
doh!

stupid mistake  :/

thanks
0
 
LVL 4

Expert Comment

by:ceoworks
Comment Utility
Don't think it's a little mistake..

Have a nice day,

Oktay
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

11 Experts available now in Live!

Get 1:1 Help Now