Working with Calculated Fields

Hello all,


I am sorry if this looks like a dummy question, but I've spent a few weeks on this problem, with no lucky.

I have a Delphi project that comprises a simple video playlist, which I control via a Query displayed by a DBGrid.

Each video has its own duration and a start 'forecast'. For instance:

The video forecast is calculated based on the previous video forecast+duration.
The first video forecast is set by the user ( 10:00:00 ) and all following video forecasts must be automatically calculated.

VideoName	duration 	forecast
video1		00:00:30	10:00:00
video2		00:00:45	10:00:30
video3		00:01:10	10:01:15


As this is a dynamic playlist, where videos can be added and removed or even swapped, I've create a Calculated Field and implemented the OnCalcFields method to handle the start forecast values.

The algorithm part is OK ( I guess ) but my problem lies in the technical aspects !

I cannot find a feaseble and relieable way to get the forecast value from the previuos video in order to calculate the current video start forecast.

All option I found implies in browsing the DataSet back and forth to get the data value. Which is not a good solution. 

Also, I cannot use a query to get the value because this is a calculated field, thus non persistent.


I could not find a way to get the Calculated field value, without having to browse thru the table.

Any quess ?

Well... again, I am sorry for the dummy questions.


Márcio
0
Marcio
6/21/2015 11:43:57 PM
embarcadero.delphi.database 1294 articles. 0 followers. Follow

4 Replies
562 Views

Similar Articles

[PageSpeed] 21

Marcio Correa wrote:
> Hello all,
> 
> 
> I am sorry if this looks like a dummy question, but I've spent a few weeks on this problem, with no lucky.
> 
> I have a Delphi project that comprises a simple video playlist, which I control via a Query displayed by a DBGrid.
> 
> Each video has its own duration and a start 'forecast'. For instance:
> 
> The video forecast is calculated based on the previous video forecast+duration.
> The first video forecast is set by the user ( 10:00:00 ) and all following video forecasts must be automatically calculated.
> 
> VideoName	duration 	forecast
> video1		00:00:30	10:00:00
> video2		00:00:45	10:00:30
> video3		00:01:10	10:01:15
> 
> 
> As this is a dynamic playlist, where videos can be added and removed or even swapped, I've create a Calculated Field and implemented the OnCalcFields method to handle the start forecast values.
> 
> The algorithm part is OK ( I guess ) but my problem lies in the technical aspects !
> 
> I cannot find a feaseble and relieable way to get the forecast value from the previuos video in order to calculate the current video start forecast.
> 
> All option I found implies in browsing the DataSet back and forth to get the data value. Which is not a good solution. 
> 
> Also, I cannot use a query to get the value because this is a calculated field, thus non persistent.
> 
> 
> I could not find a way to get the Calculated field value, without having to browse thru the table.
> 
> Any quess ?
> 
> Well... again, I am sorry for the dummy questions.
> 
> 
> Márcio

One way I can think of is if you are using client datasets in your OnCalcFields 
create a second and clone the cursor.  Then walk it calculating each value until 
you get to the current record in the main dataset.  Should actually be fairly 
fast to do.

