Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In other words, you want to create a dialog with non-data aware controls. In order to do this, you need three TSQLQueries: one to retrieve data when entering the dialog (in case of editing the data), one to insert and one to update.</p> <p>Here is some (edited) code from such a dialog which I wrote the other day. The parameter 'n' is the id of the tuple to be edited; its value will be -1 if I am inserting a new record.</p> <pre><code>Function TEditCashbox.Execute (n: longint): boolean; var q: TSqlQuery; begin if n = -1 then begin edDate.Text:= datetostr (date); edAmount.text:= '0'; end else with qGetCashbox do begin params[0].asinteger:= n; open; edDate.text:= fieldbyname ('curdate').asstring; edAmount.text:= fieldbyname ('amount').asstring; edDetails.text:= fieldbyname ('details').asstring; close end; if showmodal = mrOK then begin if n = -1 then begin q:= qInsertCashbox; q.ParamByName ('p0').asinteger:= dm.GenerateID ('cashbox') end else begin q:= qUpdateCashbox; q.ParamByName ('p0').asinteger:= n end; with q do begin parambyname ('p1').asdate:= strtodate (edDate.text); parambyname ('p2').asinteger:= strtoint (edAmount.Text); parambyname ('p3').asstring:= edDetails.text; execsql end; end end. </code></pre> <p>qGetCashbox is a query defined as select curdate, amount, details from cashbox where id = :p1</p> <p>qInsertCashbox is insert into cashbox (id, curdate, amount, details) values (:p0, :p1, :p2, :p3)</p> <p>qUpdateCashbox is update cashbox set curdate = :p1, amount = :p2, details = :p3 where id = :p0</p> <p>Of course, you could also use data aware components, which require the 'trinity' - TSQLDataSet, TDataSetProvider and TClientDataSet. Using data aware components is easier, but sometimes there are cases in which this approach is not suitable. If you do use data aware components, then my template code is as follows</p> <pre><code>sdsEditDeposit.params[0].AsInteger:= n; // this is the TSQLDataSet with qEditDeposit do // this is the clientdataset begin open; if n = -1 then // new tuple begin insert; fieldbyname ('amount').asinteger:= 0; fieldbyname ('curdate').asdatetime:= date; end; edit; if showmodal = mrOK then begin if n = -1 then begin n:= dm.GenerateID; fieldbyname ('id').asinteger:= n; end; result:= n; post; applyupdates (0) end else begin cancel; result:= 0 end; end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload