FireDAC – Imperative Programming with Interface

When I was preparing the sample code for the article on Forin to FireDAC , I remembered an article by my friend Marcos Douglas  published in Object Pascal Programming  that speaks of the Imperative or Structured programming.

In computer science, imperative programming is a programming paradigm that describes computation as actions, statements or commands that change the state (variables) of a program. Much like the imperative behavior of natural languages ​​that express orders, imperative programs are a sequence of commands to the computer running.  (Wikipedia)

The article has as objective to discuss the end of FreeAndNil proposing the use of Interface PASCAL programming. Extracting the concept is possible to write code using directly interface which demonstrates the power of language forward to the new paradigms.

Rewriting TFDQuery interface, we can do:

[code lang=”pascal”]
TQueryIntf.New (FDConnection1)
   .table ( ‘sigcad a’)
   .FieldNames ( ‘code, name’)
   .Where ( ‘between code: codigo_de and: codigo_ate’)
   .ParamValue ( ‘codigo_de’, 1)
   .ParamValue ( ‘codigo_ate’, 5)
   .open
   .DoQuery (Procedure (ds: TDataset)
      begin
          memo1.Lines.Add ( ‘loaded’ + IntToStr (ds.RecordCount))
      end);
[/code]

1 comentário

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *