Hi 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
ocess() : integer;
begin
//Result := firstssh;
exit;
end;
function CProcessManager.NewProcess
() : integer;
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
cess^.pid)
);
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.