Creating and deleting objects in Fast Report VCL (Delphi) - delphi

I'm using FastReport 4 to display some dynamically generated data and rearrange it in the report.
I use a "template" object in the report to get the initial position (in my real program I copy font properties, alignment, etc.)
I've managed to create a small project so I can create a memo component in the report, preview the report, and then remove the component so I can reuse the report with different data.
However, when I free the created object, I lose other objects from the report (in this case, my template object is not found the second time I preview the report).
What is the right way to create and remove objects from a Fast Report report?
Here is the pascal unit:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, frxClass;
type
TForm1 = class(TForm)
frxReport1: TfrxReport;
btn1: TButton;
procedure btn1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
modelObj: TfrxComponent;
newObj: TfrxMemoView;
begin
modelObj := frxReport1.FindObject('modelObj');
newObj := TfrxMemoView.Create(modelObj.Parent);
newObj.CreateUniqueName;
newObj.Text := 'Whee';
newObj.SetBounds(modelObj.Left, modelObj.Top + modelObj.Height,
modelObj.Width, modelObj.Height);
frxReport1.PrepareReport;
frxReport1.ShowPreparedReport;
newObj.Free;
end;
end.
Here's the DFM:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 299
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object btn1: TButton
Left = 224
Top = 48
Width = 75
Height = 25
Caption = 'btn1'
TabOrder = 0
OnClick = btn1Click
end
object frxReport1: TfrxReport
Version = '4.15'
DotMatrixReport = False
IniFile = '\Software\Fast Reports'
PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick]
PreviewOptions.Zoom = 1.000000000000000000
PrintOptions.Printer = 'Por defecto'
PrintOptions.PrintOnSheet = 0
ReportOptions.CreateDate = 41905.757295162040000000
ReportOptions.LastChange = 41905.757295162040000000
ScriptLanguage = 'PascalScript'
ScriptText.Strings = (
'begin'
''
'end.')
Left = 72
Top = 32
Datasets = <>
Variables = <>
Style = <>
object Data: TfrxDataPage
Height = 1000.000000000000000000
Width = 1000.000000000000000000
end
object Page1: TfrxReportPage
PaperWidth = 216.000000000000000000
PaperHeight = 279.000000000000000000
PaperSize = 1
LeftMargin = 10.000000000000000000
RightMargin = 10.000000000000000000
TopMargin = 10.000000000000000000
BottomMargin = 10.000000000000000000
object PageHeader1: TfrxPageHeader
Height = 279.685220000000000000
Top = 18.897650000000000000
Width = 740.787880000000000000
object modelObj: TfrxMemoView
Left = 166.299320000000000000
Top = 30.236240000000000000
Width = 264.567100000000000000
Height = 18.897650000000000000
ShowHint = False
Color = clYellow
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
Memo.UTF8W = (
'Model')
ParentFont = False
end
end
end
end
end

Sorry, for my misleading first answer.
It looks like an internal bug in PrepareReport, the objects seem to be exchanged.
var
modelObj: TfrxComponent;
newObj: TfrxMemoView;
cn:String;
begin
modelObj := frxReport1.FindObject('modelObj');
newObj := TfrxMemoView.Create(modelObj.Parent);
newObj.CreateUniqueName;
cn := newObj.Name; // keep for dirty workaround
newObj.Text := 'Whee';
newObj.SetBounds(modelObj.Left, modelObj.Top + modelObj.Height,
modelObj.Width, modelObj.Height);
Showmessage('New: ' + newObj.Name + ' modelObj: ' + modelObj.Name);
frxReport1.PrepareReport;
Showmessage('New: ' + newObj.Name + ' modelObj: ' + modelObj.Name);
frxReport1.ShowPreparedReport;
newObj := TfrxMemoView(frxReport1.FindObject(cn)); // dirty workaround
newObj.Free;
end;
Output:
New: Memo1 modelObj: modelObj
New: modelObj modelObj: Memo1
The workaround shown here will not be a usable way, so loading reports from a file or placing the TfrxReport component on a datamodule which will be created before printing and destroyed afterwards might be the better workarounds until this bug is fixed.

