Recent

Author Topic: Standard Dataset Actions  (Read 22985 times)

Walmir

  • New Member
  • *
  • Posts: 39
Standard Dataset Actions
« on: July 02, 2014, 03:47:57 pm »
Hi,

I am in trouble with standard dataset actions.
In a main form, I have an ACtionList with standard dataset actions.
The database components (ZConnection, ZQuery, DataSource, ...) are in a data module.
The data aware controls are in a form that is put in a TDI component.
The actions are linked to main menu items and toobuttons in a toolbar but don't work.
Even when I set the actions DataSource directly in the Object Inspector they don't work.
A DBNavigator in the same form as the data aware components works fine.
In utter dispair I put the data aware controls directly in the main form and  -- tada! -- the actions still don't work.
What am I mising?

Best regards.
Walmir.

Lazarus 1.2.2, FPC 2.6.4.

Walmir

  • New Member
  • *
  • Posts: 39
Re: Standard Dataset Actions
« Reply #1 on: July 11, 2014, 08:59:13 pm »
Even if I put the ActionList with the standard database actions in the same form as the data aware controls and set each DataSource property of the actions to the same Data Source of the data aware controls, the standard DB actions don't work.
But a DBNavigator in the same form works correctly...
Is it a bug?

Best regards,
Walmir.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Standard Dataset Actions
« Reply #2 on: July 11, 2014, 09:51:16 pm »
One way to hook this up is to create an OnExecute event for each standard database action you have added (by double-clicking on the event in the Object Inspector) and (assuming your navigator control is named DBNav) set the event code like this:
Code: [Select]
procedure TForm1.acPostExecute(Sender: TObject);
begin
  DBNav.BtnClick(nbPost);
end;
for a Post action, use nbNext for a Next action etc. You don't need to set any Datasource property if the navigator is already working OK.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Standard Dataset Actions
« Reply #3 on: July 11, 2014, 09:59:14 pm »
One way to hook this up is to create an OnExecute event for each standard database action you have added

well that would work for every action there is no need to add a tdatasetaction. If the dataset action is not executed when the datasource is set then the dataset actions have a bug that needs to be reported. I'll try to test it later this week my self to see how it works if it works that is.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 6802
Re: Standard Dataset Actions
« Reply #4 on: July 12, 2014, 01:20:02 am »
If the dataset action is not executed when the datasource is set then the dataset actions have a bug that needs to be reported. I'll try to test it later this week my self to see how it works if it works that is.
I just answered Walmir in another post about this:
See here http://forum.lazarus.freepascal.org/index.php/topic,25140.msg152333.html#msg152333

It only seems to occur when the data controls are in a data module and the data aware controls are on another form. Then the default ExecuteTarget of the DataSetActions don't work.

The weird part is that i only had to add one TDataSource to the Form pointing to the dataset in the data module for it to work again. I don't have to connect the datasetaction to this datasource. (They can stay connected to the datasource in the datamodule.)

I'm also very new so i'm not yet familiar with the bugtracker... (but will be looking at that shortly) so if you could look at this bug for him...

(In the meantime i advised him to set an extra TDataSource on his form to get the ExecuteTarget and thus also the shortcuts to work)

( I tested this on Win7 64bit / Laz 1.2.4 win32 / FPC 2.6.4 )
« Last Edit: July 12, 2014, 02:02:03 am by rvk »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Standard Dataset Actions
« Reply #5 on: July 12, 2014, 04:06:21 am »
If the dataset action is not executed when the datasource is set then the dataset actions have a bug that needs to be reported. I'll try to test it later this week my self to see how it works if it works that is.
I just answered Walmir in another post about this:
See here http://forum.lazarus.freepascal.org/index.php/topic,25140.msg152333.html#msg152333

It only seems to occur when the data controls are in a data module and the data aware controls are on another form. Then the default ExecuteTarget of the DataSetActions don't work.

The weird part is that i only had to add one TDataSource to the Form pointing to the dataset in the data module for it to work again. I don't have to connect the datasetaction to this datasource. (They can stay connected to the datasource in the datamodule.)

I'm also very new so i'm not yet familiar with the bugtracker... (but will be looking at that shortly) so if you could look at this bug for him...

(In the meantime i advised him to set an extra TDataSource on his form to get the ExecuteTarget and thus also the shortcuts to work)

( I tested this on Win7 64bit / Laz 1.2.4 win32 / FPC 2.6.4 )

If that is the case I do need to test anything it is by design. You can't have actions not connected to a datasource selecting the active datasource by them self's you should write an onActivate event to set the action's datasource, keep in mind that the form might be modal mdi or inside a page control so it makes it impossible for the action to auto select the correct datasource and if you move the datasource to a datamodule instead of the form it makes it even more difficult to know exactly which datasource to select.

In any case I would appreciate a test application that shows the problem, before I start looking.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 6802
Re: Standard Dataset Actions
« Reply #6 on: July 12, 2014, 10:01:25 am »
In any case I would appreciate a test application that shows the problem, before I start looking.
Argh... there are two topics at this moment with the same (base) issue.
I posted some sample-code (and explanation) here:
http://forum.lazarus.freepascal.org/index.php/topic,25140.msg152354.html#msg152354

So the issue seems to be already in bugtracker but isn't assigned and is still open.

