Queries information from a Tabsheet related to TListView

2

I'm a beginner and I have a big problem.

I have the following situation:

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

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

No ondblclick of listview :

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

No onChange of PageControl I try to identify 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 from 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!

    
asked by anonymous 10.06.2015 / 18:10

1 answer

0

Do the following:

  • Declare the function below to identify Form2 from 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;
    
  • In the OnDblClick of Listview event, check if any items are 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);
    
  • Modify your SENDTEXT function to look like this:

    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;
    
  • In the event onChange of PageControl , all that code is unnecessary, I think ), you just call 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);
    
  • 10.06.2015 / 22:53