Related

TVirtualStringTree - How to use my own hint window class for VT columns?

I want to use a custom Hint window class for my entire application.
I use the Application.OnShowHint, analyze the THintInfo, and return my own TMyHintWindow in the HintInfo.HintWindowClass. This works well for all controls but I have a strange problem only with TVirtualStringTree Columns hint.
VT uses it's own hint window and own structure for the HintInfo.HintData. I study the code, and know it uses the VTHintData. so far so good. problem is that when I return my own hint window class (derived from THintWindow) it shows the hint window only for a split second and disappears!
There is no problem with hints returned for tree Nodes. they use the same method/structure (VTHintData).
Here is a very simple MCVE:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, VirtualTrees, StdCtrls;
type
TForm1 = class(TForm)
VirtualStringTree1: TVirtualStringTree;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
public
procedure ApplicationShowHint(var HintStr: string; var CanShow: Boolean;
var HintInfo: THintInfo);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TMyHintWindow = class(THintWindow)
public
{ nothing special here for now }
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
VirtualStringTree1.Hint := 'VT main hint';
VirtualStringTree1.ShowHint := True;
Memo1.Hint := 'Memo hint';
Memo1.ShowHint := True;
Application.OnShowHint := ApplicationShowHint;
end;
procedure TForm1.ApplicationShowHint(var HintStr: string; var CanShow: Boolean;
var HintInfo: THintInfo);
var
VTHintData: TVTHintData;
begin
{ VT uses it's own hint window class }
if HintInfo.HintWindowClass = TVirtualTreeHintWindow then
begin
{ VT passes columns and nodes hints information in HintInfo.HintData }
if HintInfo.HintData <> nil then
begin
VTHintData := PVTHintData(HintInfo.HintData)^;
if VTHintData.Node <> nil then { node hint }
begin
{ handle this case with DoGetNodeHint/DoGetNodeToolTip ... it works fine }
end
else
begin { column hint }
HintStr := VTHintData.DefaultHint; { got it! }
end;
end;
end;
Memo1.Lines.Add(HintStr); { prove I got the right hint }
HintInfo.HintColor := clAqua;
{ use my own hint window class
the hint from the VT columns is shown for a split second and hides! }
HintInfo.HintWindowClass := TMyHintWindow;
end;
end.
Form:
object Form1: TForm1
Left = 399
Top = 256
Width = 720
Height = 211
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object VirtualStringTree1: TVirtualStringTree
Left = 8
Top = 8
Width = 409
Height = 153
Header.AutoSizeIndex = 0
Header.Font.Charset = DEFAULT_CHARSET
Header.Font.Color = clWindowText
Header.Font.Height = -11
Header.Font.Name = 'MS Sans Serif'
Header.Font.Style = []
Header.Options = [hoColumnResize, hoDrag, hoShowHint, hoShowSortGlyphs, hoVisible]
HintAnimation = hatNone
HintMode = hmTooltip
TabOrder = 0
Columns = <
item
Position = 0
Width = 150
WideText = 'column 0'
WideHint = 'VT column 0 hint'
end
item
Position = 1
Width = 150
WideText = 'column 1'
WideHint = 'VT column 1 hint'
end>
end
object Memo1: TMemo
Left = 424
Top = 8
Width = 273
Height = 153
ScrollBars = ssVertical
TabOrder = 1
end
end
I have debugged this for hours. I see nothing special.
Why is this happening? who/what closes the hint window right away?
Thanks.
I'm using VT version 5.3.0
In the TBaseVirtualTree.CMHintShowPause() it is stated:
A little workaround is needed here to make the application class
using the correct hint window class. Once the application gets
ShowHint set to true (which is the case when we want to show hints in
the tree) then an internal hint window will be created which is not
our own class (because we don't set an application wide hint window
class but only one for the tree). Unfortunately, this default hint
window class will prevent hints for the non-client area to show up
(e.g. for the header) by calling CancelHint whenever certain messages
arrive. By setting the hint show pause to 0 if our hint class was not
used recently we make sure that the hint timer (in Forms.pas) is
not used and our class is created immediately.
I'm not really sure how to handle this. I think I'll drop the whole idea of using my won hint class for the header columns.

How to manage constantly changing project run-time parameters in the IDE?

In my (XE2) IDE I constantly have to switch the settings for Project Options/ Debugger / Parameters because I'm testing for different client configurations, databases etc.
The Parameters dropdown list is becoming unmanageable. Since these have no descriptions either, it's even hard to figure out which ones to remove (How can I clean the Parameters field in the Run -> Parameters menu?).
Any smart ideas on managing these?
In an ideal word I would like to give them a tag/description, reorder them, delete some...
Not ideal but a workaround would be to add a redundant tag parameter as first parameter.
That way at least, when you use the dropdown list, you'll have some indication on what parameter combination you are using.
In addition to Lievens answer I'm adding an answer to my own question.
I have started using [identifier] at the beginning of the run-time parameter, and I can put in there what I want. In addition I have written a small app that lets me clean up the parameters that are stored in the registry (at HKEY_CURRENT_USER\Software\Embarcadero\BDS\9.0\History Lists\hlRunParameters).
Here is the code for that Win32 app. It will let you delete and sort the registry values. It is written in Delphi XE2. Just create a new VCL project and use this as the main form.
uCleanIDEParams.pas
unit uCleanIDEParams;
// https://stackoverflow.com/questions/27502689/how-to-manage-constantly-changing-project-run-time-parameters-in-the-ide
// All 32 bit stuff, the Delphi IDE is 32 bit too
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.CheckLst, Registry,
Vcl.ExtCtrls;
type
TFrmCleanIDEParams = class(TForm)
PnlTop: TPanel;
BtnLoad: TButton;
EdtRegKey: TEdit;
Label1: TLabel;
ChkRedundant: TCheckBox;
PnlBottom: TPanel;
GBxSelection: TGroupBox;
BtnSelectAll: TButton;
BtnSelectNone: TButton;
BtnStartWith: TButton;
ChkNot: TCheckBox;
EdtStartWith: TEdit;
BtnInvert: TButton;
Label2: TLabel;
BtnWrite: TButton;
ChkSort: TCheckBox;
PnlCenter: TPanel;
CLBParams: TCheckListBox;
procedure BtnLoadClick(Sender: TObject);
procedure BtnSelectAllClick(Sender: TObject);
procedure BtnSelectNoneClick(Sender: TObject);
procedure BtnInvertClick(Sender: TObject);
procedure BtnStartWithClick(Sender: TObject);
procedure BtnWriteClick(Sender: TObject);
private
public
end;
var
FrmCleanIDEParams: TFrmCleanIDEParams;
implementation
{$R *.dfm}
procedure TFrmCleanIDEParams.BtnInvertClick(Sender: TObject);
var i: integer;
begin
for i := 0 to CLBParams.Items.Count-1 do CLBParams.Checked[i] := not CLBParams.Checked[i];
end;
procedure TFrmCleanIDEParams.BtnLoadClick(Sender: TObject);
var
lReg : TRegistry;
lValue,
lItem,
lKey : String;
i,
lNrRegVals: Integer;
begin
lKey := Trim(EdtRegKey.Text);
if lKey = '' then Exit;
if lKey[1] = '\' then lKey := Copy(lKey,2);
lReg := TRegistry.Create(KEY_READ);
lReg.RootKey := HKEY_CURRENT_USER;
if not lReg.OpenKey(lKey,false) then
begin
MessageDlg('Key not found', mtError, mbOKCancel, 0);
Exit;
end;
if not lReg.ValueExists('Count') then
begin
MessageDlg('Value ''Count'' not found', mtError, mbOKCancel, 0);
Exit;
end;
lNrRegVals := lReg.ReadInteger('Count');
for i := 0 to lNrRegVals-1 do
begin
lValue := 'Item' + IntToStr(i);
if lReg.ValueExists(lValue) then
begin
lItem := lReg.ReadString(lValue);
if ChkRedundant.Checked then
lItem := Trim(StringReplace(lItem,' ',' ',[rfReplaceAll]));
CLBParams.Items.Add(lItem);
end;
end;
end;
procedure TFrmCleanIDEParams.BtnSelectAllClick(Sender: TObject);
var i: integer;
begin
for i := 0 to CLBParams.Items.Count-1 do CLBParams.Checked[i] := true;
end;
procedure TFrmCleanIDEParams.BtnSelectNoneClick(Sender: TObject);
var i: integer;
begin
for i := 0 to CLBParams.Items.Count-1 do CLBParams.Checked[i] := true;
end;
procedure TFrmCleanIDEParams.BtnStartWithClick(Sender: TObject);
var
i : integer;
lStart,
lItem : string;
begin
lStart := Lowercase(Trim(EdtStartWith.Text));
if lStart = '' then Exit;
for i := 0 to CLBParams.Items.Count-1 do
begin
lItem := lowercase(CLBParams.Items[i]);
if (not ChkNot.Checked) and (Pos(lStart,lItem) = 1)
or (ChkNot.Checked) and (Pos(lStart,lItem) <> 1) then
CLBParams.Checked[i] := true;
end;
end;
procedure TFrmCleanIDEParams.BtnWriteClick(Sender: TObject);
var
lReg : TRegistry;
lValue,
lKey : String;
i,
lNrToWrite,
lNrRegVals: Integer;
begin
for i := CLBParams.Items.Count-1 downto 0 do
if not CLBParams.Checked[i] then
CLBParams.Items.Delete(i);
if CLBParams.Items.Count = 0 then
begin
MessageDlg('Nothing to do', mtInformation, mbOKCancel, 0);
Exit;
end;
if ChkSort.Checked then
CLBParams.Sorted := true;
// Now writing back
lKey := Trim(EdtRegKey.Text);
if lKey = '' then Exit;
if lKey[1] = '\' then lKey := Copy(lKey,2);
lReg := TRegistry.Create(KEY_READ or KEY_WRITE);
lReg.RootKey := HKEY_CURRENT_USER;
if not lReg.OpenKey(lKey,false) then
begin
MessageDlg('Key not found', mtError, mbOKCancel, 0);
Exit;
end;
if not lReg.ValueExists('Count') then
begin
MessageDlg('Value ''Count'' not found', mtError, mbOKCancel, 0);
Exit;
end;
lNrRegVals := lReg.ReadInteger('Count');
lNrToWrite := CLBParams.Items.Count;
lReg.WriteInteger('Count',lNrToWrite);
// Write TCheckListBox items:
for i := 0 to lNrToWrite-1 do
begin
lValue := 'Item' + IntToStr(i);
lReg.WriteString(lValue,CLBParams.Items[i]);
end;
// Remove the rest:
for i := lNrToWrite to lNrRegVals-1 do
lReg.DeleteValue('Item' + IntToStr(i));
end;
end.
uCleanIDEParams.dfm
object FrmCleanIDEParams: TFrmCleanIDEParams
Left = 0
Top = 0
Caption = 'Clean Delphi IDE runtime parameters'
ClientHeight = 560
ClientWidth = 549
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
PixelsPerInch = 96
TextHeight = 13
object PnlTop: TPanel
Left = 0
Top = 0
Width = 549
Height = 58
Align = alTop
BevelOuter = bvNone
TabOrder = 0
object Label1: TLabel
Left = 19
Top = 11
Width = 308
Height = 13
Caption = 'HKEY_CURRENT_USER registry key for IDE runtime parameters:'
end
object BtnLoad: TButton
Left = 496
Top = 30
Width = 40
Height = 25
Caption = 'Load'
TabOrder = 0
OnClick = BtnLoadClick
end
object EdtRegKey: TEdit
Left = 16
Top = 32
Width = 473
Height = 21
TabOrder = 1
Text = '\Software\Embarcadero\BDS\9.0\History Lists\hlRunParameters'
end
object ChkRedundant: TCheckBox
Left = 388
Top = 10
Width = 151
Height = 17
Hint = 'Removes leading, trailing, and duplicate spaces'
Caption = 'Remove redundant spaces'
Checked = True
State = cbChecked
TabOrder = 2
end
end
object PnlBottom: TPanel
Left = 0
Top = 471
Width = 549
Height = 89
Align = alBottom
BevelOuter = bvNone
TabOrder = 1
object Label2: TLabel
Left = 74
Top = 62
Width = 287
Height = 13
Caption = 'Click button to write the selected items back to the registry:'
end
object GBxSelection: TGroupBox
Left = 16
Top = -3
Width = 520
Height = 51
Caption = ' Select '
TabOrder = 0
object BtnSelectAll: TButton
Left = 348
Top = 18
Width = 50
Height = 25
Caption = 'All'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
TabOrder = 0
OnClick = BtnSelectAllClick
end
object BtnSelectNone: TButton
Left = 404
Top = 18
Width = 50
Height = 25
Caption = 'None'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
TabOrder = 1
OnClick = BtnSelectNoneClick
end
object BtnStartWith: TButton
Left = 51
Top = 18
Width = 79
Height = 25
Hint = 'Selection is additive'
Caption = 'starting with:'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 2
OnClick = BtnStartWithClick
end
object ChkNot: TCheckBox
Left = 11
Top = 22
Width = 40
Height = 17
Caption = 'NOT'
TabOrder = 3
end
object EdtStartWith: TEdit
Left = 136
Top = 20
Width = 121
Height = 21
Hint = 'Case insensitive match'
ParentShowHint = False
ShowHint = True
TabOrder = 4
Text = '['
end
object BtnInvert: TButton
Left = 460
Top = 18
Width = 50
Height = 25
Caption = 'Invert'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
TabOrder = 5
OnClick = BtnInvertClick
end
end
object BtnWrite: TButton
Left = 364
Top = 58
Width = 89
Height = 25
Hint = 'Write the selected items back to the registry'
Caption = 'Write back'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 1
OnClick = BtnWriteClick
end
object ChkSort: TCheckBox
Left = 459
Top = 62
Width = 57
Height = 17
Caption = '(sorted)'
Checked = True
State = cbChecked
TabOrder = 2
end
end
object PnlCenter: TPanel
Left = 0
Top = 58
Width = 549
Height = 413
Align = alClient
BevelOuter = bvNone
TabOrder = 2
object CLBParams: TCheckListBox
AlignWithMargins = True
Left = 15
Top = 10
Width = 522
Height = 393
Margins.Left = 15
Margins.Top = 10
Margins.Right = 12
Margins.Bottom = 10
Align = alClient
ItemHeight = 13
TabOrder = 0
end
end
end
Notes:
Do not forget to change the version number in the key if you are using anything other than XE2. For old Delphi versions you may even have to change Embarcadero to Borland.
Do not run this app from within the IDE. When it closes, Delphi will overwrite any changes you made to that registry key, and it looks like your program does not work ;=)

