Solved

How do I free up a self made class correctly?

Posted on 2004-05-01
4
173 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

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

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…
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…
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.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

867 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

12 Experts available now in Live!

Get 1:1 Help Now