 |
Warning: include(../ulink180x90.php) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/show table.php on line 73
Warning: include(../ulink180x90.php) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/show table.php on line 73
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/show table.php on line 73
|
It's strange if the application database does not have a mode for
displaying tabular data.
Here is a tutorial how to display your data in a table.
To display data in a table is actually quite seherhana, ie you can
just retrieve a record from the database and then placed in the desired
position in
a grid component, TStringGrid. See example below:
procedure TForm1.Button1Click (Sender: TObject);
var
..
..
begin
// read record from database
..
..
StringGrid1.Cells [0, 1]: = PhoneOwner.Name;
StringGrid1.Cells [1, 1]: = PhoneOwner.Phone;
StringGrid1.Cells [2, 1]: = PhoneOwner.MobilePhone;
StringGrid1.Cells [3, 1]: = PhoneOwner.Fax;
end;
Meanwhile, to display the entire database, you only give the looping
statement.
Here is full code:
procedure TForm1.Button1Click (Sender:
TObject);
var
F: File of TPhoneBook;
PhoneOwner: TPhoneBook;
Size: longint;
iRow, iy: integer;
begin
//Show records in table
iRow: = 0;
ClearGrid;
//read from database
//Reopen the file in read only mode
AssignFile (F, FTableName);
Reset (F);
Size: = Filesize (F);
//Display a record from
file
try
for iy: = 0 to Size-1 do
begin
Seek (F, iy);
Read (F, PhoneOwner);
if not then PhoneOwner.Hide
begin
StringGrid1.Cells [0, iRow +1]: = PhoneOwner.Name;
StringGrid1.Cells [1, iRow +1]: = PhoneOwner.Phone;
StringGrid1.Cells [2, iRow +1]: = PhoneOwner.MobilePhone;
StringGrid1.Cells [3, iRow +1]: = PhoneOwner.Fax;
inc (iRow);
end;
end;
//Close the
file for the last time
finally
CloseFile (F);
end;
StringGrid1.RowCount: = iRow +1;
end;
|
Additional tutorial is for a record in a database and displayed
on the table. Function used is CompareText function (const S1, S2: string): Integer;
CompareText compares S1 and S2 and returns 0 if they are equal.
If S1 is greater than S2, CompareText returns an integer greater
than 0. If S1 is less than S2, CompareText returns an integer less
than 0. CompareText is not case sensitive and is not affected by
the current locale.
Following function below is only compare first character and ignore
the other on behind.
function SeacrhLike (AString, Pattern:
string): boolean;
var
i, n2: integer;
S1, S2: string;
begin
n2: = Length (Pattern);
S2: = Pattern;
//Delete unuse substring
for i: = 1 to n2 do
begin
S1: = S1 + Astring [i];
end;
if CompareText (S1, S2) = 0 then
begin
Result: = True;
end else
Result: = false;
end;
|
Function above will result in true value if the string is comparing
the same value or false if didnot same.
To perform the function SearchLike (), please see the following
code below:
procedure TForm1.sbSearchClick (Sender:
TObject);
var
F: File of TPhoneBook;
PhoneOwner: TPhoneBook;
Size: longint;
ix, iy, ifound: integer;
begin
ClearGrid;
ifound: = 1;
//Search by name
//read from database
//Reopen the file in read only mode
AssignFile (F, FTableName);
Reset (F);
Size: = Filesize (F);
try
for iy: = 0 to Size-1 do
begin
Seek (F, iy);
Read (F, PhoneOwner);
if SeacrhLike (PhoneOwner.Name, Edit5.Text) then
begin
StringGrid1.Cells [0, ifound]: = PhoneOwner.Name;
StringGrid1.Cells [1, ifound]: = PhoneOwner.Phone;
StringGrid1.Cells [2, ifound]: = PhoneOwner.MobilePhone;
StringGrid1.Cells [3, ifound]: = PhoneOwner.Fax;
inc (ifound);
end;
end;
//Close the
file for the last time
finally
CloseFile (F);
end;
if ifound> 1 then
begin
StringGrid1.RowCount: = ifound
end
else
tringGrid1.RowCount: = 2;
end;
|
You can also display the search results on komopnen TEdit.
More details you can download the code here.
Warning: include(../fileroutines.php) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/show table.php on line 262
Warning: include(../fileroutines.php) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/show table.php on line 262
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/show table.php on line 262
|
|