Board index » delphi » StringList assign exception problem

StringList assign exception problem

I am working on a database engine. It's coming along reasonably nicely, but
recently I have been getting some odd exceptions, such as this one:

"Project Sample.exe raised exception class EStringListError with message
'List index out of bounds (1)'. Process stopped. Use Step or Run to
continue."

This occurs during the TStringList.Get method at the first line (the if
statement). The code that I wrote that occurs before this method that causes
the exception follows:

procedure TDataMemo.FieldChanged; // TDataMemo is a descendant of TMemo
begin
  if FFieldLink.CurrentValue <> nil then
    Lines.Assign(FFieldLink.CurrentValue); // The exception occurs during
the call to Lines.Assign
end;

FFieldLink.CurrentValue is a class method that returns a result of TStrings
type. I know for sure that this value isn't nil and that it contains text
(simply by inserting a call to FFieldLink.CurrentValue.SaveToFile before the
if statement).

The following avoids the exception, but I'm not sure why. I could easily
just use this, but I would like to know what is causing the problem.

procedure TDataMemo.FieldChanged; // Called through an event handler by the
engine when the contents of TStrings field is changed.
var
  tmp: TStrings;
begin
  tmp := TStringList.Create;
  if FFieldLink.CurrentValue <> nil then
  begin
    tmp.Assign(FFieldLink.CurrentValue);
    Lines.Assign(tmp);
  end;
  tmp.Free;
end;

Any help would be appreciated.

Crutchy

 

Re:StringList assign exception problem


fyi, this was answered in another group by someone.

Kelly

Quote
"Crutchy" <s2111...@student.rmit.edu.au> wrote in message

news:VY9Q9.13215$jM5.37821@newsfeeds.bigpond.com...
Quote
> I am working on a database engine. It's coming along reasonably nicely,
but
> recently I have been getting some odd exceptions, such as this one:

> "Project Sample.exe raised exception class EStringListError with message
> 'List index out of bounds (1)'. Process stopped. Use Step or Run to
> continue."

> This occurs during the TStringList.Get method at the first line (the if
> statement). The code that I wrote that occurs before this method that
causes
> the exception follows:

> procedure TDataMemo.FieldChanged; // TDataMemo is a descendant of TMemo
> begin
>   if FFieldLink.CurrentValue <> nil then
>     Lines.Assign(FFieldLink.CurrentValue); // The exception occurs during
> the call to Lines.Assign
> end;

> FFieldLink.CurrentValue is a class method that returns a result of
TStrings
> type. I know for sure that this value isn't nil and that it contains text
> (simply by inserting a call to FFieldLink.CurrentValue.SaveToFile before
the
> if statement).

> The following avoids the exception, but I'm not sure why. I could easily
> just use this, but I would like to know what is causing the problem.

> procedure TDataMemo.FieldChanged; // Called through an event handler by
the
> engine when the contents of TStrings field is changed.
> var
>   tmp: TStrings;
> begin
>   tmp := TStringList.Create;
>   if FFieldLink.CurrentValue <> nil then
>   begin
>     tmp.Assign(FFieldLink.CurrentValue);
>     Lines.Assign(tmp);
>   end;
>   tmp.Free;
> end;

> Any help would be appreciated.

> Crutchy

Other Threads