How execute a TQuickRep (quickreport) without displaying or printing it? - delphi

I need run a report (TQuickRep) for export only, without printing or showing.
The Prepare method does nothing.
The beforeprints or afterprints events doesn´t fires.
Ex.
var rep: TMyQuickRep; //TMyQuickRep is a report TQuickRep
begin
rep := TMyQuickRep.Create(Self);
try
rep.SomeData := somedata;
rep.DataSet := somDataSet;
rep.Prepare;
//rep.Run? there isn´t a method for run
rep.ExportToFilter(TQRPDFDocumentFilter.Create('c:\temp\myreport.pdf'));
//pdf is an empty page
finally
FreeAndNil(rep);
end;
end;

This should work for you...( I was looking for a solution just like this and the code below worked for me.)
rep.ExportToFilter(TQRPDFDocumentFilter.Create('c:\temp\myreport.pdf'));
rep.Print;

Related

(Delphi) query.next not working

I need help to fix my code...
I try to build some application with this code
Adoquery.close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from schedule where every like ''%5%''');
ADOQuery1.Open;
if not ADOQuery1.Eof then
begin
ShowMessage('hallo '+ADOQuery1.fieldbyname('remark').AsString);
ADOQuery1.Next;
end
Else
Begin
end;
I have 2 data records for the result, but why only one remark is showing?
I try to Trace it and found problem in ADOQuery1.next. After my application read ADOQuery.next, cursor jump to end; not go back to if not ADOQuery1.Eof then.
Any mistakes with my code?
The execution does not go back to the if statement because the code does not say to do so. You have a single if statement and no iteration. You need to iterate. For instance with a while loop:
while not ADOQuery1.Eof do begin
// do something
ADOQuery1.Next;
end;

Error when using parameter in ADOQuery

I have this simple code to check if a record exists in a table, but it always returns a runtime error :
Arguments are of the wrong type, are out of acceptable range, or are
in conflict with one another.
my code is this :
function TDataModuleMain.BarCodeExists(barCode: string): boolean;
begin
if ADOQuerySql.Active then
ADOQuerySql.Close;
ADOQuerySql.SQL.Clear;
ADOQuerySql.SQL.Text := 'select count(1) from Card where BarCode = (:TestBarcode)';
ADOQuerySql.Parameters.ParamByName('TestBarcode').Value := barCode;
ADOQuerySql.Open; // HERE THE RUNTIME ERROR APPEARS
Result := ADOQuerySql.Fields[0].AsInteger = 1;
ADOQuerySql.Close;
ADOQuerySql.Parameters.Clear;
end;
The field BarCode in table Card is of type nvarchar(100)
In debug I see that the parameter is created, and gets populated with the correct value.
Running the query in sql server management studio also works.
I also found this How to pass string parameters to an TADOQuery? and checked my code with the code in the answer but I don't see any problems here.
Also this AdoQuery Error using parameters did not help me.
It will no doubt be something very simple that I have missed but I just dont see it now.
EDIT : things I tried from suggestions in the comments:
.ParamCheck := True (default)
.Parameters.ParamByName('TestBarcode').DataType := ftString
.Parameters.ParamByName('TestBarcode').DataType := ftWideString
None of these worked however.
What did help was using a non-shared AdoQuery for this, and that one did the job without any errors. I am using that now as the solution but I am still looking at the shared AdoQuery out of curiousity what the exact problem is.
EDIT: the source of the problem is found.
I used the function provided by MartinA to examine both the dynamic created query and the shared AdoQuery and I found one difference.
The shared AdoQuery had the this property filled :
ExecuteOption := [eoExecuteNoRecords]
and the dynamic created query does not.
Since this property is not set in designtime I did not see it.
After clearing the property to [] the shared AdoQuery worked again.
I am going to switch to using non shared AdoQuery for this kind of work as been suggested.
Thanks everyone for your assistance.
The following isn't intended to be a complete answer to your q, but to follow up my comment that "all you have to do is to inspect your form's DFM and compare the properties of your original ADoQuery with the unshared one. The answer should lie in the difference(s)" and your reply that the unshared query is created dynamically.
There is no "voodoo" involved in the difference in behaviour between your two ADOQuerys. It's just a question of capturing what the differences actually are.
So, what you need, to debug the problem yourself, is some code to compare the properties of two components, even if one or both of them is created dynamically. Using the following routine on both components will enable you to do exactly that:
function TForm1.ComponentToString(AComponent : TComponent) : String;
var
SS : TStringStream;
MS : TMemoryStream;
Writer : TWriter;
begin
// Note: There may be a more direct way of doing the following, without
// needing the intermediary TMemoryStream, MS
SS := TStringStream.Create('');
MS := TMemoryStream.Create;
Writer := TWriter.Create(MS, 4096);
try
Writer.Root := Self;
Writer.WriteSignature;
Writer.WriteComponent(AComponent);
Writer.FlushBuffer;
MS.Position := 0;
ObjectBinaryToText(MS, SS);
Result := SS.DataString;
finally
Writer.Free;
MS.Free;
SS.Free;
end;
end;
Over to you ...

No PDF output from ReportBuilder

I have a ReportBuilder report that preview's as expected.
I'm trying to save it to pdf with the following code taken from the documentation:
ppReport1.ShowPrintDialog := false;
ppReport1.DeviceType := dtPDF;
ppReport1.TextFileName := 'C:\temp\report.pdf';
ppReport1.Print;
I get a glimpse of an dialog on the screen, stating that it outputs a couple of pages to the given file, but the file is no where to be found on disk.
What have I missed?
So, Process Monitor showed me that the file was written, but then deleted.
After a lot of source code browsing, I found the cause of this.
There is a property under EmailSettings called DeleteFile. For some reason, it also effects printing to file.
Try checking this property:
ppReport1.AllowPrintToFile := True;
It works fine with me.
It's strange. I just use by this way:
ppReport1.AllowPrintToFile := True;
ppReport1.ShowPrintDialog := False;
ppReport1.DeviceType := 'PDF';
ppReport1.TextFileName := 'C:\temp\report.pdf';
ppReport1.Print;
(I'm using it on ReportBuilder v14.07)

Stackoverflow error (infinite loop) while using Devexpress VCL 13.1.2

I am using TcxGridDBBandedTableView and have two columns of type TcxGridDBBandedColumn.
vwABC : TcxGridDBBandedTableView
vwABCField1 : TcxGridDBBandedColumn
vwABCField2 : TcxGridDBBandedColumn
When I change anything in vwABCField1, vwABCField2 values should get cleared. For this I am using OnEditValueChanged property of vwABCField1 like this:
procedure TMyForm.vwABCField1PropertiesEditValueChanged(Sender: TObject);
begin
vwABCField2.EditValue := '';
end;
While debugging, when I come to vwABCField2.EditValue := ''; statement, I never return back and get trapped in infine loop and after some time I get stackoverflow error.
vwABCField2.EditValue := ''; is calling vwABCField1PropertiesEditValueChanged procedure again and again recursively infinite time. I don't know why. I have not declared anything on OnEditValueChanged event of vwABCField2.
Update
If I write anything else in the above function instead of vwABCField2.EditValue := '';, it will be called only once. For example
procedure TMyForm.vwABCField1PropertiesEditValueChanged(Sender:TObject);
begin
ShowMessage("hi");
end;
works fine. So I suspect that culprit is vwABCField2.EditValue := ''; statement.
As in the official documentation is stated:
Do not change the edit value in your OnEditValueChanged event handler, as this can result in stack overflow. Use this event to get notification that the edit value has changed.
Because when you change the edit value in this event, of course, your editvalue is changed and therefore calling the OnEditValueChanged event again and again and ...

TChromium GetDevToolsUrl returns nothing

I'm trying to call Chromium Dev Tools with this code from dcef3 demos:
procedure TMainForm.actDevToolExecute(Sender: TObject);
begin
actDevTool.Checked := not actDevTool.Checked;
debug.Visible := actDevTool.Checked;
Splitter1.Visible := actDevTool.Checked;
if actDevTool.Checked then
begin
if not FDevToolLoaded then
begin
debug.Load(crm.Browser.Host.GetDevToolsUrl(True));
FDevToolLoaded := True;
end;
end;
end;
When i'm running programm, and pressing DevTools button, nothing happens, empty window, empty source code.
For Debug im trying this:
showmessage(crm.Browser.Host.GetDevToolsUrl(True));
And it return nothing(empty string).
But this code Works Fine in dcef3 guidemo... And not works in my Programm.
Whats a problem?
Here is dcef3 guiclient demo Full Code - http://dumpz.org/589068/
Thanks
Searching yields a discussion on Google Groups where Henri Gourvest explains that for the dev-tools URL to work, you need to define a debugging port. For example:
CefRemoteDebuggingPort := 9000;
If that doesn't work, then you need to compare your code with the working demo and identify what else you're doing differently.

Resources