Nope that didn't make it work., but thanks for your post.
Does the above code work for anyone else??
Main Topics
Browse All TopicsHi All,
I was fairly good with Delphi programming a few years back, but have maily been doing C++ since then.
Anyway, to cut a long story short, I needed to make a class that will manage a linked list of processes.
My code is as below:
// DATA TYPES //------------------------
type PS_PRIO = (PS_FIRST=0, PS_HIGH, PS_NORM, PS_LOW, PS_LAST);
type PTRProcess = ^process_;
process_ = record
next : PTRProcess;
prev : PTRProcess;
pid : Integer;
p_name : String[30];
priority : PS_PRIO;
life : Integer;
status : Integer;
last_queued : Integer;
io_bursts : Integer;
end;
// CLASSES //------------------------
// ########## CProcessManager ##########
type CProcessManager = class
private
firstssh : boolean;
m_first : PTRProcess;
m_last : PTRProcess;
// protected
public
constructor Create();
destructor Destroy();
function NewProcess() : integer;
function GetFirstProcess() : integer;//PTRProcess
end;
//------------------------
// FUNCTION DEFS //------------------------
function ps_to_str(value : PS_PRIO) : string;
implementation
// ---- CProcessManager function definitions ----
constructor CProcessManager.Create();
begin
end;
destructor CProcessManager.Destroy();
begin
end;
function CProcessManager.GetFirstPr
begin
//Result := firstssh;
exit;
end;
function CProcessManager.NewProcess
var p_process : PTRProcess;
begin
// Make first process
New(p_process);
firstssh := TRUE; <----- error happens here. Note it has nothing to do with the dynamic allocation above.
p_process^.pid := 101;
ShowMessage(inttostr(p_pro
end;
end.
So ignoring the fact that the code does not do anything usefull... Whenever I run the code, I get an exception
when I try and set the value of firstssh. It doesnt matter what type or name I choose for the field variable in the
class, I always get an error:
"Access violation at address 00458514... Write of address 00000004."
Im sure Ive just made some silly mistake.. this would have worked fine in C++.
Some fast help is well appreciated.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
It worked fine for me (even without the inherited usage)
unit Unit2;
interface
uses
Windows, SysUtils, Messages, Forms, Dialogs;
// DATA TYPES //------------------------
type PS_PRIO = (PS_FIRST, PS_HIGH, PS_NORM, PS_LOW, PS_LAST);
type PTRProcess = ^process_;
process_ = record
next : PTRProcess;
prev : PTRProcess;
pid : Integer;
p_name : String[30];
priority : PS_PRIO;
life : Integer;
status : Integer;
last_queued : Integer;
io_bursts : Integer;
end;
// CLASSES //------------------------
// ########## CProcessManager ##########
type CProcessManager = class
private
firstssh : boolean;
m_first : PTRProcess;
m_last : PTRProcess;
// protected
public
constructor Create();
destructor Destroy();
function NewProcess() : integer;
function GetFirstProcess() : integer;//PTRProcess
end;
//------------------------
// FUNCTION DEFS //------------------------
// function ps_to_str(value : PS_PRIO) : string;
implementation
// ---- CProcessManager function definitions ----
constructor CProcessManager.Create();
begin
end;
destructor CProcessManager.Destroy();
begin
end;
function CProcessManager.GetFirstPr
begin
//Result := firstssh;
exit;
end;
function CProcessManager.NewProcess
var p_process : PTRProcess;
begin
// Make first process
New(p_process);
firstssh := TRUE;
p_process^.pid := 101;
ShowMessage(inttostr(p_pro
end;
end.
------------------
var cp: CProcessManager;
begin
cp:=CProcessManager.Create
if cp.NewProcess = 0 then
beep;
end;
Regards,
Russell
Business Accounts
Answer for Membership
by: rllibbyPosted on 2005-04-19 at 09:19:26ID: 13816923
Try the following
constructor CProcessManager.Create();
begin
inherited Create;
end;
destructor CProcessManager.Destroy();
begin
inherited Destroy;
end;
Regards,
Russell