Форма использует многократные поля редактирования для поиска полей базы данных, которые пользователь хочет найти. Затем DBGrid заполняется этими полями и используется кнопка для просмотра результатов в MS Word.
procedure TUserDefinedDentalCriteria.Button4Click(Sender: TObject);
var
i, RecNo, numchoices : integer;
slist : TStringList;
RecChange : Boolean;
apfile, sline : String;
WordApp : Variant;
begin
slist := TStringList.Create;
RecNo := 1;
RecChange := False;
apfile := ' Postmortem File';
numchoices := 4;
slist.Add(chr(9)+chr(9)+chr(9)+chr(9)+chr(9)+('DENTAL QUERY'));
slist.Add(chr(32));
if Edit7.Text = '' then
numchoices := numchoices - 1;
if Edit5.Text = '' then
numchoices := numchoices - 1;
if Edit3.Text = '' then
numchoices := numchoices - 1;
case numchoices of
1:
begin
slist.Add(chr(9)+chr(9)+chr(9)+'************************************');
slist.Add(chr(9)+chr(9)+chr(9)+'* Your search for: ' + edit2.Text +
' on tooth #' + edit1.Text + ' *');
slist.Add(chr(9)+chr(9)+chr(9)+'* Returned the following results *');
slist.Add(chr(9)+chr(9)+chr(9)+'************************************');
end;
2:
begin
slist.Add(chr(9)+chr(9)+chr(9)+'**************************************');
slist.Add(chr(9)+chr(9)+chr(9)+'* Your search for: ' + edit2.Text +
' on tooth #' + edit1.Text + ' *');
slist.Add(chr(9)+chr(9)+chr(9)+'* and: ' + edit4.Text +
' on tooth #' + edit3.Text + ' *');
slist.Add(chr(9)+chr(9)+chr(9)+'* Returned the following results *');
slist.Add(chr(9)+chr(9)+chr(9)+'**************************************');
end;
3:
begin
slist.Add(chr(9)+chr(9)+chr(9)+'************************************');
slist.Add(chr(9)+chr(9)+chr(9)+'* Your search for: ' + edit2.Text +
' on tooth #' + edit1.Text + ' *');
slist.Add(chr(9)+chr(9)+chr(9)+'* and: ' + edit4.Text +
' on tooth #' + edit3.Text + ' *');
slist.Add(chr(9)+chr(9)+chr(9)+'* and: ' + edit6.Text +
' on tooth #' + edit5.Text + ' *');
slist.Add(chr(9)+chr(9)+chr(9)+'* Returned the following results *' );
slist.Add(chr(9)+chr(9)+chr(9)+'************************************');
end;
4:
begin
slist.Add(chr(9)+chr(9)+chr(9)+'************************************');
slist.Add(chr(9)+chr(9)+chr(9)+'* Your search for: ' + edit2.Text +
' on tooth #' + edit1.Text + ' *');
slist.Add(chr(9)+chr(9)+chr(9)+'* and: ' + edit4.Text +
' on tooth #' + edit3.Text + ' *');
slist.Add(chr(9)+chr(9)+chr(9)+'* and: ' + edit6.Text +
' on tooth #' + edit5.Text + ' *');
slist.Add(chr(9)+chr(9)+chr(9)+'* and: ' + edit8.Text +
' on tooth #' + edit7.Text + ' *');
slist.Add(chr(9)+chr(9)+chr(9)+'* Returned the following results *');
slist.Add(chr(9)+chr(9)+chr(9)+'************************************');
end;
end;
slist.Add(chr(32));
slist.Add(chr(9)+chr(9)+chr(9)+chr(9)+chr(9) + 'Record #' + IntToStr(RecNo));
slist.Add(apfile);
while not DBGrid1.DataSource.DataSet.Eof do
begin
if RecChange = True then
begin
RecNo := RecNo + 1;
slist.Add(chr(9)+chr(9)+chr(9)+chr(9)+chr(9) + 'Record #' + IntToStr(RecNo));
slist.Add(apfile);
RecChange := False;
end;
for i := 0 to DBGrid1.FieldCount - 1 do
begin
if (i <> 3) and (i < 3) then //the number 3 here represents a blank
//TColumn in the DBGrid used to separate
//two files, therefore I don't want to use it
begin
sline := sline + (DBGrid1.Columns[i].Title.Caption
+ ': ' + DBGrid1.Fields[i].Text +chr(9)+chr(9)+chr(9));
end
else
begin
if i <> 3 then
begin
sline := sline + (DBGrid1.Columns[i].Title.Caption
+ ': ' + DBGrid1.Fields[i].Text +chr(9)+chr(9)+chr(9));
end
else
begin
slist.Add(sline);
sline := '';
slist.Add(chr(32));
apfile := ' Antemortem File';
slist.Add(apfile);
apfile := ' Postmortem File';
end;
end;
if i = DBGrid1.FieldCount - 1 then
begin
slist.Add(sline);
sline := '';
slist.Add(chr(32));
slist.Add('-------------------------------------------------------------------');
slist.Add(chr(32));
DBGrid1.DataSource.DataSet.Next;
RecChange := True;
end;
end;
slist.SaveToFile('QueryData.doc');
end;
WordApp := CreateOleObject('Word.Application');
WordApp.Documents.Open('QueryData');
WordApp.Visible := True;
end;
end.
Комментарии