Discussion:
component already exists... bug ?
(too old to reply)
viana
2005-05-09 20:47:10 UTC
Permalink
hello,
i always use a code like this to print using Quickreport

try
application.createform(tquickep1,quickrep1);
quickrep1.print;
finally
quickrep1.free;
end;

even with this try..finally, i get the error 'a component named quickrep1 already exists' eventually when i try to print the same report again. the only way to workaround is closing app and starting it again.

is this a QR bug ?

thanks,
viana
Crazy Horse's crazier little brother
2005-05-09 21:13:55 UTC
Permalink
Post by viana
i always use a code like this to print using Quickreport
try
application.createform(tquickep1,quickrep1);
quickrep1.print;
finally
quickrep1.free;
end;
even with this try..finally, i get the error 'a component named quickrep1
already exists' eventually when i try to print the same report again. the
only way to workaround is closing app and starting it again.
AFAIK, the ".dpr-style" creation of forms is not safe, or "the preferred
method" (outside of the .dpr).

Also, it looks like you have both a form and a component named "Quickrep1"
(you're creating a form named quickrep1, and then calling quickrep1's print
method, which I assume is the print method of a TQuickRep component, not the
Print method of the form).

Why not use something like this:

Tfrankenstein = class(TForm)
. . .
public
class procedure Cre8Yourself;
end;

class procedure Tfrankenstein.Cre8Yourself;
begin
with Self.Create(nil) do
try
ShowModal;
finally
Free;
end;
end;

and you call it like so:

Tfrankenstein.Cre8Yourself

In Tfrankenstein's OnShow() event (or some other), you can then call:

QuickRep1.Print;
--
Download Blackbird Crow Raven's book
"STILL CASTING SHADOWS: Two American Families 1620-2006"
(.exe and Delphi source): http://cc.borland.com/ccweb.exe/listing?id=23106
viana
2005-05-10 16:42:34 UTC
Permalink
hello,

thank you for you reply !

i don't use the Tquickrep inside the form ; i just use a TQuickrep. I just use the application.creatform in order to
create the report in memory.

is there an better way ?

thanks
Post by Crazy Horse's crazier little brother
Post by viana
i always use a code like this to print using Quickreport
try
application.createform(tquickep1,quickrep1);
quickrep1.print;
finally
quickrep1.free;
end;
even with this try..finally, i get the error 'a component named quickrep1
already exists' eventually when i try to print the same report again. the
only way to workaround is closing app and starting it again.
AFAIK, the ".dpr-style" creation of forms is not safe, or "the preferred
method" (outside of the .dpr).
Also, it looks like you have both a form and a component named "Quickrep1"
(you're creating a form named quickrep1, and then calling quickrep1's print
method, which I assume is the print method of a TQuickRep component, not the
Print method of the form).
Tfrankenstein = class(TForm)
. . .
public
class procedure Cre8Yourself;
end;
class procedure Tfrankenstein.Cre8Yourself;
begin
with Self.Create(nil) do
try
ShowModal;
finally
Free;
end;
end;
Tfrankenstein.Cre8Yourself
QuickRep1.Print;
--
Download Blackbird Crow Raven's book
"STILL CASTING SHADOWS: Two American Families 1620-2006"
(.exe and Delphi source): http://cc.borland.com/ccweb.exe/listing?id=23106
Crazy Horse's crazier little brother
2005-05-10 17:13:00 UTC
Permalink
Post by viana
i don't use the Tquickrep inside the form ; i just use a TQuickrep. I just
use the application.creatform in order to
create the report in memory.
is there an better way ?
Maybe I'm confused, but it looks to me like you're trying to create the
TQuickRep component as if it's a form.

Your code:

application.createform(tquickep1,quickrep1);

is saying "create a form named quickrep1 of the class type tquickrep1."

If you want to create a component dynamically, you would do it like this:

var
QuackRap: TQuickRep;
begin
QuackRap := TQuickRep.Create(nil);
try
{ do something - make those ducks hip hop }
finally
QuackRap.Free;
end;
end;

or am I confused as to what your intentions are?

Maybe it would be best to post your code here, so we can see exactly what
you're trying to do.
--
Download Blackbird Crow Raven's book
"STILL CASTING SHADOWS: Two American Families 1620-2006"
(.exe and Delphi source): http://cc.borland.com/ccweb.exe/listing?id=23106
viana
2005-05-11 13:39:59 UTC
Permalink
hi,