-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)
0
Jeff
6/22/2015 4:12:25 AM
> {quote:title=Jeff Overcash (TeamB) wrote:}{quote}
> Marcio Correa wrote:
> > Hello all,
> > 
> > 
> > I am sorry if this looks like a dummy question, but I've spent a few weeks on this problem, with no lucky.
> > 
> > I have a Delphi project that comprises a simple video playlist, which I control via a Query displayed by a DBGrid.
> > 
> > Each video has its own duration and a start 'forecast'. For instance:
> > 
> > The video forecast is calculated based on the previous video forecast+duration.
> > The first video forecast is set by the user ( 10:00:00 ) and all following video forecasts must be automatically calculated.
> > 
> > VideoName	duration 	forecast
> > video1		00:00:30	10:00:00
> > video2		00:00:45	10:00:30
> > video3		00:01:10	10:01:15
> > 
> > 
> > As this is a dynamic playlist, where videos can be added and removed or even swapped, I've create a Calculated Field and implemented the OnCalcFields method to handle the start forecast values.
> > 
> > The algorithm part is OK ( I guess ) but my problem lies in the technical aspects !
> > 
> > I cannot find a feaseble and relieable way to get the forecast value from the previuos video in order to calculate the current video start forecast.
> > 
> > All option I found implies in browsing the DataSet back and forth to get the data value. Which is not a good solution. 
> > 
> > Also, I cannot use a query to get the value because this is a calculated field, thus non persistent.
> > 
> > 
> > I could not find a way to get the Calculated field value, without having to browse thru the table.
> > 
> > Any quess ?
> > 
> > Well... again, I am sorry for the dummy questions.
> > 
> > 
> > Márcio
> 
> One way I can think of is if you are using client datasets in your OnCalcFields 
> create a second and clone the cursor.  Then walk it calculating each value until 
> you get to the current record in the main dataset.  Should actually be fairly 
> fast to do.
> 
> -- 
> Jeff Overcash (TeamB)
>        (Please do not email me directly unless  asked. Thank You)
> And so I patrol in the valley of the shadow of the tricolor
> I must fear evil. For I am but mortal and mortals can only die.
> Asking questions, pleading answers from the nameless
> faceless watchers that stalk the carpeted  corridors of Whitehall.
>               (Fish)


Hello Jeff,

Thanks for your reply.

I was not using a ClientDataSet, but the Query directly set in the DataSource and DBGRID.

I've implemented a TClientDataSet in my app and I can see it works as expected, I can move the cursor really fast and this does not change the actual dataset displayed in the UI.

But... if I try to move the ClientDataSet cursor from the OnCalcFields() I will get an error saying the DataSet is closed, this happens because, during OnCalcFields, the dataset is still closed.

Now, I am not sure if I got what you said about cloning the dataset. Could you please send me an example ?

Thank you so much!


Márcio,
0
Marcio
6/23/2015 4:22:16 PM
Marcio Correa wrote:
>> {quote:title=Jeff Overcash (TeamB) wrote:}{quote}
>> Marcio Correa wrote:
>>> Hello all,
>>>
>>>
>>> I am sorry if this looks like a dummy question, but I've spent a few weeks on this problem, with no lucky.
>>>
>>> I have a Delphi project that comprises a simple video playlist, which I control via a Query displayed by a DBGrid.
>>>
>>> Each video has its own duration and a start 'forecast'. For instance:
>>>
>>> The video forecast is calculated based on the previous video forecast+duration.
>>> The first video forecast is set by the user ( 10:00:00 ) and all following video forecasts must be automatically calculated.
>>>
>>> VideoName	duration 	forecast
>>> video1		00:00:30	10:00:00
>>> video2		00:00:45	10:00:30
>>> video3		00:01:10	10:01:15
>>>
>>>
>>> As this is a dynamic playlist, where videos can be added and removed or even swapped, I've create a Calculated Field and implemented the OnCalcFields method to handle the start forecast values.
>>>
>>> The algorithm part is OK ( I guess ) but my problem lies in the technical aspects !
>>>
>>> I cannot find a feaseble and relieable way to get the forecast value from the previuos video in order to calculate the current video start forecast.
>>>
>>> All option I found implies in browsing the DataSet back and forth to get the data value. Which is not a good solution. 
>>>
>>> Also, I cannot use a query to get the value because this is a calculated field, thus non persistent.
>>>
>>>
>>> I could not find a way to get the Calculated field value, without having to browse thru the table.
>>>
>>> Any quess ?
>>>
>>> Well... again, I am sorry for the dummy questions.
>>>
>>>
>>> Márcio
>> One way I can think of is if you are using client datasets in your OnCalcFields 
>> create a second and clone the cursor.  Then walk it calculating each value until 
>> you get to the current record in the main dataset.  Should actually be fairly 
>> fast to do.
>>
>> -- 
>> Jeff Overcash (TeamB)
>>        (Please do not email me directly unless  asked. Thank You)
>> And so I patrol in the valley of the shadow of the tricolor
>> I must fear evil. For I am but mortal and mortals can only die.
>> Asking questions, pleading answers from the nameless
>> faceless watchers that stalk the carpeted  corridors of Whitehall.
>>               (Fish)
> 
> 
> Hello Jeff,
> 
> Thanks for your reply.
> 
> I was not using a ClientDataSet, but the Query directly set in the DataSource and DBGRID.
> 
> I've implemented a TClientDataSet in my app and I can see it works as expected, I can move the cursor really fast and this does not change the actual dataset displayed in the UI.
> 
> But... if I try to move the ClientDataSet cursor from the OnCalcFields() I will get an error saying the DataSet is closed, this happens because, during OnCalcFields, the dataset is still closed.
> 
> Now, I am not sure if I got what you said about cloning the dataset. Could you please send me an example ?
> 
> Thank you so much!
> 
> 
> Márcio,

