Solved

How do I free up a self made class correctly?

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 128
Delphi: ForceDirectory plain function 7 34
Base1 Encode/Decode 3 77
Graphics32 under Delphi 10.1 Berlin 2 68
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 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