Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

which tab sheet on page control is "active" 3

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
0
0
US
I am having to modify a program that was thrown together by my former boss, he was originally an RPG programmer and doesn't use OOP techniques quite right, so I apologize for the code. I was trying to retool this program with my previous question regarding Quick Reports and while I'm still planning on re-doing the whole thing, I don't have the time right now and have resolved myself to making the existing program work correctly instead of fixing the whole thing.

So, onto the question:

I have a form with a page control. The page control has 6 tabsheets each with a string grid on it. The form has a button that prints all the tabsheets. The users would like it modified to only print the current tabsheet. How can I determine which tabsheet is the one the user is currently on?

here's the {ugly} code currently in the print button:
Code:
procedure TForm_CasesDisposed.BitBtn3Click(Sender: TObject);
begin
  with Form_QRCasesDisposed do
  begin
    // --------------------------------------------------------------------
    // Tab1/Grid1
    // --------------------------------------------------------------------
    Form_QRCasesDisposed.QRLb_CaseType.caption:=TabSheet1.Caption;
    QRStringGrid:=StringGrid1;
    CreateLabels;
    // Print the report
    QuickRep1.Print;
    // Free the labels on the report
    FreeLabels;
    // --------------------------------------------------------------------
    // Tab2/Grid2
    // --------------------------------------------------------------------
    Form_QRCasesDisposed.QRLb_CaseType.caption:=TabSheet2.Caption;
    QRStringGrid:=StringGrid2;
    CreateLabels;
    // Print the report
    QuickRep1.Print;
    // Free the labels on the report
    FreeLabels;
    // --------------------------------------------------------------------
    // Tab3/Grid3
    // --------------------------------------------------------------------
    Form_QRCasesDisposed.QRLb_CaseType.caption:=TabSheet3.Caption;
    QRStringGrid:=StringGrid3;
    CreateLabels;
    // Print the report
    QuickRep1.Print;
    // Free the labels on the report
    FreeLabels;
    // --------------------------------------------------------------------
    // Tab4/Grid4
    // --------------------------------------------------------------------
    Form_QRCasesDisposed.QRLb_CaseType.caption:=TabSheet4.Caption;
    QRStringGrid:=StringGrid4;
    CreateLabels;
    // Print the report
    QuickRep1.Print;
    // Free the labels on the report
    FreeLabels;
    // --------------------------------------------------------------------
    // Tab5/Grid5
    // --------------------------------------------------------------------
    Form_QRCasesDisposed.QRLb_CaseType.caption:=TabSheet5.Caption;
    QRStringGrid:=StringGrid5;
    CreateLabels;
    // Print the report
    QuickRep1.Print;
    // Free the labels on the report
    FreeLabels;
    // --------------------------------------------------------------------
    // Tab6/Grid6
    // --------------------------------------------------------------------
    Form_QRCasesDisposed.QRLb_CaseType.caption:=TabSheet6.Caption;
    QRStringGrid:=StringGrid6;
    CreateLabels;
    // Print the report
    QuickRep1.Print;
    // Free the labels on the report
    FreeLabels;
  end;

end;

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual
 
The ActivePage property of the page control returns the page currently displayed by the page control.

Cheers

Andrew
 
Or if you want to access the active page via an index rather than the object itself use ActivePageIndex in conjunction with the Pages array.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Ok, I haven't gotten to the printing of these pages yet, I'm still trying to fill them all in. Anybody know how I can accomplish the following?

So, I have my PageControl with the 6 tabsheets, each tabsheet with a stringgrid. I am running a single query that returns an indicator of which string grid the data is associated with. Is there a way to include that indicator to declare which string grid I'm currently working on?

Here's what I've got in the FormShow event currently:

Code:
procedure TForm_CasesDisposed.FormShow(Sender: TObject);
var
  i, j, CurrentDivision : Integer;
  Totals : Array [1..7] Of Integer;
begin

  for i:= 1 to 7 do
    Totals[i] := 0;
  I:=0;

  For i := 0 to ComponentCount - 1 do
  begin
    If Components[i] is TStringGrid Then
      with Components[i] as TStringGrid do
      begin
        ColWidths[0]:=86;
        ColWidths[1]:=244;
        ColWidths[2]:=100;
        ColWidths[3]:=100;
        ColWidths[4]:=100;
        ColWidths[5]:=100;
        ColWidths[6]:=100;

        Cells[0,0]:='Division';
        Cells[1,0]:='Judge';
        Cells[2,0]:='Dismissed';
        Cells[3,0]:='Guilty';
        Cells[4,0]:='Not Guilty';
        Cells[5,0]:='Nolle Pros';
        Cells[6,0]:='Total';

      end;
    end;

    i := 0;
[i]{I would like to now loop through the query; if the indicator is 1 then fill stringGrid1 and when the indicator changes in the query, switch to the next indicated grid}[/i]
    with DModule.QuCasesDisposed do
    begin
      First;
      while not eof do
      begin
     [i]//get indicator and switch stringgrid if needed[/i]
      [COLOR=red]with StringGrid(indicator) do[/color]
      begin

        if CurrentDivision <> FieldByName('ASNJUD').AsInteger Then
        begin
          inc(i);

          CurrentDivision := FieldByName('ASNJUD').AsInteger;
          Cells[0, i] := FieldByName('ASNJUD').AsString;
          Cells[1, i] := FieldByName('JUDNAM').AsString;
        end;
        Cells[FieldByName('SORT').AsInteger + 1, i] := FieldBYName('COUNT OF CHGTYP').AsString;
        Totals[FieldByName('SORT').AsInteger] := Totals[FieldByName('SORT').AsInteger] + FieldByName('COUNT OF CHGTYP').AsInteger;
        Next;
      end;
      inc(i);
      Cells[1, i] := 'TOTALS:';
      for j := 1 to 7 do
        Cells[j+1, i] := IntToStr(Totals[j]);
      RowCount := i + 1;
    end;
  end;
end;

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual
 
You could create and populate an array, and then refer to its elements, e.g.

Code:
procedure TForm1.FormShow(Sender: TObject);
var
  i: integer;
  GridArray: array[0..2] of TStringGrid;
begin
  GridArray[0] := StringGrid1;
  GridArray[1] := StringGrid2;
  GridArray[2] := StringGrid3;

  for i := 0 to 2 do
    GridArray[i].Cells[1,1] := 'Test '+IntToStr(i);
end;

or you could write a simple function to return a component based on its name. This is a illustrative example, your actual should include type checking and error handling etc but you get the idea...

Code:
function TForm1.ComponentByName(aName: string): TComponent;
var
  i: integer;
begin
  Result := nil;
  for i := 0 to ComponentCount-1 do
    if Components[i].Name = aName then
    begin
      Result := Components[i];
      break;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
begin
  for i := 1 to 3 do
    with TStringGrid(ComponentByName('StringGrid'+IntToStr(i))) do
      Cells[2,1] := 'Test '+IntToStr(i);
end;
[/code

Steve
 
thanks for the tips Steve, I'll give them a go!

leslie
 
the ComponentByName function works like a charm!! Wish I could give you another star!

Thanks for the help.

Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top