Hello. I am a new Lazarus/FreePascal user who moved from FORTRAN to TurboPascal, to C++, and then to REALbasic for it's cross-platform capabilities. I am very impressed with Lazarus/FreePascal and am attempting to migrate several substantial programs. A basic component I need is a virtual TListView, and would very much appreciate some help. I have spent several days searching Delphi and Lazarus forums, but am still flummoxed.
I am using OS X 10.6.5 Intel with Lazarus 0.9.31, and am using the Qt widget set. I believe I have everything installed properly, although I did have some initial problems, so could have made a mistake.
For the TListView I set OwnerData := true and add two TListColumns then try the following code.
var
dataA: array [0..9] of string =
('A0','A1','A2','A3','A4','A5','A6','A7','A8','A9');
dataB: array [0..9] of string =
('B0','B1','B2','B3','B4','B5','B6','B7','B8','B9');
col1: array [0..9] of string;
col2: array [0..9] of string;
procedure TForm1.ListView1Data(Sender: TObject; Item: TListItem);
begin
Item.Caption := col1[Item.Index];
Item.SubItems.Add(col2[Item.Index]);
end;
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
ShowMessage(IntToStr(Item.Index)); // never happens :/
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
for i := 0 to 9 do
begin
col1[i] := dataA[i];
col2[i] := dataB[i];
end;
ListView1.Items.Count := 10;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i: integer;
begin
for i := 0 to 9 do
begin
col1[i] := dataB[i];
col2[i] := dataA[i];
end;
ListView1.Items.Count := 10;
end;
I was unclear if 'Item.SubItems.Add' is the correct way to set the text in column 2, but couldn't figure out any other way to do it. Is there a better way?
Is setting 'Items.Count' the correct way to refresh the list?
The data sets update properly from the 'OnData' event, but the 'OnSelectItem' event never fires. I have tried other events as well ('OnClick', 'OnMouseDown', etc.), but don't get a response.
Can anyone point me in the correct direction?