i already have a report named Quickrep1. the report is
already designed, with all bands, labels etc.

i just use the application.createform in order to instance the report in memory.

that's the point : isn't it the best way to create the instance of the report in memory ?

using your code (QuackRap := TQuickRep.Create(nil)) will create a new report dynamically, but i don't want it; i just want to instance my already created report in memory.

thanks again for your time
viana
Post by Crazy Horse's crazier little brother
Maybe I'm confused, but it looks to me like you're trying to create the
TQuickRep component as if it's a form.
application.createform(tquickep1,quickrep1);
is saying "create a form named quickrep1 of the class type tquickrep1."
var
QuackRap: TQuickRep;
begin
QuackRap := TQuickRep.Create(nil);
try
{ do something - make those ducks hip hop }
finally
QuackRap.Free;
end;
end;
or am I confused as to what your intentions are?
Maybe it would be best to post your code here, so we can see exactly what
you're trying to do.
Crazy Horse's crazier little brother
2005-05-11 13:56:39 UTC
Permalink
Post by viana
i already have a report named Quickrep1. the report is
already designed, with all bands, labels etc.
i just use the application.createform in order to instance the report in memory.
that's the point : isn't it the best way to create the instance of the report in memory ?
No, it's not, and that's why you get that err msg. If you already have
Quickrep1 designed, you don't need to create it. Besides that, createform()
is for creating forms, not anthing else--and even then, it should (arguably)
only be used in the .DPR, not in a .PAS file, even when creating forms.
--
Download Blackbird Crow Raven's book
"STILL CASTING SHADOWS: Two American Families 1620-2006"
(.exe and Delphi source): http://cc.borland.com/ccweb.exe/listing?id=23106

"viana" <***@ig.com.br> wrote in message news:42820b2f$***@newsgroups.borland.com...
viana
2005-05-11 18:13:56 UTC
Permalink
hi,

i really don't get it. if i try a command like this :

quickrep1.preview;

i get an Access violation, because there is no instance of quickrep1 in memory. that's why i use .createform method
BEFORE call .preview.

viana
No, it's not, and that's why you get that err msg. If you >already have
Quickrep1 designed, you don't need to create it. Besides that, >createform()
is for creating forms, not anthing else--and even then, it >should (arguably)
only be used in the .DPR, not in a .PAS file, even when >creating forms.
Crazy Horse's crazier little brother
2005-05-11 19:06:40 UTC
Permalink
Post by viana
quickrep1.preview;
i get an Access violation, because there is no instance of quickrep1 in
memory. that's why i use .createform method
BEFORE call .preview.
What class type is quickrep1? It's not a form, is it? Is it a TQuickRep?

Where are you calling quickrep1.preview?

If in the FormCreate() event, try FormShow() event.
--
Download Blackbird Crow Raven's book
"STILL CASTING SHADOWS: Two American Families 1620-2006"
(.exe and Delphi source): http://cc.borland.com/ccweb.exe/listing?id=23106
viana
2005-05-11 20:53:27 UTC
Permalink
yes, quickrep1 is a TQuickRep.

i have to create an instance of quickrep1 in memory before i can preview it . so i use the following code :

try
application.creaform(tquickrep1, quickrep1);
quickrep1.preview;
finally
quickrep1.free;
end;

is there another way ? let's suppose the only thing i want is to preview quickrep1. i have a button on the main form of the application and when the user click this button, quickrep1 will be previewed. what code do you suggest in order to do it ?

thanks again for your time !
Post by Crazy Horse's crazier little brother
What class type is quickrep1? It's not a form, is it? Is it a TQuickRep?
Where are you calling quickrep1.preview?
If in the FormCreate() event, try FormShow() event.
Crazy Horse's crazier little brother
2005-05-11 21:09:03 UTC
Permalink
Post by viana
yes, quickrep1 is a TQuickRep.
i have to create an instance of quickrep1 in memory before i can preview
try
application.creaform(tquickrep1, quickrep1);
quickrep1.preview;
finally
quickrep1.free;
end;
is there another way ? let's suppose the only thing i want is to preview
quickrep1. i have a button on the main form of the application and when
the user click this button, quickrep1 will be previewed. what code do you
suggest in order to do it ?
Yes, there is another way. Again, Createform() is for creating forms,
nothing else. You can't create TQuickRep components, or any other
components, using it.