Post your OnCalcFields procedure.

-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)
0
Jeff
6/23/2015 5:01:32 PM
> {quote:title=Jeff Overcash (TeamB) wrote:}{quote}
> Marcio Correa wrote:
> >> {quote:title=Jeff Overcash (TeamB) wrote:}{quote}
> >> Marcio Correa wrote:
> >>> Hello all,
> >>>
> >>>
> >>> I am sorry if this looks like a dummy question, but I've spent a few weeks on this problem, with no lucky.
> >>>
> >>> I have a Delphi project that comprises a simple video playlist, which I control via a Query displayed by a DBGrid.
> >>>
> >>> Each video has its own duration and a start 'forecast'. For instance:
> >>>
> >>> The video forecast is calculated based on the previous video forecast+duration.
> >>> The first video forecast is set by the user ( 10:00:00 ) and all following video forecasts must be automatically calculated.
> >>>
> >>> VideoName	duration 	forecast
> >>> video1		00:00:30	10:00:00
> >>> video2		00:00:45	10:00:30
> >>> video3		00:01:10	10:01:15
> >>>
> >>>
> >>> As this is a dynamic playlist, where videos can be added and removed or even swapped, I've create a Calculated Field and implemented the OnCalcFields method to handle the start forecast values.
> >>>
> >>> The algorithm part is OK ( I guess ) but my problem lies in the technical aspects !
> >>>
> >>> I cannot find a feaseble and relieable way to get the forecast value from the previuos video in order to calculate the current video start forecast.
> >>>
> >>> All option I found implies in browsing the DataSet back and forth to get the data value. Which is not a good solution. 
> >>>
> >>> Also, I cannot use a query to get the value because this is a calculated field, thus non persistent.
> >>>
> >>>
> >>> I could not find a way to get the Calculated field value, without having to browse thru the table.
> >>>
> >>> Any quess ?
> >>>
> >>> Well... again, I am sorry for the dummy questions.
> >>>
> >>>
> >>> Márcio
> >> One way I can think of is if you are using client datasets in your OnCalcFields 
> >> create a second and clone the cursor.  Then walk it calculating each value until 
> >> you get to the current record in the main dataset.  Should actually be fairly 
> >> fast to do.
> >>
> >> -- 
> >> Jeff Overcash (TeamB)
> >>        (Please do not email me directly unless  asked. Thank You)
> >> And so I patrol in the valley of the shadow of the tricolor
> >> I must fear evil. For I am but mortal and mortals can only die.
> >> Asking questions, pleading answers from the nameless
> >> faceless watchers that stalk the carpeted  corridors of Whitehall.
> >>               (Fish)
> > 
> > 
> > Hello Jeff,
> > 
> > Thanks for your reply.
> > 
> > I was not using a ClientDataSet, but the Query directly set in the DataSource and DBGRID.
> > 
> > I've implemented a TClientDataSet in my app and I can see it works as expected, I can move the cursor really fast and this does not change the actual dataset displayed in the UI.
> > 
> > But... if I try to move the ClientDataSet cursor from the OnCalcFields() I will get an error saying the DataSet is closed, this happens because, during OnCalcFields, the dataset is still closed.
> > 
> > Now, I am not sure if I got what you said about cloning the dataset. Could you please send me an example ?
> > 
> > Thank you so much!
> > 
> > 
> > Márcio,
> 
> Post your OnCalcFields procedure.
> 
> -- 
> Jeff Overcash (TeamB)
>        (Please do not email me directly unless  asked. Thank You)
> And so I patrol in the valley of the shadow of the tricolor
> I must fear evil. For I am but mortal and mortals can only die.
> Asking questions, pleading answers from the nameless
> faceless watchers that stalk the carpeted  corridors of Whitehall.
>               (Fish)