http://bugs.freepascal.org/view.php?id=25441
(and maybe this http://bugs.freepascal.org/view.php?id=25988)

percentage

  • New member
  • *
  • Posts: 9
Re: Standard Dataset Actions
« Reply #7 on: July 12, 2014, 07:23:26 pm »

Walmir

  • New Member
  • *
  • Posts: 39
Re: Standard Dataset Actions
« Reply #8 on: July 15, 2014, 05:48:29 pm »
Even when a place a TDataSource in the same form as the data aware controls, the standard database actions still don't work.
In summary, what I have:
- the data componentes in a data module;
- the action list with the standar DB actions in the main form;
- the data aware controls in another form that is opend inside a TDI Component
Although I think this is the "natural" way of doing things, the standar DB actions apparently are not prepared to work in this way.
Conclusion: I can't expect to do in Lazarus the same as I did in Delphi with DB actions and, so, they are useless.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Standard Dataset Actions
« Reply #9 on: July 15, 2014, 05:52:26 pm »
Walmir, if you feel this is a bug and if you have a test project that demonstrates the problem (including any needed database table definitions/DDL) could you please raise an item in the bugtracker so this can get looked at and hopefully addressed by the Lazarus developers?

Thanks.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

rvk

  • Hero Member
  • *****
  • Posts: 6802
Re: Standard Dataset Actions
« Reply #10 on: July 15, 2014, 06:55:01 pm »
Walmir, did you put a TDataSource (pointing to your DataSet in the DataModule) on your main form? The TDataSetActions in your TActionList need a TDataSource on the same form as the TActionList itself, otherwise they don't work.

BigChimp, this issue is already in the bugtracker here (#0025441). I added an extra note with sample code there. I'm not sure of the status but Luigi also posted this (@0025988) there. Not sure if that's the (correct) fix.

(It is strange the TDataSource doesn't even need to be connected to the TDatasetAction's. It just needs to be on the form.)

Walmir

  • New Member
  • *
  • Posts: 39
Re: Standard Dataset Actions
« Reply #11 on: July 16, 2014, 03:49:32 pm »
What I observed is that not only the TDataSource must be on the same form as the actionlist, but the controls that will be linked to the actions (menu items, buttons) must also be in that form.

So itf I put the TDataSource and the action list in a data module, the database actions will not work.
If this is so by design, it must be well documented.

Conclusion: In order to do the standard actions work, all the following must be in the same form:
- the action list with the standard database actions;
- the TDataSource componentes;
- the controls that will be linked to the actions.

Walmir

  • New Member
  • *
  • Posts: 39
Re: Standard Dataset Actions
« Reply #12 on: July 16, 2014, 06:09:16 pm »
Another gotcha!

I tried to place a TDataSource in the same form as the database actions and set its DataSet property at run time, when the form with the data aware controls are activated.
This don't work, too! The DataSet property of the TDataSource must be set at design time!
What a buggy thing!

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Standard Dataset Actions
« Reply #13 on: July 16, 2014, 08:11:58 pm »
Ooops. Sorry guys forgot all about this problem. I have downloaded the supplied samples and I'm going to take a closer look asap (if not tonight tomorrow night for sure). sorry again.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Standard Dataset Actions
« Reply #14 on: July 17, 2014, 10:44:28 am »
I took a good look yesterday it seems that the problem is on the TDataSetAction object specifically on the function HandlesTarget which is implemented like
Code: [Select]
function TDataSetAction.HandlesTarget(Target: TObject): Boolean;
begin
  Result:=(DataSource<>Nil);
  if Result and (DataSource=Target) then
    Result:=(DataSource.DataSet<>Nil)
  else
    Result:=(Target is TDataSource) and (TDataSource(Target).DataSet<>Nil);
end;

As you can see on the first if the implementor makes a hard coded that the active control that is passed from the suite to the action must be the same as the linked in datasource. That overrides any design time link and makes it impossible to have the datasource anywhere else but the form.

This needs to be changed to something along the lines of
Code: [Select]
function TDataSetAction.HandlesTarget(Target: TObject): Boolean;
begin
  Result:=(DataSource<>Nil) and (DataSource.DataSet<>Nil);
  if not Result  then
    Result:=(Target is TDataSource) and (TDataSource(Target).DataSet<>Nil);
end;
short circuit boolean evaluation must be on for the above code to work properly you can always make a multi if statement if you want.
That will solve the main problem but it will introduce a new bug coming from the GetDataSet function which needs to be changed from
Code: [Select]
function TDataSetAction.GetDataSet(Target: TObject): TDataSet;
begin
  Result:=(Target as TDataSource).DataSet;
end;
to

Code: [Select]
function TDataSetAction.GetDataSet(Target: TObject): TDataSet;
begin
  if assigned(FDataSource) then
    Result := FDataSource.dataset
  else
    Result:=(Target as TDataSource).DataSet;
end;
that should take care most of the problems.

Please keep in mind that the above have not been tested and there might be more problems introduced that I haven't seen yet. In any case this should put you back on track for now. I'll try to create a custom set of dataset actions to test the changes and report back. I haven't looked at the patch supplied on the bug tracker so I can't be sure what it changes and if it will do the job yet and I must find the bug reports to add a comment there too.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018