You don't need to do anything to create the TQuickRep component if it's
already on your form. Delphi will take care of that for you.

All you need is the call to Preview in response to some event (such as a
button click, as you suggested).
--
Download Blackbird Crow Raven's book
"STILL CASTING SHADOWS: Two American Families 1620-2006"
(.exe and Delphi source): http://cc.borland.com/ccweb.exe/listing?id=23106
viana
2005-05-12 14:13:37 UTC
Permalink
hi,

the question is quickrep1 component isn't inside a form; this is a Tquickrep only. i create it clicking in File > New > other > report.

so it is not in a form, it's a Tquickrep alone.

the button to preview is in a form, but the component quickrep1 is NOT. that's why i need to create it before i can preview it.

any ideas ?

: )
Post by Crazy Horse's crazier little brother
Yes, there is another way. Again, Createform() is for creating forms,
nothing else. You can't create TQuickRep components, or any other
components, using it.
You don't need to do anything to create the TQuickRep component if it's
already on your form. Delphi will take care of that for you.
All you need is the call to Preview in response to some event (such as a
button click, as you suggested).
--
Download Blackbird Crow Raven's book
"STILL CASTING SHADOWS: Two American Families 1620-2006"
(.exe and Delphi source): http://cc.borland.com/ccweb.exe/listing?id=23106
Crazy Horse's crazier little brother
2005-05-12 14:16:16 UTC
Permalink
Post by viana
the question is quickrep1 component isn't inside a form; this is a
Tquickrep only. i create it clicking in File > New > other > report.
so it is not in a form, it's a Tquickrep alone.
the button to preview is in a form, but the component quickrep1 is NOT.
that's why i need to create it before i can preview it.
My main point is, you can't create a non-form with Createform().
CreateForm() is for creating forms.
--
Download Blackbird Crow Raven's book
"STILL CASTING SHADOWS: Two American Families 1620-2006"
(.exe and Delphi source): http://cc.borland.com/ccweb.exe/listing?id=23106
Joe Griffin
2005-05-12 20:55:53 UTC
Permalink
Post by viana
the question is quickrep1 component isn't inside a form; this is a Tquickrep only.
i create it clicking in File > New > other > report.
And you saved it as a form? (That's what you do when you save it.)
Post by viana
so it is not in a form, it's a Tquickrep alone.
No it's not; it's a form (called QuickReport1) of type TQuickRep
Post by viana
the button to preview is in a form, but the component quickrep1 is NOT. that's why
i need to create it before i can preview it.

If you create a report(form) and save it without changing the name of the report, it
will be QuickReport1, so in your calling code, try (culled from some of my production
code)...

QuickReport1 := TQuickReport1.Create(Application);
with QuickReport1 do
try
{ whatever }
if ((ParamCount = 1) and (UpperCase(ParamStr(1)) = 'DEBUG')) or
(GetKeyState(VK_SHIFT) < 0) then
begin
Preview;
end
else
begin
Print;
end;
finally // wrap up
Free;
end; // try/finally

... Joe
Member of the UK Borland User Group
viana
2005-05-13 11:59:16 UTC
Permalink
hello joe,

this works for me. i will change my code and see if the
problem get solved. thank you for your time !

viana.
Post by Joe Griffin
If you create a report(form) and save it without changing the name of the report, it
will be QuickReport1, so in your calling code, try (culled from some of my production
code)...
QuickReport1 := TQuickReport1.Create(Application);
with QuickReport1 do
try
{ whatever }
if ((ParamCount = 1) and (UpperCase(ParamStr(1)) = 'DEBUG')) or
(GetKeyState(VK_SHIFT) < 0) then
begin
Preview;
end
else
begin
Print;
end;
finally // wrap up
Free;
end; // try/finally
... Joe
Member of the UK Borland User Group
Morten Bergman
2005-05-12 16:29:20 UTC
Permalink
Try this:

with tquickep1.Create(self) do
begin
try
preview;
finally
free;
end;
end;

Morten
Post by viana
hello,
i always use a code like this to print using Quickreport
try
application.createform(tquickep1,quickrep1);
quickrep1.print;
finally
quickrep1.free;
end;
even with this try..finally, i get the error 'a component named quickrep1
already exists' eventually when i try to print the same report again. the
only way to workaround is closing app and starting it again.
is this a QR bug ?
thanks,
viana
Loading...