Hello Jeff

I am sorry for the delay... I´ve been out for a while.

Thre you go:

Please, disregard all the string and datetime conversions... this is just a POC.
My actual code handles it in different way, but I still need the same problem.

Probably I dont know how to work with ClientDataSets.

ZQuery1qt_prev is my Calculated Field.



procedure TForm1.ZQuery1CalcFields(DataSet: TDataSet);
begin

    if ZQuery1qt_entrada.Value <> '' then
    begin
      ZQuery1qt_prev.Value := ZQuery1qt_entrada.Value;
    end
    else
      begin

        ZQuery1qt_prev.Value := getUltimaPrev(ZQuery1id_posicao.Value);

      end;


end;


function TForm1.getUltimaPrev(pos : integer): String;
var
  duracao, previsao  : String;
  dtPrevisao : String;

begin

  cds2 := TClientDataSet.Create(nil);

  cds2.CloneCursor(cdsTemp,false,false);

  if cds2.Locate('id_posicao',pos-1,[loCaseInsensitive]) then
  begin

    previsao := cds2.fieldbyname('qt_prev').AsString;
    duracao := cds2.fieldbyname('qt_duracao').AsString;

    if previsao = '' then previsao := '00:00:00';
    if duracao = '' then duracao := '00:00:00';


    dtPrevisao := Timetostr ( strtotime(duracao) + strtotime(previsao));

  end;

  result := dtPrevisao;

end;


Thank you so much !
0
Marcio
7/4/2015 11:25:48 PM
Reply:

Similar Artilces:

Autoincrement field not working from Delphi
I'm using Anywhere 6.01 and Delphi 4 C/S. I setup a table to include an autoincrement field, not null, yet whenever I try to append a record, it always tells me that this field is required! What am I missing here? It also has the same effect when adding through the SQL Explorer in Delphi. Thanks, Craig. -- *********************************************************** Craig Roberts AllChem Industries, Inc. 6010 NW 1st Place, Gainesville, FL, 32607, USA. Phone 352-378-9696 FAX 352-338-0400 http://www.allchem.com **********************************************************...

How To Calculate Working day Exclude Holidays From Database.
Recently i am doing a project on calculating working days. I manage to calculate the working days exclude weekend but i am stuck at exclude holidays from database. In the Holiday database, it has the startdate and enddate for a holiday. How i going to compare which holiday i will using to exclude from the holiday bank? Pls give me some advise pls !! It is not easy stuff but try the links below for two possible solutions.  Hope this helps.  http://www.aspfaq.com/show.asp?id=2519 http://www.databasejournal.com/features/mssql/article.php/1442221  Kind regards,Gift Peddie ...