Delphi insert image to database firebird

i have table (employee) with many fields.
first name, last name, middle name, image and so on.
i'm using dbExpress (TclientDataset) and have code in the event After Post
clientdataset1.applyupdates(0)
and it works but i want to insert/update also the image but it doesn't save the image to database(Fire bird)
id search in google but it doesn't fit to what i want, please help thanks
Below is the source and DFM of a project I've put together to see if I get the same problem as you.
I don't. It successfully loads and saves .BMP files to the CDS1Image field.
You didn't say what your column type is, but in my FB db, the Image column is defined as a BLOB.
Btw, I'm not sure what kind of image you're trying to work with, but there is a long-standing problem that TDBImage doesn't handle JPEGs.
procedure TForm2.GetImage;
var
ImageFN : String;
MS : TMemoryStream;
begin
if OpenDialog1.Execute then begin
ImageFN := OpenDialog1.FileName;
end;
MS := TMemoryStream.Create;
MS.LoadFromFile(ImageFN);
MS.Seek(0, soBeginning);
try
CDS1.Edit;
CDS1Image.LoadFromStream(MS);
CDS1.Post;
finally
MS.Free;
end;
end;
procedure TForm2.RefreshCDS;
begin
CDS1.ApplyUpdates(0);
CDS1.Close;
CDS1.Open;
end;
procedure TForm2.CDS1NewRecord(DataSet: TDataSet);
var
ID : Integer;
begin
Inc(ID);
if SqlQuery2.Active then
SqlQuery2.Close;
SqlQuery2.Open;
ID := 1 + SqlQuery2.Fields[0].AsInteger;
CDS1.FieldByName('ID').AsInteger := ID;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
CDS1.Open;
end;
procedure TForm2.btnGetImageClick(Sender: TObject);
begin
GetImage;
end;
procedure TForm2.btnRefreshClick(Sender: TObject);
begin
RefreshCDS;
end;
DFM
object Form2: TForm2
Left = 256
Top = 95
Caption = 'Form2'
ClientHeight = 303
ClientWidth = 452
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 8
Top = 8
Width = 320
Height = 120
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
end
object DBNavigator1: TDBNavigator
Left = 24
Top = 144
Width = 240
Height = 25
DataSource = DataSource1
TabOrder = 1
end
object btnRefresh: TButton
Left = 350
Top = 8
Width = 75
Height = 25
Caption = 'Refresh'
TabOrder = 2
OnClick = btnRefreshClick
end
object DBImage1: TDBImage
Left = 128
Top = 175
Width = 105
Height = 105
DataField = 'IMAGE'
DataSource = DataSource1
TabOrder = 3
end
object btnGetImage: TButton
Left = 350
Top = 64
Width = 75
Height = 25
Caption = 'GetImage'
TabOrder = 4
OnClick = btnGetImageClick
end
object SQLConnection1: TSQLConnection
DriverName = 'Firebird'
LoginPrompt = False
Params.Strings = (
'DriverUnit=Data.DBXFirebird'
'DriverPackageLoader=TDBXDynalinkDriverLoader,DbxCommonDriver180.' +
'bpl'
'DriverAssemblyLoader=Borland.Data.TDBXDynalinkDriverLoader,Borla' +
'nd.Data.DbxCommonDriver,Version=18.0.0.0,Culture=neutral,PublicK' +
'eyToken=91d62ebb5b0d1b1b'
'MetaDataPackageLoader=TDBXFirebirdMetaDataCommandFactory,DbxFire' +
'birdDriver180.bpl'
'MetaDataAssemblyLoader=Borland.Data.TDBXFirebirdMetaDataCommandF' +
'actory,Borland.Data.DbxFirebirdDriver,Version=18.0.0.0,Culture=n' +
'eutral,PublicKeyToken=91d62ebb5b0d1b1b'
'GetDriverFunc=getSQLDriverINTERBASE'
'LibraryName=dbxfb.dll'
'LibraryNameOsx=libsqlfb.dylib'
'VendorLib=fbclient.dll'
'VendorLibWin64=fbclient.dll'
'VendorLibOsx=/Library/Frameworks/Firebird.framework/Firebird'
'Database=d:\delphi\firebird\databases\employee.fdb'
'User_Name=sysdba'
'Password=masterkey'
'Role=RoleName'
'MaxBlobSize=-1'
'LocaleCode=0000'
'IsolationLevel=ReadCommitted'
'SQLDialect=3'
'CommitRetain=False'
'WaitOnLocks=True'
'TrimChar=False'
'BlobSize=-1'
'ErrorResourceFile='
'RoleName=RoleName'
'ServerCharSet='
'Trim Char=False')
Connected = True
Left = 40
Top = 24
end
object SQLQuery1: TSQLQuery
MaxBlobSize = 1
Params = <>
SQLConnection = SQLConnection1
Left = 112
Top = 24
end
object DataSource1: TDataSource
DataSet = CDS1
Left = 272
Top = 88
end
object CDS1: TClientDataSet
Active = True
Aggregates = <>
CommandText = 'select * from maimages'
Params = <>
ProviderName = 'DataSetProvider1'
AfterOpen = CDS1AfterOpen
OnNewRecord = CDS1NewRecord
Left = 280
Top = 24
object CDS1ID: TIntegerField
FieldName = 'ID'
Required = True
end
object CDS1NAME: TStringField
FieldName = 'NAME'
Size = 50
end
object CDS1IMAGE: TBlobField
FieldName = 'IMAGE'
Size = 1
end
end
object DataSetProvider1: TDataSetProvider
DataSet = SQLQuery1
Options = [poAllowCommandText, poUseQuoteChar]
Left = 184
Top = 24
end
object OpenDialog1: TOpenDialog
Filter = 'BMPs|*.Bmp'
Left = 400
Top = 32
end
object SQLQuery2: TSQLQuery
Active = True
MaxBlobSize = 1
Params = <>
SQL.Strings = (
'select max(ID) from maimages')
SQLConnection = SQLConnection1
Left = 16
Top = 120
end
end

