Three experiences of developing database program with Delphi

Source: Internet
Author: User
Tags requires

1. Establishment of temporary tables

Data input is the necessary link of developing database program. In a client/server structure, a client may have to enter a batch of data and then submit it to the server's back-end database, which requires a temporary data table to be set up locally (the client) to store data entered by the user, and the local table data is purged when submitted. The advantage of this method is that it improves the input efficiency and reduces the network burden.

Because the amount of data that a user enters at once is small (no more than hundreds of records), a temporary table can be built in memory, which is handled faster.

Method 1: Use the query control (tquery)

1th step: Put the Query Control (tquery) on the form and set up the connected datasheet.

2nd step: Make Tquery. Cachedupdates=true;

Tquery. Requestlive=true

Step 3rd: Add a WHERE child statement after the original SQL statement, asking that the SQL query result be empty after adding the where child statement.

For example:

  SELECT Biolife.″Species No″, Category, Common_Name, Biolife.″Species Name″, Biolife.″Length (cm)″, Length_In, Notes, Graphic
    FROM ″biolife.db″ Biolife
   where Biolife.Category=′A′ and Biolife.Category=′B′

So the temporary table is completed.

Method 2: Create a temporary table using code

The code is as follows:

  function CreateTableInMemory(const AFieldDefs:TFieldDefs):TDataSet;
   var
TempTable:TClientDataSet;
   begin
   TempTable:=nil;
   Result:=nil;
   if AFieldDefs$#@60;$#@62;nil then
   begin
   try
   TempTable:=TClientDataSet.Create(Application);
   TempTable.FieldDefs.Assign(AFieldDefs);
   TempTable.CreateDataSet;
   Result:=(TempTable as TDataSet);
   Except
   if TempTable$#@60;$#@62;nil then
TempTable.Free;
  Result:=nil;
   raise;
    end
end
  end;

Use the following methods in your program:

  procedure TForm1.Button1Click(Sender: TObject);
   var
ADataSet:TDataSet;
   begin
   ADataSet:=TDataSet.Create(Self);
   with ADataSet.FieldDefs do
   begin
   Add(′Name′,ftString,30,False);
   Add(′ ue′,ftInteger,0,False);
   end;
   with DataSource1 do
   begin
   DataSet:=CreateTableInMemory(ADataSet.FieldDefs);
   DataSet.Open;
   end;
   ADataSet.Free;
   end;

temporary table creation completed.

Method 1 is simple to use, but because of the query control, you need to query the server back-end database for the data, so it's a bit slow and does not apply to the fact that the fields in the temporary table are pieced together by fields from several data tables. Method 2 is wide and fast, but requires coding. (The use of Tfielddefs in code is very simple, see Delphi online Help).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.