I have a TStringList variable in a unit in the private section of a form
class. I want to add some strings to it in the OnCreate event of the form,
but it generates an access violation. The unit compiles without any errors
or hints. What am I doing wrong? I'm using Delphi 5 Pro.
type
TFormMain = class (TForm);
...
private
FieldTypeList: TStringList
...
procedure TFormMain.FormCreate(Sender: TObject);
begin
FieldTypeList.Add ('test');
end;
Thanks
Peter
procedure TFormMain.FormCreate(Sender: TObject);
begin
FieldTypeList := TStringList.Create;
FieldTypeList.Add ('test');
end;
and in the OnDestroy method
procedure TFormMain.FormDestroy(sender: TObject);
begin
FieldTypeList.Free;
end;
Domingo García
In article <81tf0d$sr...@forums.borland.com>,
Sent via Deja.com http://www.deja.com/
Before you buy.
>Hi
>
>I have a TStringList variable in a unit in the private section of a form
>class. I want to add some strings to it in the OnCreate event of the form,
>but it generates an access violation.
You did not create the TStringList object.
>procedure TFormMain.FormCreate(Sender: TObject);
>begin
FieldTypeList := TStringList.Create;
> FieldTypeList.Add ('test');
>end;
you can free the object in the OnDestroy event.
---
Yorai Aminov (TeamB)
http://ourworld.compuserve.com/homepages/yaminov
(TeamB cannot answer questions received via email.
To contact me for any other reason remove nospam from my address)
[AccessViolation]
>type
> TFormMain = class (TForm);
> ...
> private
> FieldTypeList: TStringList
>....
>procedure TFormMain.FormCreate(Sender: TObject);
>begin
FieldTypeList:=TStringList.Create;
try
> FieldTypeList.Add ('test');
finally
FieldTypeList.Free
end;
>end;
So long,
Stephan R.
--
I'm searching for a good signature ...
>
> Peter
Because of Delphi's object referencing model, it is necessary to CREATE
an object (not just declare it) before using it. This might seem like a
pain at first but it allows for tremendous flexibility later when
referencing objects.
- Chad
Peter
Yorai Aminov (TeamB) <yam...@nospam.trendline.co.il> wrote in message
news:iEtCOHE3=O2EecYjd0...@4ax.com...
> On Mon, 29 Nov 1999 11:08:24 +0200, "Peter Jukel"
> <pju...@jukesoft.com> wrote:
>
> >Hi
> >
> >I have a TStringList variable in a unit in the private section of a form
> >class. I want to add some strings to it in the OnCreate event of the
form,
> >but it generates an access violation.
>
> You did not create the TStringList object.
>
> >procedure TFormMain.FormCreate(Sender: TObject);
> >begin