gridview database update with datetime field not working
For some reason when the updatecommand runs my two datetime fields aren't entered into the database (a NULL value is).  I can't figure out why.I think the problem is from the StartDate and EndDate, though no error is thrown, so it's hard to debug.  The EventName and EventLocation get's updated properly, but the StartDate and EndDate get set to NULL Here is my SP:ALTER PROCEDURE dbo.spAdminInEvents     @EventName varchar(200),    @EventLocation varchar(250),    @StartDate datetime,    @EndDate datetimeA...

TClientDataset and Calculated field problem (Delphi XE3)
Hi everybody, I have a problem with a TClientDataset and a calculated field. I have migrate my code from Delphi 6 to Delphi XE3, and in Delphi 6, I had a TADODataset with the next properties: CursorLocation: clUseServer, CursorType: ctOpenForwardOnly and LockType: ltReadOnly. In this Dataset I add a calculated field. Then I have a TClientDataset which is related with the ADOdataset by a TDatasetProvider. And the data, is shown on a DBGrid. This works on Delphi 6, but in Delphi XE3, I have to set the TADODataset cursorl ocation to clUseClient in order to work correctly, but of course this i...

updating calculated fields to database in asp.net 2.0
i'm doing a inventory management website. whenever the new stocks come in, i want to update my qtyinstock in the database by adding the new stocks and the exsiting qtyinstock. currently, i'm able to calculate the total and also to update the new stocks. but i wasn't able to update the calculated values to qtyinstock in my database. i'm using formview to carry out the various functions. i think that the fault lies with the update command.  i want the qtyinstock to be replaced by the calculated fields in expr1. SelectCommand="SELECT SUM(QtyInStock + NewStocks) AS E...

Display and Calculate a number between two different fields stored in my database
Hi Im not sure if i posted this in right section or not becuase im not sure what section my query falls under but basically i would like to:Calculate a number between two different fields stored in my database and store that number back in.For example. Employee has 20 days holday in Days_Left Feild and in Holiday_Table they have Days_Requested as 6 days and that status has been approved.I am now wondering as soon as the status becomes approved, how i can get 20 - 6 and put 14 back into Days_Left field. It needs to be done just for that employee.Im not sure how to go about doing this so if...

Can you recommend a simple non dependancy Database to work with Delphi 2010
Hi I recently bought Delphi 2010 having moved from Lazarus/FPC, I used lazarus with Zeoslib package to use single file Sqlite databases in my apps and it worked great. Having bought Delphi 2010 PRO the current Zeoslib does not support delphi 2010, so I am looking to embed a database in my apps that does not require any additional files installing on the end users computer except maybe a dll file with the executable. My question is does delphi ship with anything similar to what I have described above, or can anyone recommend a freeware component that will function with Delphi 2010. Thank...

Setting calculated field into a column field
Hi All, I need to assign a result of calculated field into a column field. dw_1.object.data[1,1,10,1]=dw_1.object.calculate_1[1,10] How can l do this ? If I use a loop to assign the value the performance is too low. Any help appreciated Stefano Bullo ...

how to connect a database-field to an input-field
Hi There, I'm having a problem with connecting a field from a database to an input field. I do get a record but don't know how to attach this to a textbox. I thought the .value would do the trick but it doesn't... Here is my code: if DS.Tables(0).Rows.Count = 1 then naam.text = ds.Tables(0).Columns("Contact_naam").value.ToString end if myConnection.Close() End Sub </script> <html> <head> <link href="../../../styles/website.css" rel="stylesheet" soort="text/c...

my database is working on my system but is not working on server
please i will like to know if is there any configuration that i use to make my website work using aspx with .mdf database. i test the site using Visual Studio 2008 and it is working perfectly but when i upload the site on internet please is there any connection need different from the one on web.config please help me because i am new this is the code i used on my system please i need your assistance It sounds like you have an issue with your connection string settings on your production application. Are you hosting this yourself or through an external provider? Regards Scotty B Are ...

