Description:
Is it possible to connect UniDac components to a server mode Grid view?
Answer:
Yes, it is possible to make our TdxServerModeCustomDataSource class support UniDAC. It is sufficient to override some of TdxServerModeCustomDataSource methods to implement this functionality. Attached is a .pas file that shows how it can be done. Just add this unit to the uses section of your project and write the code similar to the following:
Delphiunit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
dxServerModeUniDACDataSource, dxServerModeSQLAdapters, DBAccess, cxGraphics, cxControls,
cxLookAndFeels, cxLookAndFeelPainters, cxStyles, cxCustomData, cxFilter, cxData,
cxDataStorage, cxEdit, cxNavigator, DB, StdCtrls, cxGridLevel, cxClasses, cxGridCustomView,
cxGridCustomTableView, cxGridTableView, cxGridServerModeTableView, cxGrid,
Uni, UniProvider, SQLServerUniProvider;
type
TForm2 = class(TForm)
btCreateUniDACDataSource: TButton;
cxGrid: TcxGrid;
cxGridLevel: TcxGridLevel;
cxGridServerModeTableView: TcxGridServerModeTableView;
UniConnection: TUniConnection;
procedure btCreateUniDACDataSourceClick(Sender: TObject);
private
FDataSource: TdxServerModeUniDACDataSource;
public
property DataSource: TdxServerModeUniDACDataSource read FDataSource;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.btCreateUniDACDataSourceClick(Sender: TObject);
begin
btCreateUniDACDataSource.Enabled := False;
FDataSource := TdxServerModeUniDACDataSource.Create(Self);
DataSource.Connection := UniConnection;
DataSource.SQLAdapterClass := TdxServerModeMSSQLAdapter;
DataSource.TableName := 'ServerModeGridTableDemo';
DataSource.Active := True;
cxGridServerModeTableView.DataController.DataSource := DataSource;
cxGridServerModeTableView.DataController.CreateAllItems;
end;
end.
Note that this is just a draft approach that can be modified as your needs dictate.
P.S.: We recommend you always use parametric queries when you work with the UniDAC connection.
See also:
The custom solution provided by Robert N Harris:
UniDAC in Server Mode - Custom solution
The custom solution provided by Michael Schumann:
cxGrid Servermode Unidac 6.4.16 and Firebird 3
The custom solution provided by Andrzej Kulakowski:
Thank you for this post.
I have also tested the TdxServerModeUniDACQueryDataSource successfully.
You are always welcome.
Hello,
All files should be in the "Attachments" section (see the attached image).
Hello,
I have modified your sample. In attached zip you will get source code for parametrized UniDac server mode query.
One inconvenience is to call method PrepareParams before open dataset.
This is the way I use it:
dxServerModeUniDACQueryDataSource1.SQL.Clear;
dxServerModeUniDACQueryDataSource1.SQL.Add(
'select * from [hub].[HubEvents](:LocalizationId, :Date, :Year, :Offset) ');
dxServerModeUniDACQueryDataSource1.KeyFieldNames := 'EventId';
dxServerModeUniDACQueryDataSource1.PrepareParams;
dxServerModeUniDACQueryDataSource1.ParamByName('LocalizationId').Value := 35;
dxServerModeUniDACQueryDataSource1.ParamByName('Offset').Value := -1;
dxServerModeUniDACQueryDataSource1.Open;
Best regards
Tomasz Andrzejewski
Thank you very much for your comment. Your code may be interesting to other programmers.
UniDacQuerySource with in-place edit/delete.
You have to set TableName property e.g in PostData event.
Is UniDac going to be supported by DevExpress, it would seem that the codoing work (as above) was done 2 years ago! given this I expect it would be trivial to roll out?
Is there a C++ version of the above code/do I need one (I don't have a delphi identity)
Hello,
We are not going to support UniDac third-party components for Server Mode out-of-the-box. I strongly recommend you consider migrating to the FireDAC engine that is embedded into modern Embarcadero IDEs. This Knowledge Base article is just a temporary solution and has only Delphi code.
Thank You for your answer -
That leaves me with a huge problem as I use other components that don't support firedac.
It seems odd that you won't support UniDac as the work has pretty much already been done. You seem to be turning your back on a huge segment of the market.
At least your timely answer has meant I can respond to the embarcadero sales chap who called yesterday in response to this and I can tell him no longer need to upgrade and buy the Delphi personality.
This solution should work in the latest version of our controls (VCL 13.2.3). So if you really need UniDAC + Server Mode, you can use it. However, the built-in UniDAC solution is not planned for the near future.
I am lost now Paulo which solution works - what do I need to do?
The solution demonstrated in this Knowledge Base article (how to use UniDAC DB with our Server Mode in Delphi) still works in the latest version of our controls (VCL 13.2.3). However, if you are using C++Builder, than it is necessary to adapt this solution by yourself because we do not have a C++ counterpart for this sample.
Thanks - I ended up implementing my own servermode as I suggested in this post four years ago
http://www.devexpress.com/Support/Center/Question/Details/Q272253