Warning: include(../mainbanner.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 31

Warning: include(../mainbanner.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 31

Warning: include() [function.include]: Failed opening '../mainbanner.htm' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/makedata/public_html/delphitutorial/linking table.php on line 31

Warning: include(../left.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 52

Warning: include(../left.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 52

Warning: include() [function.include]: Failed opening '../left.htm' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/makedata/public_html/delphitutorial/linking table.php on line 52
Delphi Tutorial

Linking Tables

Part One. In some database applications use more than one table. They used many tables but they are related. You can create a simple database application with some of the related table. Here we will be discussed about how to make it.

This tutorial have three parts :

Create Two Tables and Insert Its Data


Warning: include(../ulink180x90.php) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 90

Warning: include(../ulink180x90.php) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 90

Warning: include() [function.include]: Failed opening '../ulink180x90.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/makedata/public_html/delphitutorial/linking table.php on line 90

Sebagai contoh saya membuat dua buah tabel yang saling berhubungan. Tabel pertama menyimpan data nama dan tabel kedua menyimpan data alamat serta nomor telepon. Setiap tabel memiliki field NumId sebagai penada urutan record. Nilai NumId harus sama antar tabel pertama dan tabel kedua.

As an example I created two tables each other have relation ship. First table save the data about name and the second table store address and phone number fileds. Each table has a field NumId as a sequence record. NumId value should be the same betwen between the first and second table.

First step, define the tables

type
  TMyTable1 = record
    NumId: longint;
    Name: string[30];
    Hide: boolean;
  end;
type TMyTable2 = record NumId: longint; Address: string[250]; Phone: string[12]; Hide: boolean; end;

I confirm that the first table called 'table-1.dat' file as master table and secod table called 'table-2.dat' file act as follower or slave.

const FileName1= 'table-1.dat';
      FileName2= 'table-2.dat';

To create two tables in the same time are basically same as create table file like as in previous tutorial. But only do twice. See the code listing following below to create two tables at once.

procedure TForm1.Button1Click(Sender: TObject);
var
 F1: File of TMyTable1;
 F2: File of TMyTable2;
begin
  //Create 2 tables directly
  if not FileExists(FileName1) then
  begin
    AssignFile(F1, FileName1);
    try
      Rewrite(F1);
    finally
      CloseFile(F1);
    end;
  end else
   ShowMessage('Table-1 already exists.');
  if not FileExists(FileName2) then
  begin
    AssignFile(F2, FileName2);
    try
      Rewrite(F2);
    finally
      CloseFile(F2);
    end;
  end else
   ShowMessage('Table-2 already exists.');
end;

Now to insert new record at the same time also the same method like as previous tutoial. Actually be done sequentially. See the following code in the list below.

procedure TForm1.Button3Click(Sender: TObject);
var
  F1: File of TMyTable1;
  F2: File of TMyTable2;
  data1: TMyTable1;
  data2: TMyTable2;
  NumRow1, NumRow2: longint;
begin
  //Insert new record into table-1
  AssignFile(F1, FileName1);
  Reset(F1);
  NumRow1:= FileSize(F1); //Count table-1 rows
  try
    Seek(F1, NumRow1);
    data1.NumId:= NumRow1;
    data1.Name:= Edit1.Text;
    data1.Hide:= false;
    Write(F1, data1);
  finally
    CloseFile(F1);
  end;

  //Insert new record into table-2
  AssignFile(F2, FileName2);
  Reset(F2);
  NumRow2:= FileSize(F2); //Count table-2 rows
  try
    Seek(F2, NumRow2);
    data2.NumId:= NumRow2;
    data2.Address:= Edit2.Text;
    data2.Phone:= Edit3.Text;
    data2.Hide:= false;
    Write(F2, data2);
  finally
    CloseFile(F2);
  end;
end;

More details you can download the source code here.



Warning: include(../fileroutines.php) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 227

Warning: include(../fileroutines.php) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 227

Warning: include() [function.include]: Failed opening '../fileroutines.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/makedata/public_html/delphitutorial/linking table.php on line 227

Warning: include(../right.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 241

Warning: include(../right.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 241

Warning: include() [function.include]: Failed opening '../right.htm' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/makedata/public_html/delphitutorial/linking table.php on line 241

Warning: include(../bottombanner.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 256

Warning: include(../bottombanner.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/linking table.php on line 256

Warning: include() [function.include]: Failed opening '../bottombanner.htm' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/makedata/public_html/delphitutorial/linking table.php on line 256