How to get multiple result set in dbexpress tsqlstoredproc

I want get multiple record or result sets from tsqlstoredproc in Delphi XE3 or I want get multiple record or result sets from tsqlquery.
For example:
ds1,ds2: tsqldataset;
begin
sqlstoredproc1.open; //or Active:=true
ds1:=sqlstoredproc1;
ds2:=sqlstoredproc1.nextrecordset;
thanks for all
The Button1Click handler below shows how to do this for a TSqlStoredProc. TSqlQuery does not implement a NextRecordSet function. This is unlike the TAdoXXX set of Stored Proc + DataSet components which all provide access to the NextRecordSet function of their underlying MDac RecordSet objects.
All you need do is to declare a TCustomSqlDataset variable and then assign the SqlStoredProc's NextRecordSet function result to it.
A thing to be aware of is that the CustomSqlDataSet returned by TSqlStoredProc.NextRecordSet is given the same owner as the TSqlStoredProc. This is fine if the SqlStoredProc is on a form, because it and the CustomSqlDataSet will be freed when the form is. But if you create an ownerless SqlStoredProc in code, you will need to free any CustomSqlDataSet returned by its NextRecordSet yourself or you will have a memory leak.
Btw, the variable you assign .NextRecordSet to needs to have a lifetime at least as long as you want to use the NextRecordSet for. In other words, it's no use assigning the result of NextRecordSet to a local variable of a procedure which exits immediately afterwards (I wasn't sure whether the code in your q was supposed to be a local procedure or not).
TForm1 = class(TForm)
SQLConnection1: TSQLConnection;
SQLStoredProc1: TSQLStoredProc;
DataSetProvider1: TDataSetProvider;
ClientDataSet1: TClientDataSet;
ClientDataSet2: TClientDataSet;
DataSetProvider2: TDataSetProvider;
DataSource1: TDataSource;
DataSource2: TDataSource;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
NextDataSet : TCustomSqlDataSet;
end;
var Form1: TForms;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
NextDataSet := SqlStoredProc1.NextRecordset;
DataSetProvider2.DataSet := NextDataSet;
ClientDataSet2.Open;
end;
Partial DFM (TSqlConnection edited for security reasons)
object Form1: TForm1
Left = 265
Top = 197
Width = 527
Height = 358
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 8
Top = 8
Width = 320
Height = 120
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object DBGrid2: TDBGrid
Left = 8
Top = 160
Width = 320
Height = 120
DataSource = DataSource2
TabOrder = 1
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object Button1: TButton
Left = 352
Top = 24
Width = 137
Height = 25
Caption = 'Get next recordset'
TabOrder = 2
OnClick = Button1Click
end
object DataSource1: TDataSource
DataSet = ClientDataSet1
Left = 232
Top = 32
end
object SQLStoredProc1: TSQLStoredProc
Active = True
MaxBlobSize = -1
Params = <>
SQLConnection = SQLConnection1
StoredProcName = 'getfilesdetails2'
Left = 72
Top = 32
end
object DataSource2: TDataSource
DataSet = ClientDataSet2
Left = 176
Top = 232
end
object DataSetProvider1: TDataSetProvider
DataSet = SQLStoredProc1
Left = 112
Top = 32
end
object ClientDataSet1: TClientDataSet
Active = True
Aggregates = <>
Params = <>
ProviderName = 'DataSetProvider1'
Left = 192
Top = 32
end
object SQLConnection1: TSQLConnection
ConnectionName = 'MSSQLConnection'
DriverName = 'MSSQL'
GetDriverFunc = 'getSQLDriverMSSQL'
LibraryName = 'dbexpmss.dll'
LoginPrompt = False
Params.Strings = (
'DriverName=MSSQL'
'HostName=aaaa'
'DataBase=bbbb'
'User_Name=cccc'
'Password='
'BlobSize=-1'
'ErrorResourceFile='
'LocaleCode=0000'
'MSSQL TransIsolation=ReadCommited'
'OS Authentication=False')
VendorLib = 'oledb'
Connected = True
Left = 32
Top = 32
end
object ClientDataSet2: TClientDataSet
Aggregates = <>
Params = <>
ProviderName = 'DataSetProvider2'
Left = 136
Top = 232
end
object DataSetProvider2: TDataSetProvider
Left = 88
Top = 232
end
end

