Query information for a Tlistview-related Tabsheet

Asked

Viewed 425 times

2

Well I’m a beginner and I’m in big trouble.

I have the following situation:

I create an item on Tlistview by making two clicks on the selected item I add an object in the form to the item of listview and create a form with parent at the Tabsheet.

In this case what I’m not getting is to relate the Tabsheet to the item when I close the form or delete the item. I was able to do just by adding the handle of Tabsheet to the selected item, I do the loop of handle to identify which tabsheet this related to the item.

In the ondblclick of listview:

LV1.Selected.SubItems[1]:=IntToStr(NewTabSheet.Handle);
LV1.Selected.SubItems.Objects[3] := TObject(NewTabSheet);

In the onChange of PageControl I try to identify the tabsheet:

procedure TForm1.pgc1Change(Sender: TObject);
var
  i, c: integer;
begin
  try
    for i := 0 to lv1.Items.Count -1 do
      if i > 0 then
      begin
        if IntToStr(pgc1.ActivePage.Handle) = Form1.lv1.Items.Item[i].SubItems[1] then
        begin
          lv1.Items.Item[i].Selected:= True;
          Abort;
        end;
      end;
   // ...

Here is when I try to set some item information when I change tabsheet:

procedure TForm1.SENDTEXT(txt:string;NUM:INTEGER);
var
  i,c:integer;
begin
  for i := 0 to Form1.LV1.Items.count - 1 do
  begin
    if form1.lv1.Items[i].SubItems[1] = inttostr(pgc1.ActivePage.Handle) then
    begin
      (form1.lv1.Items[i].SubItems.Objects[2]as TForm2).StatusText.Panels[NUM].Text:=txt;
    end;
  end;
end;

Correct me because I’m getting lost in the code, I think my method is wrong!

1 answer

0


Do the following:

  1. Declare the function below to identify the Form2 from the PageControl:

    function IdentificarFormulario(PageControl: TPageControl): TForm2;
    var
      tab: TTabSheet;
      I: Integer;
    begin
      Result := nil;
      tab := PageControl.ActivePage;
      for I := 0 to tab.ControlCount- 1 do
        if tab.Controls[I] is TForm then
        begin
          Result := TForm2(tab.Controls[I]);
          Break;
        end;
    end;
    
  2. At the event OnDblClick of Listview, check if there are any items selected before assigning information to Listview:

    // Se não houver nada selecionado, o código abaixo não será executado
    if LV1.Selected = nil then exit;
    
    LV1.Selected.SubItems[1] := IntToStr(NewTabSheet.Handle);
    
    // Onde "PGC1" é o componente "PageControl"
    LV1.Selected.SubItems.Objects[3] := IdentificarFormulario(PGC1);
    
  3. Change your job function SENDTEXT to keep it that way:

    procedure SENDTEXT(txt: string; NUM: INTEGER);
    var
      I: integer;
    begin
      for I := 0 to LV1.Items.Count - 1 do
        if (LV1.Items.Item[I] <> nil) and
           (LV1.Items.Item[I].SubItems[1] = IntToStr(pgc1.ActivePage.Handle))
        then
          TForm2(LV1.Items.Item[I].SubItems.Objects[3]).StatusText.Panels[0].Text := txt;
    end;
    
  4. At the event onChange of PageControl, all that code is unnecessary (I think), just call the function SENDTEXT:

    // Onde "texto" é a informação que você quer mostrar no "StatusText" do "Form2"
    // O segundo argumento é índice do "Panel" do "StatusText"
    SENDTEXT('Texto', 0);
    
  • 1

    take longer left kkkk msm thing , vlw flw !!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.