Delphi 2009 database update SQL includes fkCalculated field's condition?
ClientDataSet -> DataSetProvider -> SQLQuery -> [Oracle Database] Add fkCalculated field into TSQLQuery. Execute ClientDataSet.ApplyUpdates cast error: ORA-00904: invalid column name In Call stack window, The TSQLResolver.DoExecSQL carries strange 'where' clauses to PSExecuteStatement. ---------------------------------------------- ... DBXCommon.TDBXMorphicCommand.ExecuteQuery SqlExpr.TSQLConnection.Execute('update "TEST_TABLE" set'#$D#$A' "ID" = ?'#$D#$A'where'#$D#$A' "ID" = ? and'#$D#$A&...

Modify a working Delphi XE4 installation does not work
Hello, i need to upgrade the intraweb component in Delphi XE4 to the official atozed license. The info from atozed is first to uninstall the bundled version. But when i start the installation wizard from XE4 and select modify, a message "serial number unvalid" appears and i can only stop with taskmanager. What can i do. Thanks Theo Ok, i found the solution myself. Here is how it goes: http://support.embarcadero.com/article/43089 ...

column field length < database field??
I have a datawindow in which I have a column field. in the column field the length that I have fixed only fit 40 chars. The database field length is 50 char. The question is...What property/ies Do I have to set for I could write 50 chars although they weren't seen altogether in the datawindow column field? Thanks in advance Export the DW into it's "source" code. Then change the column length to 50 and re-import the source code! regards ... Chris <jomarca1> wrote in message news:3ff16e26.547c.846930886@sybase.com... > I have a datawindow in whic...

Why does this work fine in Delphi 2009, but not in Delphi 2010
I've been racking my head trying to figure this out and can't understand what is wrong, TFileStream.ReadComponentRes fails when I try to read a component containing a record, it works fine in Delphi 2009 and Delphi 2007, but fails with Delphi 2010 Here is the unit source and DFM *+//UnitSource+* unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TThresholdMode = (tm0,tm1,tm2,tm3,tm4,tm5); TThreshold = Record Mode:TThresholdMode; Filter,Start,Stop:Integer; end; ...

Web resources about - Working with Calculated Fields - embarcadero.delphi.database

Calculated Risk - Wikipedia, the free encyclopedia
^ Streitfeld, David (December 1, 2008). "Doris Dungey, Prescient Finance Blogger, Dies at 47" . New York Times. p. A27, New York edition . h ...

Image from page 12 of "The American anti-slavery almanac, for ... : calculated for Boston, New York ...
Identifier: americanantislav1838chil Title: The American anti-slavery almanac, for ... : calculated for Boston, New York, and Pittsburgh .. Year: ...

Cosy deal calculated to aid fund managers
A few years back, the corporate regulators did the fund managers a big favour.

How is the ATAR calculated?
All Study Scores are scaled to adjust for the fact that it is more difficult to obtain a high Study Score in some studies than others.

Clive Palmer's buffoonery may be a calculated act
Clive Palmer’s parliamentary buffoonery is just what those who voted for him want.

Missing Malaysia Airlines search site matches final contact point calculated two weeks ago
A final unexplained signal emitted by the missing Malaysia Airlines plane was tracked to the same point in the Indian Ocean at which authorities ...

Canterbury Bulldogs' calculated leap of faith in Michael Lichaa places weight of expectation on his shoulders ...
Even the expectation of bursting into the NRL as the hottest rookie in the game could not have prepared Michael Lichaa for what would unfold ...

Keystone XL Emissions Could Be Four Times Higher Than U.S. Calculated, Says New Study
WASHINGTON - The much-debated Keystone XL pipeline could produce four times more global warming pollution than the State Department calculated ...

Size matters, but so does how it is calculated
Size matters, but so does how it is calculated

Stop Giving Away the Store: “Reasonably Calculated” does not define the scope of discovery. (And it never ...
For over a hundred years Americans have enjoyed Josh Billing’s chestnut, “I’d rather not know so much, than to know so much that ain’t so.” ...

Resources last updated: 1/3/2016 2:48:41 AM