How do you loop a video using DSPack?

I've got a very simple program that uses DSPack from within Delphi 2010. I have a form with a TFilterGraph and a TVideoWindow. The video plays and renders nicely. I can't seem to figure out how to make the video loop back to the beginning when it ends.
How do you make a video automatically loop using DSPack?
Code
unit Unit21;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DSPack, ExtCtrls;
type
TForm21 = class(TForm)
FilterGraph1: TFilterGraph;
OpenDialog1: TOpenDialog;
Button1: TButton;
Button2: TButton;
Panel1: TPanel;
VideoWindow1: TVideoWindow;
Panel2: TPanel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form21: TForm21;
implementation
{$R *.dfm}
procedure TForm21.Button1Click(Sender: TObject);
begin
OpenDialog1.InitialDir := ExtractFilePath(ParamStr(0));
if OpenDialog1.Execute then
begin
if not FilterGraph1.Active then FilterGraph1.Active:= True;
VideoWindow1.FilterGraph:= FilterGraph1;
FilterGraph1.RenderFile(OpenDialog1.Filename);
FilterGraph1.Play;
end;
end;
procedure TForm21.Button2Click(Sender: TObject);
begin
FilterGraph1.Stop;
end;
procedure TForm21.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
FilterGraph1.ClearGraph;
FilterGraph1.Active:= False;
end;
end.
DFM
object Form21: TForm21
Left = 0
Top = 0
Caption = 'Form21'
ClientHeight = 441
ClientWidth = 644
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCloseQuery = FormCloseQuery
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 644
Height = 384
Align = alClient
Caption = 'Panel1'
TabOrder = 0
object VideoWindow1: TVideoWindow
Left = 1
Top = 1
Width = 642
Height = 382
Mode = vmVMR
FilterGraph = FilterGraph1
VMROptions.Mode = vmrWindowed
Color = clWhite
Align = alClient
end
end
object Panel2: TPanel
Left = 0
Top = 384
Width = 644
Height = 57
Align = alBottom
Caption = 'Panel2'
TabOrder = 1
object Button1: TButton
Left = 24
Top = 16
Width = 75
Height = 25
Caption = 'Play'
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 128
Top = 16
Width = 75
Height = 25
Caption = 'Stop'
TabOrder = 1
OnClick = Button2Click
end
end
object FilterGraph1: TFilterGraph
GraphEdit = True
LinearVolume = True
Left = 424
Top = 144
end
object OpenDialog1: TOpenDialog
Left = 344
Top = 128
end
end
There is no built in support for seamless looping. Yes you certainly can receive completion event, seek playback to the beginning and run the graph again, however this would inevitably have a restart delay and possibly flickering.
To implement seamless looping you either a multigraph solution, to restart upstream graph while presentation graph is on a short pause and does not flicker. Or otherwise add custom filters into the pipeline to restart streaming internally and present it as continuous stream.

Resources