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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing different dbgrids with one procedure?

Status
Not open for further replies.

niclas73

Programmer
Sep 19, 2005
7
SE
Hi
i have a procedure to print dbgrids call it like this:
//-------------------------------------
DBGridPrint(DBGSearch,'Search result');

procedure TForm1.DBGridPrint(DBGrid: TDBGrid; Title: string);

How can i use this procedure for any dbgrid in my form?
I´ve try this:
DBGridPrint(TForm1.ActiveControl.Name, 'Search result');

but it dont work!!

//niclas
 
You need to pass the grid, not the form.

DBGridPrint(MyForm.Whatever_Name_The_Grid_Have, "The Title").

Furthermore you are passing the form type (TForm1), not the variable containing the form.

Check the thread at just today another user asked quite the same question.

Please, next time tell us what error you are getting. Things like "it dont work" dont help too much when figuring what is wrong.

buho (A).
 
Hi again
Maby I explain my problem bad.

I have several dbgrids in my form, I want to use one button to print some of them.
I check the activeControl like this:

if (ActiveControl is TDBGrid) then
DBGridPrint(*The name of the active DBgrid*,'Search result');

procedure TForm1.DBGridPrint(DBGrid: TDBGrid; Title: string);

Thanks

/niclas
 
If DBPrintGrid is defined as

procedure TForm1.DBPrintGrid(Grid : TDBGrid; Title : String);

you cant use the grid name, you need to use the grid itself:

if (ActiveControl is TDBGrid)
then DBGridPrint((ActiveControl as TDBGrid), 'Text');

or

if (ActiveControl is TDBGrid)
then DBGridPrint(TDBGrid(ActiveControl), 'Text');

buho (A).


 
Thanks buho
That was just wat I looking for, I cast a vote for you as TipMaster.. :)

/niclas
 
you cant use the grid name, you need to use the grid itself
Not actually true.

You could code
Code:
if ActiveControl.Name = XYZGrid.Name then
...
although it would be less efficient. This may or may not matter.

Andrew
Hampshire, UK
 
>>> niclas:
procedure TForm1.DBGridPrint(DBGrid: TDBGrid; Title: string);
DBGridPrint(TForm1.ActiveControl.Name, 'Search result');
<<<

>> buho:
If DBPrintGrid is defined as
procedure TForm1.DBPrintGrid(Grid : TDBGrid; Title : String);
you cant use the grid name, you need to use the grid itself:
<<

> towerbase
Not actually true.
You could code
if ActiveControl.Name = XYZGrid.Name then
<

Of course it is true! He can't use the grid name to call DBPrintGrid. The phrase you are quoting is not related to the "if" line (where the grid name is not the answer anyway, see below).

>>> niclas:
I have several dbgrids in my form, I want to use one button to print some of them.
<<<

And he can't check by name either, as he is not checking against a specific grid but against any grid.

buho (A).
 
> niclas:
That was just wat I looking for, I cast a vote for you as TipMaster.. :)
<

Plase, no.

It was my pleasure to help you, and feel yourself free to ask any other thing you need; but this issue is too basic to deserve a vote for tip master.

Thanks a lot anyway.

buho (A).
 
buho, just for future reference you can use the following syntax to quote someone:
[ignore]
Stretchwickster said:
blah, blah, blah
[/ignore]

and the result would look like this (if you have "Process TGML" ticked):
Stretchwickster said:
blah, blah, blah
Please don't take this as a criticism I'm just trying to make you aware of a useful feature which aids readability of posts.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"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
 
You're welcome!

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top