Here is my code:
unit ListSelectionEntry;
interface
uses ComCtrls, Classes;
type
TListSelectionEntry = class
private
RichEdit1 : TRichEdit;
ComboBox1 : TComboBoxEx;
protected
public
constructor Create(length, relativeTop, relativeLeft : Integer;
mainForm : TComponent);
published
end;
implementation
constructor TListSelectionEntry.Create(length, relativeTop,
relativeLeft : Integer; mainForm : TComponent);
begin
if RichEdit1 = nil then // Exception comes here
begin
end;
RichEdit1 := TRichEdit.Create(nil); // Exception comes here too
with RichEdit1 do begin
//Parent := currentForm;
Top := relativeTop;
Left := 304;
Height := 20;
Width := 473;
end;
ComboBox1 := TComboBoxEx.Create(nil); // Exception also comes here
with ComboBox1 do begin
//Parent := TwinControl(currentForm);
Top := relativeTop;
Left := 160;
Height := 20;
Width := 145;
end;
end;
end.
Error Message:
Project xxxx raised exception class EAccessViolation with message
'Access violation at address 0049E617 in module '<My project's .exe>'.
Read of address 00000004' Process stopped. Use Step or Run to
continue.
I apologize for the sloppy parts of my code. I performed a bunch of
tests, so a lot of it is rearranged.
From what I can determine, it doesn't know that the pointers exist,
so, When I try to work with them, it gives me the exception. However,
I don't know why that would be.
Thank you for all that help in advance.
> Error Message:
>
> Project xxxx raised exception class EAccessViolation with message
> 'Access violation at address 0049E617 in module '<My project's .exe>'.
> Read of address 00000004' Process stopped. Use Step or Run to
> continue.
C'est strange! The code doesn't give me any exception (and why would it?).
You must be thinking of C++. By the time any code in the constructor is
running, the entire class already exists with all fields initialized to
all-bits-zero. Also notice that his TListSelectionEntry class descends
directly from TObject: the inherited constructor is an empty method, so
it would make no difference to this problem.
--
Rob
You're creating your TListSelectionEntry object like the following,
aren't you?
var
entry: TListSelectionEntry;
begin
entry.Create(length, relativeTop, relativeLeft, mainForm);
end;
That can lead to the problems you're seeing. Create it like this
instead, just like you create the controls in your class's constructor.
entry := TListSelectionEntry.Create(...);
--
Rob
ListSelectionEntry.Create(20, 20, 20, Self);
instead of
Testing := ListSelectionEntry.Create(20, 20, 20, Self);
Thanks for pointing out this simple, simple mistake :).
Rob Kennedy <rken...@example.com> wrote in message news:<virp81o...@corp.supernews.com>...
>constructor TListSelectionEntry.Create(length, relativeTop,
> relativeLeft : Integer; mainForm : TComponent);
>begin
> if RichEdit1 = nil then // Exception comes here
RichEdit1 will always be nil here as a result of object initiation by Delphi.
> begin
> end;
> RichEdit1 := TRichEdit.Create(nil); // Exception comes here too
> with RichEdit1 do begin
> //Parent := currentForm;
> Top := relativeTop;
> Left := 304;
> Height := 20;
> Width := 473;
>
SetBounds(304, RelativeTop, 473, 20); // saves a few lines of code
Alan Lloyd
alang...@aol.com
I tried looking at the help files, but the definiton for TObject doesn't
specify if the constructor returns anything, when i'm convinced it does :S.
I know the problems been solved now, but I thought you might of liked
some insight into why :)
Psyqwix ):0) "Gluttony is an emotional escape, a signal that something
is eating us" - Peter de Vries
From the topic "Constructors":
<<
To create an object, call the constructor method in a class type. For
example,
MyObject := TMyClass.Create;
... the constructor returns a reference to the newly allocated and
initialized object. The type of the returned value is the same as the
class type specified in the constructor call.
>>
And later on:
<<
When a constructor is called using an object reference (rather than a
class reference), it does not create an object or return a value.
Instead, the constructor operates on the specified object, executing
only the statements in the constructor’s implementation.
>>
--
Rob
Rob Kennedy wrote:
> Psyqwix wrote:
>
>> I tried looking at the help files, but the definiton for TObject
>> doesn't specify if the constructor returns anything, when i'm
>> convinced it does :S.
>
>
> From the topic "Constructors":
>
> <<
> To create an object, call the constructor method in a class type. For
> example,
>
> MyObject := TMyClass.Create;
>
> .... the constructor returns a reference to the newly allocated and