Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-07

TStringList error

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bob K.
I'm getting the error: unit1.pas(48,3) Warning: Local variable "List" does not seem to be initialized

Here's the code (which used to work):

unit Unit1;
{$mode objfpc}{$H+}
interface

uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,

  ZConnection, ZDataset, db, DBGrids, DbCtrls, SdfData, StdCtrls;
type
  { TForm1 }
  TForm1 = class(TForm)
    Datasource1: TDatasource;
    Datasource2: TDatasource;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    ZConnection1: TZConnection;
    ZTable1: TZTable;
    ZTable2: TZTable;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;
var
  Form1: TForm1;
implementation

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var
  List: TStringList;
begin
  ZConnection1.Connected:=True;
  ZTable1.Active:=True;
  ZTable2.Active:=True;
  list.Add('here');
 {
  while not ZTable2.EOF do
    begin
      List.Add(ZTable2.FieldByName('MAKE').AsString);
      ZTable2.Next;
    end; //while
 }
    //showmessage(list.Strings[0]);
 //  DBGrid1.Columns[0].PickList:=List;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  end;
initialization
  {$I unit1.lrs}
end.

What has happened?

bob k.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080721/3a133a73/attachment.html

Reply by email

Cesar Romero
to Bob K.

This is not a error, as you can see is a warning.
The erros that you are not creating a instance of TStringList. Before use list you should create the object.

List:= TStringList.Create;
try
  // your code here
finally
  List.Free;
end;
Bob K. wrote 85 lines
I'm getting the error: *unit1.pas(48,3) Warning: Local variable "List" does not seem to be initialized* Here's the code (which used to work): unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ZConnection, ZDataset, db, DBGrids, DbCtrls, SdfData, StdCtrls; type { TForm1 } TForm1 = class(TForm) Datasource1: TDatasource; Datasource2: TDatasource; DBGrid1: TDBGrid; DBNavigator1: TDBNavigator; ZConnection1: TZConnection; ZTable1: TZTable; ZTable2: TZTable; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; implementation { TForm1 } procedure TForm1.FormCreate(Sender: TObject); *var List: TStringList*; begin ZConnection1.Connected:=True; ZTable1.Active:=True; ZTable2.Active:=True; * list.Add('here');* { while not ZTable2.EOF do begin List.Add(ZTable2.FieldByName('MAKE').AsString); ZTable2.Next; end; //while } //showmessage(list.Strings[0]); // DBGrid1.Columns[0].PickList:=List; end; procedure TForm1.Button1Click(Sender: TObject); begin end; initialization {$I unit1.lrs} end. What has happened? bob k. ------------------------------------------------------------------------ _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Vincent Snijders
to Bob K.: I'm getting the error: unit1.pas(48,3) Warning: Local variable "List" does not seem to be…
Bob K. wrote
I'm getting the error: *unit1.pas(48,3) Warning: Local variable "List" does not seem to be initialized* Here's the code (which used to work):

Then you were unbelievable lucky.

list := TStringList.Create is missing.

If it used to work, then you the uninitialized variable list was pointing to a memory location in the heap, contained valid (or at least non-crash causing) information and updating that upformation, e.g. the count value of the list didn't cause a crash. Extremely lucky.

Next time, try adding the -gt option, to decrease your chances on such luck and get a crash sooner rather than later.

Vincent

Reply by email

Bob K.
to Cesar Romero: This is not a error, as you can see is a warning. The erros that you are not creating a…

Thank worked. Thank you Cesar.

bob k.

--------------------------------------------------

Earlier message 115 lines
From: "Cesar Romero" Sent: Monday, July 21, 2008 10:02 AM To: "General mailing list" Subject: Re: [Lazarus] TStringList error > This is not a error, as you can see is a warning. > The erros that you are not creating a instance of TStringList. > Before use list you should create the object. > > > List:= TStringList.Create; > try > // your code here > > finally > List.Free; > end; > > Bob K. escreveu: >> I'm getting the error: *unit1.pas(48,3) Warning: Local variable "List" >> does not seem to be initialized* >> >> Here's the code (which used to work): >> >> unit Unit1; >> >> {$mode objfpc}{$H+} >> >> interface >> >> uses >> Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, >> ZConnection, ZDataset, db, DBGrids, DbCtrls, SdfData, StdCtrls; >> >> type >> >> { TForm1 } >> >> TForm1 = class(TForm) >> Datasource1: TDatasource; >> Datasource2: TDatasource; >> DBGrid1: TDBGrid; >> DBNavigator1: TDBNavigator; >> ZConnection1: TZConnection; >> ZTable1: TZTable; >> ZTable2: TZTable; >> procedure Button1Click(Sender: TObject); >> procedure FormCreate(Sender: TObject); >> private >> { private declarations } >> public >> { public declarations } >> end; >> >> var >> Form1: TForm1; >> >> implementation >> >> { TForm1 } >> >> procedure TForm1.FormCreate(Sender: TObject); >> *var >> List: TStringList*; >> begin >> >> ZConnection1.Connected:=True; >> >> ZTable1.Active:=True; >> ZTable2.Active:=True; >> >> * list.Add('here');* >> { >> while not ZTable2.EOF do >> begin >> List.Add(ZTable2.FieldByName('MAKE').AsString); >> ZTable2.Next; >> end; //while >> } >> //showmessage(list.Strings[0]); >> // DBGrid1.Columns[0].PickList:=List; >> >> end; >> >> procedure TForm1.Button1Click(Sender: TObject); >> begin >> end; >> >> initialization >> {$I unit1.lrs} >> end. >> >> What has happened? >> >> bob k. >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Lazarus mailing list >> >> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus >> > > > -- > Cesar Romero > http://blogs.liws.com.br/cesar > http://blogs.liws.com.br/cesar/?feed= > > _______________________________________________ > Lazarus mailing list > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Bob K.
to Vincent Snijders: Then you were unbelievable lucky. list := TStringList.Create is missing. If it used to…

Thank you Vincent.

--------------------------------------------------

Earlier message 32 lines
From: "Vincent Snijders" Sent: Monday, July 21, 2008 10:22 AM To: "General mailing list" Subject: Re: [Lazarus] TStringList error > Bob K. schreef: >> I'm getting the error: *unit1.pas(48,3) Warning: Local variable "List" >> does not seem to be initialized* >> >> Here's the code (which used to work): > > Then you were unbelievable lucky. > > list := TStringList.Create is missing. > > If it used to work, then you the uninitialized variable list was pointing > to a > memory location in the heap, contained valid (or at least non-crash > causing) > information and updating that upformation, e.g. the count value of the > list didn't > cause a crash. Extremely lucky. > > Next time, try adding the -gt option, to decrease your chances on such > luck and get > a crash sooner rather than later. > > Vincent > _______________________________________________ > Lazarus mailing list > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email